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: [Sync mode] Effects are not re-run after suspense completes #18141

Closed
1000hz opened this issue Feb 26, 2020 · 3 comments
Closed

Bug: [Sync mode] Effects are not re-run after suspense completes #18141

1000hz opened this issue Feb 26, 2020 · 3 comments
Labels
Resolution: Wontfix Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@1000hz
Copy link

1000hz commented Feb 26, 2020

As reported in #14536, React mounts suspended components to the DOM with display:none and fires effects before the components are visible. Once suspense has completed, effects are not re-run. This means that any component that reads layout info from the DOM becomes visible with content based on a stale layout.

React version: 16.12.0

Steps To Reproduce

  1. Create a component that reads layout info from the DOM
  2. Render that component in a suspense alongside a lazy component

Link to code example: https://codesandbox.io/s/busy-jang-75wmf

The current behavior

The layout-dependent component is rendered incorrectly based on when it was still invisible.

The expected behavior

The layout-dependent component should render correctly regardless of whether or not siblings are lazy and caused suspense.

@1000hz 1000hz added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Feb 26, 2020
@bvaughn
Copy link
Contributor

bvaughn commented Feb 26, 2020

cc @lunaruan in case this ties into the hidden stuff any.

@gaearon
Copy link
Collaborator

gaearon commented Feb 26, 2020

My understanding is that this is not possible to fix in the legacy (ReactDOM.render) mode. Sorry. It's a quirk of the legacy mode which we can't fix without introducing other breaking changes. This is solved in Blocking Mode and Concurrent Mode, but they are only available in experimental releases for now.

@gaearon
Copy link
Collaborator

gaearon commented Mar 29, 2022

This is fixed in React 18.

https://codesandbox.io/s/admiring-forest-tsnnbq?file=/src/index.js

You need to upgrade to createRoot() for the fix to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Wontfix Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

3 participants