Repository navigation
Conversation
Allows `react()` to run next to a plugin that already provides Fast Refresh, such as React Router in framework mode, so that JSX and the React Compiler can still be handled by this plugin. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Member
|
Can you update the added playground to use react-router and remove the unit tests? |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Alternative to #1436, following @ArnaudBarre's suggestion in #1436 (comment): instead of exporting a second plugin, add an option to
react()that turns Fast Refresh off, so the plugin can run next to another plugin that already provides it. The motivating case is React Router framework mode:reactRouter()runsreact-refresh/babelitself and wraps modules with its own runtime, so addingreact()today fails withIdentifier 'RefreshRuntime' has already been declared(remix-run/react-router#12870), which leaves no way to use the Rust React Compiler in those apps.Behavior:
fastRefresh: falsefolds into the existingskipFastRefreshlogic (the same path as production, build andserver.hmr: false), so the oxcjsx.refreshtransform, the refresh wrapper, the preamble and the compiler plugin's refresh flag are all skipped. HMR itself stays on.compiler,vite:react-compilerisenforce: 'pre', so it sees route modules before React Router rewrites them regardless of plugin order, and JSX is lowered in the sameoxc-transform-reactpass as the compiler, sojsxDEVsource positions match the source file (thejsx: 'preserve'concern from feat: add standalonereactCompilerplugin #1436 does not apply).fastRefreshexisted until 3.x and was removed in 4.0 (feat!: allow to run Babel on non js/ts extensions #122) because the plugin could always enable it on its own. This brings it back for the case where a different plugin owns it.Verified against a React Router 8.4 framework-mode app (SSR) with
react({ compiler: true, fastRefresh: false })next toreactRouter():react-router buildsucceeds; the client bundle contains the compiled output and no refresh code.jsxDEV, importsRefreshRuntimeexactly once from React Router's virtual HMR runtime and does not reference/@react-refresh. The HTML has no preamble.jsxDEVlineNumbervalues match the JSX lines of the source file.count is 2!: React Router's Fast Refresh preserves state on the compiled output, with no browser or server errors.Included:
playground/fast-refresh-falsewithreact({ compiler: true, fastRefresh: false }), asserting compiled output in serve and build, no refresh code or preamble, and a full reload on edit since that playground has no Fast Refresh boundary.Happy to rename the option if
fastRefreshis not the preferred name.🤖 Generated with Claude Code