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

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

Merged
merged 1 commit into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/next/src/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,7 @@ async function exportAppImpl(
strictNextHead: nextConfig.experimental.strictNextHead ?? true,
deploymentId: nextConfig.deploymentId,
htmlLimitedBots: nextConfig.htmlLimitedBots.source,
streamingMetadata:
// 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,
streamingMetadata: true,
experimental: {
clientTraceMetadata: nextConfig.experimental.clientTraceMetadata,
expireTime: nextConfig.expireTime,
Expand Down
6 changes: 1 addition & 5 deletions packages/next/src/export/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,7 @@ export async function exportPages(
enableExperimentalReact: needsExperimentalReact(nextConfig),
sriEnabled: Boolean(nextConfig.experimental.sri?.algorithm),
buildId: input.buildId,
streamingMetadata:
// 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,
streamingMetadata: true,
}),
// If exporting the page takes longer than the timeout, reject the promise.
new Promise((_, reject) => {
Expand Down
9 changes: 8 additions & 1 deletion packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2446,6 +2446,7 @@ async function spawnDynamicValidationInDev(
}
)

let rootDidError = false
const serverPhasedStream = serverPrerenderStreamResult.asPhasedStream()
try {
const prerender = require('react-dom/static.edge')
Expand Down Expand Up @@ -2476,7 +2477,12 @@ async function spawnDynamicValidationInDev(
isPrerenderInterruptedError(err) ||
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
if (typeof componentStack === 'string') {
Expand All @@ -2501,6 +2507,7 @@ async function spawnDynamicValidationInDev(
}
)
} catch (err) {
rootDidError = true
if (
isPrerenderInterruptedError(err) ||
finalClientController.signal.aborted
Expand Down
6 changes: 1 addition & 5 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,7 @@ export default abstract class Server<
isExperimentalCompile: this.nextConfig.experimental.isExperimentalCompile,
// `htmlLimitedBots` is passed to server as serialized config in string format
htmlLimitedBots: this.nextConfig.htmlLimitedBots,
streamingMetadata:
// 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,
streamingMetadata: true,
experimental: {
expireTime: this.nextConfig.expireTime,
clientTraceMetadata: this.nextConfig.experimental.clientTraceMetadata,
Expand Down
14 changes: 10 additions & 4 deletions test/e2e/app-dir/dynamic-io-errors/dynamic-io-errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,16 @@ function runTests(options: { withMinification: boolean }) {
throw new Error('expected build not to fail for fully static project')
}

expect(next.cliOutput).toContain('ƒ / ')
const $ = await next.render$('/')
expect($('#dynamic').text()).toBe('Dynamic')
expect($('[data-fallback]').length).toBe(0)
if (WITH_PPR) {
expect(next.cliOutput).toContain('◐ / ')
const $ = await next.render$('/')
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')
}
})
})

Expand Down
Loading