GithubHelp home page GithubHelp logo

Comments (1)

lubieowoce avatar lubieowoce commented on April 28, 2024

this might be a duplicate of #27729

(i guess it comes up in an RSC scenario because client references are wrapped with Lazy?)

I've been debugging this alongside @ziir, and I've managed to whittle this down to a much smaller repro that doesn't involve RSC at all, just a Thenable<ReactNode> that contains a lazy component with a use() call inside.

https://codesandbox.io/p/sandbox/fizz-promise-leak-between-components-in-use-in-a-lazy-component-ppy4v8?file=%2Fsrc%2Findex.tsx%3A16%2C1-17%2C1

Expected output:
Screenshot 2023-11-21 at 03 12 47

Actual output:
Screenshot 2023-11-21 at 03 13 12

"A nested promise for Use" is what's in the promise that gets use()-ed. But the use() returns a whole chunk of other stuff instead.

I believe this is related to lazy() components, because uncommenting this bit here actually stops the issue from appearing:

const LazyUse = lazy(() => sleep(20).then(() => ({ default: Use })));
// const LazyUse = Use; // fixes the issue!

In summary, the issue seems to go like this:

  1. Render a promise (promise1) of JSX as a child of the shell
  2. Have a lazy component in that JSX
  3. call use(promise2) within that lazy component. use will act as if use(promise1) was called instead, so it returns the wrong thing.

Notably, this only seems to happen on the first request. The codesandbox caches the response so that it's easily viewable (also their preview does two requests, so it's not visible.)


Based on some poking around in the react internals, the issue seems to come from an incorrectly restored thenableState. when the Use component runs, thenableState is set to an array containing the promise returned from getAsyncContent instead of null, so use just returns that (via this line in trackUsedThenable). My guess is that this is somehow related to lazy() using the legacy suspense implementation, but that's as far as i've gotten.

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.