ArnaudBarre / eslint-plugin-react-refresh

Validate that your components can safely be updated with Fast Refresh
MIT License
206 stars 13 forks source link

feature request: Allow lazy loading #40

Open januswel opened 6 months ago

januswel commented 6 months ago

Now, the rule raises errors with the following codes

const LazyComponent = React.lazy(
  () => import("./MyComponent"),
);
Fast refresh only works when a file only exports components. Move your component(s) to a separate file.eslint(react-refresh/only-export-components)

Can we modify to determine this as the correct code?

ArnaudBarre commented 6 months ago

Can you give more context? This code creates a component so it should follow some Fast refresh rules

januswel commented 6 months ago

I made a repo to repro

https://github.com/januswel/react-refresh-sample

image

This problem may occur with RouteObjects react-router v6

ArnaudBarre commented 6 months ago

This is the same issue as https://github.com/ArnaudBarre/eslint-plugin-react-refresh/issues/25

I need to dig deeper to see how it really behaves at runtime. Given that SWC and Babel generate some fast refresh code for that for now it's safer to consider that React.lazy calls are like creating a wrapper component (which is the case)

januswel commented 6 months ago

@ArnaudBarre Thank you for your comment I saw #25 and consider to use workarounds from you