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
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
isRefreshBoundaryfunction in@vitejs/plugin-reactis 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