GithubHelp home page GithubHelp logo

Comments (12)

guillaumebrunerie avatar guillaumebrunerie commented on June 24, 2024 3

For what it's worth, styled-components worked around this bug by simply using useLayoutEffect instead of useInsertionEffect. Maybe Emotion could do the same in the mean time?

from react.

Andarist avatar Andarist commented on June 24, 2024 1

@gaearon yes! I actually started to work on a PR locally - it's very draft-ish and I only fixed one of the discrepancies so far. Gonna open a draft PR later today.

from react.

Andarist avatar Andarist commented on June 24, 2024

I was just about to report the same issue (my repro case can be found here, it's prepared based on @jmca's repro for the issue caused by this - but it's essentially the same repro as yours).

I think that useInsertionEffect is essentially the same as useLayoutEffect, it's just that they have a "higher priority" and they are executed first, in a batch, before useLayoutEffects. So I'm heavily leaning towards your conclusion - this is a bug in React. All other semantics of layout effects should be shared between useInsertionEffect and useLayoutEffect (such as semantics in suspense boundaries, mounting/unmounting them appropriately in Offscreen components, their reappearing and more)

from react.

gaearon avatar gaearon commented on June 24, 2024

Seems like a bug. Anyone wants to look into fixing it?

from react.

Andarist avatar Andarist commented on June 24, 2024

To rephrase what the observed issue here is:

  1. insertion effects are not disconnected when the suspended subtree gets hidden
  2. they are also not disconnected when a different subtree gets finally rendered (when Suspense resumes~)
  3. to get them to disconnect we need to "revisit" the old component and switch away from it without suspending.
  4. this doesn't match how any other type of effects work. I'd expect those effects to get disconnected in the similar vein as layout effects are but if that's not desirable for some reason then they likely should be disconnected just like passive effects (or using some different semantics of their own but the bottom line is that they should be disconnected at some point)

from react.

sebmarkbage avatar sebmarkbage commented on June 24, 2024

This is intentional to avoid layout thrash when things are hidden and restored. It's also to allow for hidden trees to be able to do early preemptive layout calculations for hidden trees so that they can be instantly restored.

from react.

Andarist avatar Andarist commented on June 24, 2024

Hmm, but that cleanup has to be called at some point in time - when that is?

from react.

sebmarkbage avatar sebmarkbage commented on June 24, 2024

When the Suspense boundary itself is committed and deleted or if an update changes it to no longer be visible. I could imagine the second case being a bug since itโ€™s a thing we typically donโ€™t model at all.

from react.

lubieowoce avatar lubieowoce commented on June 24, 2024

When the Suspense boundary itself is committed and deleted

unless i'm misunderstanding, this doesn't seem to be the case,Page2.tsx,Page1.tsx

Repro: press "Go to Page 1", "Go to Page 2", "Just unmount the whole thing". the suspense boundary and the suspending children below all get destroyed, but the background stays pink (i.e. Page1's useInsertionEffect is not actually cleaned up)

Interestingly, this only acts "strange" when Page1 or Page2 suspend, not when they're already available. reproducible like this:

  • Initial page
  • Go to Page 1 (suspends, then makes the background pink)
  • Go to Page 2 (suspends, Page1's insertion isn't cleaned up = bg stays pink)
  • Go back to Page 1 (doesn't suspend anymore, runs insertion effect)
  • Go to Page 2 (doesn't suspend anymore, Page1's insertion effect is cleaned up this time = bg restored to white)

maybe i'm missing something, but i'd expect insertion cleanups to behave the same regardless of whether something suspensey happened (i.e Page2 suspended, Page1 got hidden, and never came back) or not.

from react.

lpolito avatar lpolito commented on June 24, 2024

Was there any movement on this? I ran into the same issue linked by @Andarist , specifically with Emotion's Global component not calling the clean up on unmount.

In my case all components are wrapped inside of React.lazy() because that's how we have our page route components set up (all pages being lazily loaded).

from react.

fsjsd avatar fsjsd commented on June 24, 2024

Any movement on this one?

from react.

owenashurst avatar owenashurst commented on June 24, 2024

I had to downgrade to React 17.0.2 to resolve this for now.

from react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.