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

restore next14 sync base branch #31841

Merged
merged 1 commit into from
Dec 18, 2024
Merged

Conversation

gnoff
Copy link
Collaborator

@gnoff gnoff commented Dec 18, 2024

The original commit for nextjs 14 is 14898b6 but since that was lost in the facebook repo of React when the next nextjs-sync branch was created it is being restored

… without relying on render-time assertions (facebook#28580)

(cherrypick b09e102 facebook#28568)

[Fizz] Prevent uncloned large precomputed chunks without relying on
render-time assertions (facebook#28568)

A while back we implemented a heuristic that if a chunk was large it was
assumed to be produced by the render and thus was safe to stream which
results in transferring the underlying object memory. Later we ran into
an issue where a precomputed chunk grew large enough to trigger this
hueristic and it started causing renders to fail because once a second
render had occurred the precomputed chunk would not have an underlying
buffer of bytes to send and these bytes would be omitted from the
stream. We implemented a technique to detect large precomputed chunks
and we enforced that these always be cloned before writing.
Unfortunately our test coverage was not perfect and there has been for a
very long time now a usage pattern where if you complete a boundary in
one flush and then complete a boundary that has stylehsheet dependencies
in another flush you can get a large precomputed chunk that was not
being cloned to be sent twice causing streaming errors.

I've thought about why we even went with this solution in the first
place and I think it was a mistake. It relies on a dev only check to
catch paired with potentially version specific order of operations on
the streaming side. This is too unreliable. Additionally the low limit
of view size for Edge is not used in Node.js but there is not real
justification for this.

In this change I updated the view size for edge streaming to match Node
at 2048 bytes which is still relatively small and we have no data one
way or another to preference 512 over this. Then I updated the assertion
logic to error anytime a precomputed chunk exceeds the size. This
eliminates the need to clone these chunks by just making sure our view
size is always larger than the largest precomputed chunk we can possibly
write. I'm generally in favor of this for a few reasons.

First, we'll always know during testing whether we've violated the limit
as long as we exercise each stream config because the precomputed chunks
are created in module scope. Second, we can always split up large chunks
so making sure the precomptued chunk is smaller than whatever view size
we actually desire is relatively trivial.
Copy link

vercel bot commented Dec 18, 2024

@sebmarkbage is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Dec 18, 2024
@gnoff gnoff changed the title Cherry-pick #31840 restore next14 sync base branch Dec 18, 2024
@gnoff gnoff merged commit 1db6222 into facebook:sync-nextjs-14 Dec 18, 2024
36 of 38 checks passed
@gnoff gnoff deleted the next14-base branch December 18, 2024 21:26
ztanner added a commit to vercel/next.js that referenced this pull request Dec 19, 2024
Updates React from 14898b6a9 to 178c267a4e.

### React upstream changes

- facebook/react#31842
- facebook/react#31841
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants