-
-
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
the vite's HMR does not work when I use React.lazy() API for lazyload #4298
Comments
I can't reproduce this, can you provide a small repro, thanks |
Hello @cookiepool. Please provide a minimal reproduction using a GitHub repository or codesandbox. Issues marked with |
Same issue, My App is like below code:
After use React.lazy, change in Component A (or B) cannot hot reload, but need switch routing. |
in path '/a', change Component B to hot reload? |
https://github.com/cookiepool/vite-react-typescript-template you can use this repository! |
Hope your team can fix this soon! My team has the same trouble with this! |
The issue mainly affects Class Component.Function Component is normal! |
I use Function components, and our app is broken when using lazy import 😅. |
I'm using |
So do I! |
https://github.com/iheyunfei/vite-bug-report-4298 And the problem only happens on function component, Class Component seems to work. |
damn.
import React from 'react'
const Foo = () => ( // works
<div>foo</div>
)
export default Foo import React from 'react'
export default () => ( // doesn't works
<div>foo</div>
) So, It's definitely not a bug of vite, but an intentional behavior of react facebook/react#21181. |
I can't reproduce this either, working examples using |
I think using
|
Have you solve the problem? How to do ? |
So, if I understood correctly, a named export works but a default export won't? Does wrapping a component with // MyComponent.tsx
export const MyComponent: React.FunctionComponent
// App.tsx
const MyComponent = React.lazy(() => import('./components/MyComponent').then(
res => ({ default: res.MyComponent })
)
const App = () => {
return (
<Route path='/' component={MyComponent} />
)
} Is there some other way I could try to get HMR working correctly? |
Default exports work - working example: const Explore = lazy(() => import("@/components/Explore"));
const Footer = lazy(() => import("@/components/Footer"));
const Header = lazy(() => import("@/components/Header"));
const ImageGrid = lazy(() => import("@/components/ImageGrid")); |
I see... Well, my setup is a bit more complex with routing, custom providers and hooks. In a nutshell, when HMR is triggered for a component in the lazy loaded path, a hook fails to get a parameter from the URL. It just returns a default value I've set without actually checking the URL again. If I find the time, I'll try making a small reproduction. |
@RubenLaube-Pohto that would make it easier to help troubleshoot 👍 |
I'm encountering this issue and can't find any obvious places where i'm not defining a component as a const before export defaulting it. Any additional input on how people got over this would be appreciated! |
@guibwl |
Describe the bug
when I use React.lazy(),like this:
supplement!I use
react-router-config
manage my routes information,like this:when I modify some code in Home.tsx or About.tsx etc,the HMR was not effected.I need refresh the broswer can see my modification.
Reproduction
I see vite HMR can work,but it nonitor a wrong file.
I modify About.tsx,but vite HMR feed back router/index.ts.
System Info
Validations
The text was updated successfully, but these errors were encountered: