-
Notifications
You must be signed in to change notification settings - Fork 916
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
[BUG] HMR breaks with React class components #3323
Comments
Update: I found a partial workaround (works inconsistently): if all class components are wrapped with the |
Update 2: I figured out that the following code is not being injected into the file:
I also figured out that if I render the class component inside a function component in the same file and then export the function component, the above code gets injected correctly and HMR starts working again. It looks like snowpack is having trouble telling that class components should use HMR. I might attempt a fix if someone can point me in the right direction as to where in the snowpack code base the bug would likely originate from. |
After further investigation, I've found other cases where the HMR code isn't being injected: files where the only component is being wrapped with the redux connect function and files with only components generated by styled components. Perhaps it's a more general bug related to React components generated by npm libraries. |
Also, I tried making the same components in create react app and they refresh correctly, so it's definitely a problem with snowpack or one of it's plugins. |
I've updated the title of this issue since figuring out that there isn't a problem with styled-components or react-refresh. I've done quite a bit of testing and I've found that they both appear to work correctly. The real problem is that when a class component is changed, the change should bubble up to it's parent component (in another file) but doesn't if there is a function component in the same file. Here is a minimal example that shows this:
It seems that snowpack sees function A and assumes that this entire file can be hot reloaded when in fact it can't since the exported component is a class component and so needs to be reloaded from scratch. I think I'm getting closer to finding the source of the bug but any guidance would be greatly appreciated. Thanks. |
Bug Report Quick Checklist
Describe the bug
When using React Class components with styled components, both React Fast Refresh and HMR break entirely and the browser doesn't update at all when you save a file.
To Reproduce
Expected behavior
It should update.
The text was updated successfully, but these errors were encountered: