-
Notifications
You must be signed in to change notification settings - Fork 49.9k
[compiler][playground] (3/N) Config override panel #34371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[compiler][playground] (3/N) Config override panel #34371
Conversation
2c275d2 to
51547c8
Compare
|
Definitely considering just removing the comment pragmas on the input panel, it's pretty redundant and adds unnecessary complexity |
| export default function ConfigEditor(): JSX.Element { | ||
| const [, setMonaco] = useState<Monaco | null>(null); | ||
| export default function ConfigEditor(): React.ReactElement { | ||
| const [isExpanded, setIsExpanded] = useState(false); |
There was a problem hiding this comment.
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.
| // 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, | ||
| }); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| ({ | ||
| 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>);`; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
<!-- 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)
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