Unverified Commit adf7540e authored by Josh Story's avatar Josh Story Committed by GitHub

Revert "Avoid a premature Suspense fallback flash in the streaming dev render…"

This reverts commit 66496a4c.
parent 573bb7f6
......@@ -89,15 +89,6 @@ type SpaFetchServerResponseResult = {
runtimePrefetchStream: ReadableStream<Uint8Array> | null
responseHeaders: Headers
debugInfo: Array<any> | null
/**
* Dev only: resolves once the server has flushed the shell-stage content to
* the stream (or earlier, on a cache miss). The navigation defers revealing
* the response (resolving its deferred RSCs) until this settles, so React
* doesn't render a boundary's children before their row has been decoded and
* commit a premature Suspense fallback. `null` outside the streaming dev
* render.
*/
revealAfter: Promise<void> | null
}
type MpaFetchServerResponseResult = string
......@@ -310,7 +301,6 @@ export async function fetchServerResponse(
runtimePrefetchStream: flightResponse.p ?? null,
responseHeaders: res.headers,
debugInfo: flightResponsePromise._debugInfo ?? null,
revealAfter: flightResponse._revealAfter ?? null,
}
} catch (err) {
// If the fetch rejected due to a network error, wait for connectivity
......
......@@ -1802,8 +1802,7 @@ async function fetchMissingDynamicData(
seed.data,
seed.head,
dynamicStaleAt,
result.debugInfo,
result.revealAfter
result.debugInfo
)
return {
......@@ -1831,18 +1830,11 @@ function writeDynamicDataIntoNavigationTask(
dynamicData: CacheNodeSeedData | null,
dynamicHead: HeadData,
dynamicStaleAt: number,
debugInfo: Array<any> | null,
revealAfter: Promise<void> | null
debugInfo: Array<any> | null
): boolean {
if (task.status === NavigationTaskStatus.Pending && dynamicData !== null) {
task.status = NavigationTaskStatus.Fulfilled
finishPendingCacheNode(
task.node,
dynamicData,
dynamicHead,
debugInfo,
revealAfter
)
finishPendingCacheNode(task.node, dynamicData, dynamicHead, debugInfo)
// Update the BFCache entry's staleAt for this segment with the value
// from the dynamic response. This applies the per-page
......@@ -1901,8 +1893,7 @@ function writeDynamicDataIntoNavigationTask(
dynamicDataChild,
dynamicHead,
dynamicStaleAt,
debugInfo,
revealAfter
debugInfo
)
if (childDidReceiveUnknownParallelRoute) {
didReceiveUnknownParallelRoute = true
......@@ -1925,8 +1916,7 @@ function finishPendingCacheNode(
cacheNode: CacheNode,
dynamicData: CacheNodeSeedData,
dynamicHead: HeadData,
debugInfo: Array<any> | null,
revealAfter: Promise<void> | null
debugInfo: Array<any> | null
): void {
// Writes a dynamic response into an existing Cache Node tree. This does _not_
// create a new tree, it updates the existing tree in-place. So it must follow
......@@ -1959,21 +1949,7 @@ function finishPendingCacheNode(
// This is a deferred RSC promise. We can fulfill it with the data we just
// received from the server. If it was already resolved by a different
// navigation, then this does nothing because we can't overwrite data.
//
// In the streaming dev render, defer the fill until `revealAfter` settles,
// so React doesn't render the boundary's children before their row has been
// decoded (otherwise it suspends on the still-pending children and commits
// a premature fallback). Outside that render `revealAfter` is null and we
// resolve immediately.
if (revealAfter !== null) {
const resolveRsc = () => rsc.resolve(dynamicSegmentData, debugInfo)
// Use the same callback for both outcomes: we don't expect `revealAfter`
// to reject, but if it ever did (e.g. a connection drop mid-stream) we'd
// still want to resolve the RSC.
revealAfter.then(resolveRsc, resolveRsc)
} else {
rsc.resolve(dynamicSegmentData, debugInfo)
}
rsc.resolve(dynamicSegmentData, debugInfo)
} else {
// This is not a deferred RSC promise, nor is it empty, so it must have
// been populated by a different navigation. We must not overwrite it.
......
......@@ -578,21 +578,6 @@ async function navigateToUnknownRoute(
}
}
// In the streaming dev render, this single response's seed content may still
// be streaming when we build the tree below. An unknown-route navigation
// places that content inline (it has no prior cache entry, so the server
// sends a full seed rather than the dynamic-only delta a known route gets),
// and that inline content is not gated like a known route's deferred RSCs. So
// React could read a still-pending chunk and flash a Suspense fallback
// (wanted on a cold cache, but not on a warm one). Wait for the shell to
// flush (`revealAfter`) first, so the inline seed content is decoded by the
// time React reads it, the same way the known-route path gates its deferred
// RSCs. `revealAfter` is null outside the streaming dev render. On a cache
// miss it resolves early, so the cold-cache fallback is still shown.
if (result.revealAfter !== null) {
await result.revealAfter
}
return navigateToKnownRoute(
now,
state,
......
......@@ -428,18 +428,6 @@ export type InitialRSCPayload = {
* staleness.
*/
d?: number
/**
* revealAfter (dev only). Resolves once the server has flushed the
* shell-stage content to the stream (static shell, or runtime-prefetchable
* shell for runtime-prefetch routes), or earlier on a cache miss. The client
* decodes this from the payload and defers resolving the response's deferred
* RSCs on it, so a boundary's children aren't revealed before their row has
* been decoded (which would flush a premature Suspense fallback). Its
* resolution row follows the children's row in the payload, so the children
* are decoded by the time the client unblocks. The HTML render gates on the
* same signal server-side instead of reading this field.
*/
_revealAfter?: Promise<void>
}
// Response from `createFromFetch` for normal rendering
......@@ -482,18 +470,6 @@ export type NavigationFlightResponse = {
* staleness.
*/
d?: number
/**
* revealAfter (dev only). Resolves once the server has flushed the
* shell-stage content to the stream (static shell, or runtime-prefetchable
* shell for runtime-prefetch routes), or earlier on a cache miss. The client
* decodes this from the payload and defers resolving the response's deferred
* RSCs on it, so a boundary's children aren't revealed before their row has
* been decoded (which would flush a premature Suspense fallback). Its
* resolution row follows the children's row in the payload, so the children
* are decoded by the time the client unblocks. The HTML render gates on the
* same signal server-side instead of reading this field.
*/
_revealAfter?: Promise<void>
}
// Response from `createFromFetch` for server actions. Action's flight data can be null
......
......@@ -62,7 +62,7 @@ describe('cache-components-dev-streaming', () => {
//
// Use instant checks throughout: `elementByCss`/`elementById` also wait for
// the page "load" event, which (with `waitUntil: 'commit'`) only fires once
// the slow cache has filled, which would advance past the very window this
// the slow cache has filled — that would advance past the very window this
// test inspects.
await retry(async () => {
expect(await browser.elementByCssInstant('#dynamic').text()).toBe(
......@@ -136,10 +136,9 @@ describe('cache-components-dev-streaming', () => {
})
it('shows the private-cache fallback on a cold client navigation but not on a warm one', async () => {
// Uses a runtime-prefetch route, whose cached content belongs to the
// runtime shell stage. On a warm navigation the client defers revealing
// the response (via `_revealAfter`) until the server has flushed the shell,
// so the content arrives with the shell and the fallback isn't shown.
// Uses a runtime-prefetch route, whose stream is held back until after the
// runtime stage, so a warm navigation reliably delivers the content with
// the shell and omits the fallback.
const browser = await next.browser('/')
// Cold navigation: the cache misses and fills in the background, so the
......@@ -150,26 +149,22 @@ describe('cache-components-dev-streaming', () => {
expect(await browser.elementByCss('#private-fallback').text()).toBe(
'Loading...'
)
expect(await browser.elementByCss('#private').text()).toBeDateString()
await retry(async () => {
expect(
await browser.elementByCssInstant('#private').text()
).toBeDateString()
})
// Wait for the background write to settle so the next navigation hits the
// warm entry instead of racing a pending write.
await waitFor(2000)
// Hard-reload home so the first navigation below is a fresh, unknown-route
// nav. An unknown route has no prior cache entry, so the server sends the
// content inline in the seed (rather than the dynamic-only delta a known
// route gets), and that inline reveal is gated on `_revealAfter` too, so
// even this first nav delivers the content with the shell. Later iterations
// navigate via back()/forward, exercising the known-route deferred-RSC
// path.
await browser.loadPage(new URL('/', next.url).href)
// Warm navigation: record whether the fallback ever enters the DOM during
// the navigation, even briefly. It shouldn't, since the warm content is
// delivered with the shell.
await browser.loadPage(new URL('/', next.url).href)
await browser.eval(() => {
;(window as any).__privateFallbackSeen = 0
;(window as any).__privateFallbackSeen = false
new MutationObserver((records) => {
records.forEach((record) =>
record.addedNodes.forEach((node) => {
......@@ -178,33 +173,24 @@ describe('cache-components-dev-streaming', () => {
(node.id === 'private-fallback' ||
node.querySelector('#private-fallback'))
) {
;(window as any).__privateFallbackSeen += 1
;(window as any).__privateFallbackSeen = true
}
})
)
}).observe(document.body, { childList: true, subtree: true })
})
// Regression test for a rare client-side race the `_revealAfter` gate
// fixes. The Flight client decodes the response incrementally, so before
// the gate React Fiber could occasionally commit the fallback before the
// children's row was processed, even though the warm content is delivered
// with the shell. Deferring the reveal until `_revealAfter` settles means
// the children are decoded by the time React reads them, so the fallback no
// longer appears. The race was timing-dependent, so a single navigation
// would catch a regression only by luck; we repeat the warm navigation many
// times and assert the fallback never enters the DOM.
for (let i = 0; i < 100; i++) {
await browser
.elementByCss('a[href="/use-cache-private-runtime-prefetch"]')
.click()
expect(await browser.elementByCss('#private').text()).toBeDateString()
await browser.back()
}
await browser
.elementByCss('a[href="/use-cache-private-runtime-prefetch"]')
.click()
await retry(async () => {
expect(
await browser.elementByCssInstant('#private').text()
).toBeDateString()
})
expect(
await browser.eval(() => (window as any).__privateFallbackSeen)
).toBe(0)
).toBe(false)
})
// The following are smoke tests that Cache Components validation still
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment