The Wayback Machine - https://web.archive.org/web/20220119043159/https://github.com/facebook/react/issues/19701
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

Bug: Context.Consumer inside Suspense does not receive context updates while suspended #19701

Open
overlookmotel opened this issue Aug 26, 2020 · 5 comments · May be fixed by #21414 or #23095
Open

Bug: Context.Consumer inside Suspense does not receive context updates while suspended #19701

overlookmotel opened this issue Aug 26, 2020 · 5 comments · May be fixed by #21414 or #23095

Comments

@overlookmotel
Copy link
Contributor

@overlookmotel overlookmotel commented Aug 26, 2020

A <Context.Consumer> callback inside a suspended <Suspense> boundary does not receive updates when context value changes.

This issue was originally found with React Router (remix-run/react-router#7137) but can be reproduced with React alone.

React version: 16.13.1 or 17.0.0-rc.0 (and at least some earlier versions too)

Steps To Reproduce

https://codesandbox.io/s/suspense-context-test-case-6jlsq

The current behavior

In the example above, clicking on the "About" button puts the <Suspense> boundary into a suspended state. Clicking "Home" updates the context value, but the <Context.Consumer> callback is not called with this updated value. Therefore the page never navigates back to "Home".

Please note that Received context: home is not logged after the "Home" button is pressed.

The expected behavior

The <Context.Consumer> callback should be called with value 'home' when the value of the context is updated.

Please note that the problem does not occur if any of:

  1. the Suspense boundary is never suspended (uncomment the first line of About function to verify).
  2. useContext() is used in place of <Context.Consumer> (substitute <SwitchWithUseContext /> for <Switch />).
  3. the contents of Switch function is inlined within the <Suspense> rather than in a separate component.

The last of these leads me to suspect that the problem may be related to #17356. In the example, <Context.Consumer> is within a Switch component. But the <Switch> element inside <Suspense> never changes - so it's effectively memoized. I wonder if this is why it doesn't receive context updates?

@gaearon
Copy link
Member

@gaearon gaearon commented Aug 26, 2020

Can you turn this into a failing test, like we did for #17356?

@overlookmotel
Copy link
Contributor Author

@overlookmotel overlookmotel commented Aug 26, 2020

overlookmotel added a commit to overlookmotel/react that referenced this issue Aug 26, 2020
@engprodigy
Copy link

@engprodigy engprodigy commented Sep 25, 2020

@overlookmotel and @gaearon This is looking abandoned. Can I take a look at it?

@overlookmotel
Copy link
Contributor Author

@overlookmotel overlookmotel commented Sep 25, 2020

@engprodigy I've submitted PR #19702 with a failing test. Personally, I'd very much appreciate your input if you have any ideas for a fix.

@engprodigy
Copy link

@engprodigy engprodigy commented Oct 1, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment