-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Modules with no react exports are treated as fast-refresh boundaries #9869
Comments
I'm willing to attempt a PR to use |
I've hit a snag, unfortunately. I was able to add a conditional vite/packages/vite/src/node/plugins/importAnalysis.ts Lines 399 to 419 in 71eaacf
It appears that the import analyzer only looks for the string I tried to calculate a list of "acceptable" exports and use I'd love to hear any thoughts from @patak-dev or @aleclarson (or anyone else!) about what could potentially be done here. |
Describe the bug
In Dan's original comment describing fast-refresh (facebook/react#16604), he says only files that only export components should be treated as boundaries. But, it seems that the
isRefreshBoundary
function in@vitejs/plugin-react
is much more lax. It seems to only check that export names are capitalized. But, they don't need to be functions, they can be exported objects. See the reproduction for an example of how this causes problems.One approach we could take which might be more robust, would be to perform a runtime check using isLikelyComponentType from the react-refresh runtime library. That has more robust checks than I think we can accomplish statically in the AST. https://github.com/PepsRyuu/rollup-plugin-react-refresh/blob/master/index.js is an example of a project that takes roughly this approach.
Reproduction
https://stackblitz.com/edit/vitejs-vite-b4yvhl?file=src/not-react-components.jsx
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: