-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Reactive variables stop working with Fast Refresh #6661
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
Comments
Does the fast refresh plugin have any sort of API that modules can hook into to clean up / recreate resources before/after the module is refreshed? If I recall correctly, Webpack had a Worth mentioning: hot module replacement systems tend to disregard resource management by default, except in narrow cases (like with React components) where the system has been designed around refreshing a particular type of module with a particular kind of export (i.e. just a single React component). Getting it to work well in general requires some manual effort, which almost no one who uses HMR with React seems to realize. The difficulty of solving this problem in a general way is why these plugins often label themselves as EXPERIMENTAL. |
Thanks for the quick response! I think I get your point that getting HMR to work well often requires some manual effort (especially when using experimental plugins), but Fast-Refresh is fully supported by React and should definitely be working out-of-the-box with Apollo Client. The ubiquity (borderline necessity) of HMR/FR means that any feature that doesn’t support it is going to have a hard time being adopted widely. If fast-refresh makes reactive variables no longer reactive, that seems to be a clear indication that there’s something wrong with the RV setup. I’m a little new to all this, so take this somewhat with a grain of salt, but here are some things that could potentially be causing this issue:
I might totally be wrong about these, but since fast-refresh is getting more and more popular, I really believe that there’s something here that needs to be fixed. Thanks! |
Cross-referencing an explanation about how Fast Refresh works: #5870 (comment). Instead of a special API to "hook into" it I believe the fix is to handle the semantics of how it re-runs the Hooks. |
I found this issue because I'm using next.js with Apollo Client and reactive variables. |
Hi,
I just started using Apollo Client v3 and reactive variables in my react-native-web app. I've also been using a webpack plugin that enables "Fast Refresh" (https://github.com/pmmmwh/react-refresh-webpack-plugin). I've run into a problem where, whenever I update a file that triggers a fast refresh, my reactive variables essentially stop working.
I'm using the following code:
Intended outcome:
Normally, if i call
userVar(newUser)
, the UserProfile page will rerun the query and return the new user. This is what should happen even after a Fast Refresh is triggeredActual outcome:
Once fast refresh is triggered, calling
userVar(newUser)
doesn't rerun the query and the UserProfile component doesn't rerender.How to reproduce the issue:
Add the following code to your webpack.config.js to enable fast refresh:
Versions
@apollo/client: 3.0.0
The text was updated successfully, but these errors were encountered: