Skip to content

Conversation

@EugeneChoi4
Copy link
Contributor

@EugeneChoi4 EugeneChoi4 commented Sep 3, 2025

Summary

Part 3 of adding a "Config Override" panel to the React compiler playground. Added a button to apply config changes to the Input panel, as well as making the tab collapsible. Added validation for the the PluginOptions type (although comes with a bit more boilerplate) to make it very obvious what the possible config errors could be. Added some toasts for trying to apply broken configs.

How did you test this change?

Screen.Recording.2025-09-04.at.4.34.22.PM.mov

@meta-cla meta-cla bot added the CLA Signed label Sep 3, 2025
@EugeneChoi4 EugeneChoi4 force-pushed the compiler-playground-config/3 branch 2 times, most recently from 2c275d2 to 51547c8 Compare September 4, 2025 18:40
@EugeneChoi4
Copy link
Contributor Author

Definitely considering just removing the comment pragmas on the input panel, it's pretty redundant and adds unnecessary complexity

@EugeneChoi4 EugeneChoi4 marked this pull request as ready for review September 4, 2025 20:39
@EugeneChoi4 EugeneChoi4 requested a review from jackpope September 4, 2025 20:39
export default function ConfigEditor(): JSX.Element {
const [, setMonaco] = useState<Monaco | null>(null);
export default function ConfigEditor(): React.ReactElement {
const [isExpanded, setIsExpanded] = useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Chatted offline about abstracting a CollapsiblePane type component that can be used across all the panes as a follow up so we don't have to recreate this layout logic each time.

Comment on lines +95 to +111
// Add the babel-plugin-react-compiler type definitions to Monaco
monaco.languages.typescript.typescriptDefaults.addExtraLib(
//@ts-expect-error - compilerTypeDefs is a string
compilerTypeDefs,
'file:///node_modules/babel-plugin-react-compiler/dist/index.d.ts',
);
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.Latest,
allowNonTsExtensions: true,
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
module: monaco.languages.typescript.ModuleKind.ESNext,
noEmit: true,
strict: false,
esModuleInterop: true,
allowSyntheticDefaultImports: true,
jsx: monaco.languages.typescript.JsxEmit.React,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

This is great, lots of validation features for free!

const handleChange: (value: string | undefined) => void = value => {
if (value === undefined) return;

// Only update the config
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what you mean by this comment exactly. As oppose to the source? But that also gets passed in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The source remains unchanged but the config gets updated when users type into the config pane. The source is only update when the button is clicked as of now.

Comment on lines +19 to +36
({
compilationMode: 'infer',
panicThreshold: 'none',
environment: {},
logger: null,
gating: null,
noEmit: false,
dynamicGating: null,
eslintSuppressionRules: null,
flowSuppressions: true,
ignoreUseNoForget: false,
sources: filename => {
return filename.indexOf('node_modules') === -1;
},
enableReanimatedCheck: true,
customOptOutDirectives: null,
target: '19',
} satisfies Partial<PluginOptions>);`;
Copy link
Contributor

Choose a reason for hiding this comment

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

This default has to be maintained as we change the config schema or defaults, right? If we can't load automatically from the plugin options themselves, we at least should have a unit test.

Basically if this default goes out of date we should fail a test so the next person who changes an option can come update this string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, planning to add better testing soon

@EugeneChoi4 EugeneChoi4 merged commit de5a1b2 into facebook:main Sep 5, 2025
24 checks passed
@EugeneChoi4 EugeneChoi4 deleted the compiler-playground-config/3 branch September 5, 2025 14:12
github-actions bot pushed a commit to code/lib-react that referenced this pull request Sep 7, 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

Part 3 of adding a "Config Override" panel to the React compiler
playground. Added a button to apply config changes to the Input panel,
as well as making the tab collapsible. Added validation for the the
PluginOptions type (although comes with a bit more boilerplate) to make
it very obvious what the possible config errors could be. Added some
toasts for trying to apply broken configs.

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

## How did you test this change?

https://github.com/user-attachments/assets/63ab8636-396f-45ba-aaa5-4136e62ccccc

<!--
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 [de5a1b2](facebook@de5a1b2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants