Skip to content

Conversation

EugeneChoi4
Copy link
Contributor

@EugeneChoi4 EugeneChoi4 commented Sep 15, 2025

Summary

Made many small changes to the compiler playground to improve user experience. Removed any "Loading" indicators that would flash in before a component would finish loading in. Additionally, before users would see the "Show Internals" button toggling from false to true if they had set it at true previously. I was able to refactor the URL/local storage loading so that the Store would be fully initialized before the components would load in.

Attempted to integrate <Activity> into showing/hiding these different editors, but the current state of monaco editors does not allow for this. I created an issue for them to address: suren-atoyan/monaco-react#753

Added a debounce to the config editor so every key type wouldn't cause the output panel to respond instantly. Users can type for 500 ms before an error is thrown at them.

How did you test this change?

Here is what loading the page would look like before (not sure why its so blurry):

Screen.Recording.2025-09-17.at.7.46.18.PM.mov

Here is how it looks now:

Screen.Recording.2025-09-17.at.7.48.07.PM.mov

Here is the debouncing:

Screen.Recording.2025-09-17.at.7.59.48.PM.mov

@meta-cla meta-cla bot added the CLA Signed label Sep 15, 2025
config: value,
},
});
}, 500); // 500ms debounce delay
Copy link
Member

@josephsavona josephsavona Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use useDeferredValue() instead of manually debouncing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useDeferredValue was already being used previously to update the output: https://github.com/facebook/react/blob/main/compiler/apps/playground/components/Editor/EditorImpl.tsx#L329.

It seemed like these updates were still happening too quickly while typing in the config editor so I tried adding a manual debouncing mechanism with a longer timeout window.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josephsavona we're adding debouncing to reduce thrash in the output panel from JS parse errors

@EugeneChoi4 EugeneChoi4 changed the title Playground bug fixes [playground] bug fixes & UX improvements Sep 17, 2025
@EugeneChoi4 EugeneChoi4 marked this pull request as ready for review September 18, 2025 00:00
@EugeneChoi4 EugeneChoi4 added the React Core Team Opened by a member of the React Core Team label Sep 18, 2025
<StoreContext.Provider value={store}>
<StoreDispatchContext.Provider value={dispatch}>
{children}
{isPageReady ? children : null}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah gotcha, we're now waiting until Store is initialized before revealing the page

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! This seemed like the best way to init with url/local storage

const dispatchStore = useStoreDispatch();
const debounceTimerRef = useRef<NodeJS.Timeout | null>(null);

// Cleanup timeout on unmount
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this effect for cleanup?

In the unlikely scenario that you finished typing and closed the config editor within 500ms, you'd still watch the last input change to dispatch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my understanding, when would it be appropriate to have the cleanup effect? If the ExpandedEditor component had some state that was being manipulated by the timer, would it then be necessary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If for example this used a setInterval or otherwise initialized a resource that could cause memory leaks or other side effects by staying around then you want to clean that up. In this case, the timer reference is going to expire at the end of the timeout anyway, so you'd just want to decide if its important if that function is canceled after an unmount or not.

});
const text =
(await page.locator('.monaco-editor').nth(1).allInnerTexts()) ?? [];
(await page.locator('.monaco-editor').nth(3).allInnerTexts()) ?? [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this has gone back and forth a couple times. As a follow up there could be a test that starts the app both with internals showing and not showing.

Also/alternatively adding some testID to the tabs would allow for better selecting. like '[data-testid="config-tab"] .monaco-editor'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I'm actually cleaning up/adding more tests in another PR right now so this will be addressed there.

@@ -1,56 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, we're now using app/page.tsx. Makes sense to delete this

Copy link
Contributor

@mofeiZ mofeiZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you for making playground easier to use!

@EugeneChoi4 EugeneChoi4 merged commit 6eda534 into facebook:main Sep 18, 2025
21 checks passed
github-actions bot pushed a commit to code/lib-react that referenced this pull request Sep 21, 2025
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

Made many small changes to the compiler playground to improve user
experience. Removed any "Loading" indicators that would flash in before
a component would finish loading in. Additionally, before users would
see the "Show Internals" button toggling from false to true if they had
set it at true previously. I was able to refactor the URL/local storage
loading so that the `Store` would be fully initialized before the
components would load in.

Attempted to integrate `<Activity>` into showing/hiding these different
editors, but the current state of [monaco
editors](https://github.com/suren-atoyan/monaco-react) does not allow
for this. I created an issue for them to address:
suren-atoyan/monaco-react#753

Added a debounce to the config editor so every key type wouldn't cause
the output panel to respond instantly. Users can type for 500 ms before
an error is thrown at them.

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->

## How did you test this change?

Here is what loading the page would look like before (not sure why its
so blurry):

https://github.com/user-attachments/assets/58f4281a-cc02-4141-b9b5-f70d6ace12a2

Here is how it looks now:

https://github.com/user-attachments/assets/40535165-fc7c-44fb-9282-9c7fa76e7d53

Here is the debouncing:

https://github.com/user-attachments/assets/e4ab29e4-1afd-4249-beca-671fb6542f5e

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->

DiffTrain build for [6eda534](facebook@6eda534)
github-actions bot pushed a commit to code/lib-react that referenced this pull request Sep 21, 2025
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

Made many small changes to the compiler playground to improve user
experience. Removed any "Loading" indicators that would flash in before
a component would finish loading in. Additionally, before users would
see the "Show Internals" button toggling from false to true if they had
set it at true previously. I was able to refactor the URL/local storage
loading so that the `Store` would be fully initialized before the
components would load in.

Attempted to integrate `<Activity>` into showing/hiding these different
editors, but the current state of [monaco
editors](https://github.com/suren-atoyan/monaco-react) does not allow
for this. I created an issue for them to address:
suren-atoyan/monaco-react#753

Added a debounce to the config editor so every key type wouldn't cause
the output panel to respond instantly. Users can type for 500 ms before
an error is thrown at them.

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->

## How did you test this change?

Here is what loading the page would look like before (not sure why its
so blurry):

https://github.com/user-attachments/assets/58f4281a-cc02-4141-b9b5-f70d6ace12a2

Here is how it looks now:

https://github.com/user-attachments/assets/40535165-fc7c-44fb-9282-9c7fa76e7d53

Here is the debouncing:

https://github.com/user-attachments/assets/e4ab29e4-1afd-4249-beca-671fb6542f5e

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->

DiffTrain build for [6eda534](facebook@6eda534)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants