Unverified Commit 9216ab13 authored by Josh Story's avatar Josh Story Committed by GitHub

[dynamicIO] routes with dynamic segments should be able to be static in dev (#76691)

Dev mode reports static/dynamic behavior using a heuristic when
dynamicIO is enabled. The heuristic previously incorrectly marked routes
as dynamic when they were in fact static as a consequence of refactoring
metadata to support streaming. This update adjust the heuristic to not
incorrectly assume dynamic in these situations.

The root cause is that errors in `onError` cannot be assumed to be valid
if the render has already aborted

Closes NAR-112
parent 6f6001a8
...@@ -387,11 +387,7 @@ async function exportAppImpl( ...@@ -387,11 +387,7 @@ async function exportAppImpl(
strictNextHead: nextConfig.experimental.strictNextHead ?? true, strictNextHead: nextConfig.experimental.strictNextHead ?? true,
deploymentId: nextConfig.deploymentId, deploymentId: nextConfig.deploymentId,
htmlLimitedBots: nextConfig.htmlLimitedBots.source, htmlLimitedBots: nextConfig.htmlLimitedBots.source,
streamingMetadata: streamingMetadata: true,
// Disable streaming metadata when dynamic IO is enabled.
// FIXME: remove dynamic IO guard once we fixed the dynamic indicator case.
// test/e2e/app-dir/dynamic-io/dynamic-io.test.ts - should not have static indicator on not-found route
!nextConfig.experimental.dynamicIO,
experimental: { experimental: {
clientTraceMetadata: nextConfig.experimental.clientTraceMetadata, clientTraceMetadata: nextConfig.experimental.clientTraceMetadata,
expireTime: nextConfig.expireTime, expireTime: nextConfig.expireTime,
......
...@@ -425,11 +425,7 @@ export async function exportPages( ...@@ -425,11 +425,7 @@ export async function exportPages(
enableExperimentalReact: needsExperimentalReact(nextConfig), enableExperimentalReact: needsExperimentalReact(nextConfig),
sriEnabled: Boolean(nextConfig.experimental.sri?.algorithm), sriEnabled: Boolean(nextConfig.experimental.sri?.algorithm),
buildId: input.buildId, buildId: input.buildId,
streamingMetadata: streamingMetadata: true,
// Disable streaming metadata when dynamic IO is enabled.
// FIXME: remove dynamic IO guard once we fixed the dynamic indicator case.
// test/e2e/app-dir/dynamic-io/dynamic-io.test.ts - should not have static indicator on not-found route
!nextConfig.experimental.dynamicIO,
}), }),
// If exporting the page takes longer than the timeout, reject the promise. // If exporting the page takes longer than the timeout, reject the promise.
new Promise((_, reject) => { new Promise((_, reject) => {
......
...@@ -2446,6 +2446,7 @@ async function spawnDynamicValidationInDev( ...@@ -2446,6 +2446,7 @@ async function spawnDynamicValidationInDev(
} }
) )
let rootDidError = false
const serverPhasedStream = serverPrerenderStreamResult.asPhasedStream() const serverPhasedStream = serverPrerenderStreamResult.asPhasedStream()
try { try {
const prerender = require('react-dom/static.edge') const prerender = require('react-dom/static.edge')
...@@ -2476,7 +2477,12 @@ async function spawnDynamicValidationInDev( ...@@ -2476,7 +2477,12 @@ async function spawnDynamicValidationInDev(
isPrerenderInterruptedError(err) || isPrerenderInterruptedError(err) ||
finalClientController.signal.aborted finalClientController.signal.aborted
) { ) {
requestStore.usedDynamic = true if (!rootDidError) {
// If the root errored before we observe this error then it wasn't caused by something dynamic.
// If the root did not error or is erroring because of a sync dynamic API or a prerender interrupt error
// then we are a dynamic route.
requestStore.usedDynamic = true
}
const componentStack = errorInfo.componentStack const componentStack = errorInfo.componentStack
if (typeof componentStack === 'string') { if (typeof componentStack === 'string') {
...@@ -2501,6 +2507,7 @@ async function spawnDynamicValidationInDev( ...@@ -2501,6 +2507,7 @@ async function spawnDynamicValidationInDev(
} }
) )
} catch (err) { } catch (err) {
rootDidError = true
if ( if (
isPrerenderInterruptedError(err) || isPrerenderInterruptedError(err) ||
finalClientController.signal.aborted finalClientController.signal.aborted
......
...@@ -600,11 +600,7 @@ export default abstract class Server< ...@@ -600,11 +600,7 @@ export default abstract class Server<
isExperimentalCompile: this.nextConfig.experimental.isExperimentalCompile, isExperimentalCompile: this.nextConfig.experimental.isExperimentalCompile,
// `htmlLimitedBots` is passed to server as serialized config in string format // `htmlLimitedBots` is passed to server as serialized config in string format
htmlLimitedBots: this.nextConfig.htmlLimitedBots, htmlLimitedBots: this.nextConfig.htmlLimitedBots,
streamingMetadata: streamingMetadata: true,
// Disable streaming metadata when dynamic IO is enabled.
// FIXME: remove dynamic IO guard once we fixed the dynamic indicator case.
// test/e2e/app-dir/dynamic-io/dynamic-io.test.ts - should not have static indicator on not-found route
!this.nextConfig.experimental.dynamicIO,
experimental: { experimental: {
expireTime: this.nextConfig.expireTime, expireTime: this.nextConfig.expireTime,
clientTraceMetadata: this.nextConfig.experimental.clientTraceMetadata, clientTraceMetadata: this.nextConfig.experimental.clientTraceMetadata,
......
...@@ -159,10 +159,16 @@ function runTests(options: { withMinification: boolean }) { ...@@ -159,10 +159,16 @@ function runTests(options: { withMinification: boolean }) {
throw new Error('expected build not to fail for fully static project') throw new Error('expected build not to fail for fully static project')
} }
expect(next.cliOutput).toContain('ƒ / ') if (WITH_PPR) {
const $ = await next.render$('/') expect(next.cliOutput).toContain('◐ / ')
expect($('#dynamic').text()).toBe('Dynamic') const $ = await next.render$('/')
expect($('[data-fallback]').length).toBe(0) expect($('#dynamic').text()).toBe('Dynamic')
expect($('[data-fallback]').length).toBe(1)
} else {
expect(next.cliOutput).toContain('ƒ / ')
const $ = await next.render$('/')
expect($('#dynamic').text()).toBe('Dynamic')
}
}) })
}) })
......
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