Skip to content
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

Subscription prematurely closed w/ useSubscription + webpack + react-fast-refresh (plus possible simple fix) #6405

Closed
papercuptech opened this issue Jun 6, 2020 · 2 comments

Comments

@papercuptech
Copy link

Intended outcome:
When changing JSX of func component that uses useSubscription, while webpack-dev-server --hot is running, underlying subscription should not be lost; i.e. source pushes should still result in useSubscription causing re-render.

Actual outcome:
After first change to func component, source changes pushed no longer cause useSubscription to cause re-render.

How to reproduce the issue:
Minimal setup of webpack, @pmmmwh/react-refresh-webpack-plugin, react-refresh

Possible fix
I changed this:

if (this.currentObservable.subscription) {

to this (quick hack in node_modules/@apollo... to see if would work)

    if (this.currentObservable.subscription && !this.isMounted) {

Simple breakpoint testing for a component fast-refreshed vs. one that has been unmounted appears to indicate adding && !this.isMounted solves the problem;i.e. this.isMounted === true when endSubscription called as part of fast-refresh processing, and this.isMounted === false when endSubsctiption called for a component no longer in (i.e. unmounting /ed or 'leaving') render tree.

Versions
System:
OS: Windows 10 10.0.18363
Binaries:
Node: 14.2.0 - ~\AppData\Local\nvs\default\node.EXE
npm: 6.14.4 - ~\AppData\Local\nvs\default\npm.CMD
Browsers:
Edge: 44.18362.449.0
npmPackages:
@apollo/client: ^3.0.0-rc.2 => 3.0.0-rc.2
@apollo/link-ws: ^2.0.0-beta.3 => 2.0.0-beta.3

@nodabladam
Copy link

nodabladam commented Jun 11, 2020

On my apollo client 2.6 dev machine when I am doing development unrelated to apollo (css/jsx changes), I seem to occasionally get some errors about subscribeToMore being undefined. I haven't been able to figure out why or how to stop it. It feels related to this issue and it would certainly be nice for this to be fixed in 3.

@hwillson
Copy link
Member

Let us know if this is still a concern with @apollo/client@latest - thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants