[test] Add deploy coverage for a non-ASCII postponed state
A PPR route whose postponed state contains a multi-byte character is
served with a corrupt document on Vercel, while the same build serves it
correctly under `next start`. This adds a deploy test for that, built
around two routes that differ only in a single character: `/ascii`
renders a list item keyed `Doppelganger`, and `/non-ascii` keys the same
item `Doppelgänger`.
The key is what carries the character into the postponed state. React
records every element enclosing a postponed boundary as a replay node
and copies its `key` in verbatim, so keying the list item that wraps the
boundary puts the label into the serialized state rather than only into
the prerendered HTML. `ä` occupies two bytes in UTF-8 but a single
UTF-16 code unit, which is enough to make the state's byte length exceed
its `String.prototype.length`. The `/revalidated` route additionally
holds a tagged `use cache` entry, so the test can invalidate that tag
through `app/api/revalidate/route.js` and assert the same invariant
against a cache entry produced by revalidation rather than one written
at build time. Those two cases are handled by different code, so neither
covers the other.
Three of the five tests fail on deploy today and all of them pass in dev
and start. The served document arrives as `l<!DOCTYPE html>`, and a
client-side navigation to the affected route ends on the "This page
couldn't load" screen with React error #412 ("Connection closed"),
because the same stray byte in front of the RSC payload shifts the first
flight row id, so the row the model references never resolves. Two
different lengths are involved here, and only one of them is wrong.
Inside the serialized state, Next.js writes a length prefix in UTF-16
code units and reads it back with `String.prototype.slice`, so that pair
agrees with itself. The `state-length` parameter on the
`application/x-nextjs-pre-render` content type is a byte offset into the
cached body, used to separate the postponed state from the prerendered
content, and it is the one currently measured in UTF-16 code units, so
the split lands short whenever the state is not pure ASCII. The local
modes pass because nothing there divides the state by a byte offset.
Note that `/ascii` and `/non-ascii` deliberately avoid `use cache`,
which keeps their Resume Data Cache empty and its serialized tail the
literal `null`. Any truncation of that tail fails to inflate, so those
two routes fail loudly. `/revalidated` has a base64 tail instead, where
dropping the final byte can still inflate, so on that route the resume
survives and the leading stray byte is the only signal. The comments in
the fixture record this so the assertions are not tightened into
something that only holds for one of the two shapes.
Showing
Please
register
or
sign in
to comment