Files
Josh StoryandGitHub d49f449f94 [Cache Components] Reset PrerenderStore after generating RSC payload (#82286)
The RSC payload ideally would be constructed during the prerender.
However it is not currently sync and RSC doesn't provide a top level way
to produce an object child from a function at the root so we generate
the component tree before starting the render.

However we use the workUnitStore type to govern certain behaviors within
the RSC payload generation for instance preparing things like
searchParams and params props for layouts and pages.

So at the moment we scope the RSC generation inside the same
workUnitStore instance that will also scope the prerender. This is fine
except there are certain things that apply in the prerender context that
do not apply in the component tree generation. Namely we do not want to
track Sync IO as need to abort the prerender. This would lead to the
entire prerender being aborted before it even begins.

There are a few options. We could create a new workUnitStore type. This
isn't great b/c we have so many places where we need to exhaustively
check this.

We could use a new phase to similarly track whether we're before render
or not however this has the same problem of all places where phase is
considered needing to be aware of this additional possible phase.

Instead I think we ought to leave the logic of the code that determines
what to do simple and continue to track the sync IO but we just reset
the dynamic tracking and abort controllers so that the render starts
afresh with these.
2025-08-01 20:43:37 -07:00

21 lines
857 B
TypeScript

export default function Page() {
return (
<>
<p>
This test does some hacky stuff to cause a `Math.random()` call to
happen during the component tree creation which happens before the RSC
render. Before the fix that this test accompanied landed this kind of
sync IO was reported as a problem in Dev and in runtime during start. In
practice this would be because of an OTEL span generation during
create-component-tree. With this fix in place the create-component-tree
function will not leak any sync IO results into the final prerender.
</p>
<p>
In the long run we ought to move create-component-tree into the render
itself and ensure the tree structure comports with CacheComponent rules.
This test can be deleted at that time.
</p>
</>
)
}