Skip to content

Commit

Permalink
Fix static indicator for pure IO case (vercel#72639)
Browse files Browse the repository at this point in the history
Follow-up to vercel#72631 this ensures
we properly update the `requestStore` when we detect pure IO case and no
dynamic methods are used like `cookies()` or `headers()` e.g. just a
fetch with no caching opts enabled.

---------

Co-authored-by: Zack Tanner <[email protected]>
  • Loading branch information
ijjk and ztanner authored Nov 13, 2024
1 parent 3c3710b commit 0bc2346
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ async function generateDynamicFlightRenderResult(
ctx,
false,
ctx.clientReferenceManifest,
ctx.workStore.route
ctx.workStore.route,
requestStore
)
}

Expand Down Expand Up @@ -1654,7 +1655,8 @@ async function renderToStream(
ctx,
res.statusCode === 404,
clientReferenceManifest,
workStore.route
workStore.route,
requestStore
)

reactServerResult = new ReactServerResult(reactServerStream)
Expand Down Expand Up @@ -1980,7 +1982,8 @@ async function spawnDynamicValidationInDev(
ctx: AppRenderContext,
isNotFound: boolean,
clientReferenceManifest: NonNullable<RenderOpts['clientReferenceManifest']>,
route: string
route: string,
requestStore: RequestStore
): Promise<void> {
const { componentMod: ComponentMod } = ctx

Expand Down Expand Up @@ -2235,6 +2238,8 @@ async function spawnDynamicValidationInDev(
isPrerenderInterruptedError(err) ||
finalClientController.signal.aborted
) {
requestStore.usedDynamic = true

const componentStack: string | undefined = (errorInfo as any)
.componentStack
if (typeof componentStack === 'string') {
Expand Down
14 changes: 13 additions & 1 deletion test/e2e/app-dir/dynamic-io/dynamic-io.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('dynamic-io', () => {
return staticIndicatorPresent
}

it('should not have static indicator on dynamic route', async () => {
it('should not have static indicator on dynamic method route', async () => {
const browser = await next.browser('/cases/dynamic_api_cookies')

await retry(async () => {
Expand All @@ -41,6 +41,18 @@ describe('dynamic-io', () => {
expect(await hasStaticIndicator(browser)).toBe(false)
})

it('should not have static indicator on dynamic IO route', async () => {
const browser = await next.browser('/cases/fetch_mixed')

await retry(async () => {
expect(await browser.eval('!!window.next.router ? "yes": "no"')).toBe(
'yes'
)
})

expect(await hasStaticIndicator(browser)).toBe(false)
})

it('should have static indicator on static route', async () => {
const browser = await next.browser('/cases/static')

Expand Down

0 comments on commit 0bc2346

Please sign in to comment.