Skip to content

Modules with no react exports are treated as fast-refresh boundaries #9869

@IanVS

Description

@IanVS

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

N/A

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions