Skip to content

Commit

Permalink
store isPrerender flag in RSC payload
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Sep 30, 2024
1 parent c6f4405 commit ca96740
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
RSC_HEADER,
RSC_CONTENT_TYPE_HEADER,
NEXT_HMR_REFRESH_HEADER,
NEXT_IS_PRERENDER_HEADER,
NEXT_DID_POSTPONE_HEADER,
} from '../app-router-headers'
import { callServer } from '../../app-call-server'
Expand Down Expand Up @@ -176,7 +175,6 @@ export async function fetchServerResponse(

const contentType = res.headers.get('content-type') || ''
const interception = !!res.headers.get('vary')?.includes(NEXT_URL)
const isPrerender = !!res.headers.get(NEXT_IS_PRERENDER_HEADER)
const postponed = !!res.headers.get(NEXT_DID_POSTPONE_HEADER)
let isFlightResponse = contentType.startsWith(RSC_CONTENT_TYPE_HEADER)

Expand Down Expand Up @@ -223,7 +221,7 @@ export async function fetchServerResponse(
flightData: normalizeFlightData(response.f),
canonicalUrl: canonicalUrl,
couldBeIntercepted: interception,
isPrerender: isPrerender,
isPrerender: response.S,
postponed,
}
} catch (err) {
Expand Down
3 changes: 3 additions & 0 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ async function generateDynamicRSCPayload(
return {
b: ctx.renderOpts.buildId,
f: flightData,
S: staticGenerationStore.isStaticGeneration,
}
}

Expand Down Expand Up @@ -642,6 +643,7 @@ async function getRSCPayload(
m: missingSlots,
G: GlobalError,
s: typeof ctx.renderOpts.postponed === 'string',
S: staticGenerationStore.isStaticGeneration,
}
}

Expand Down Expand Up @@ -731,6 +733,7 @@ async function getErrorRSCPayload(
f: [[initialTree, initialSeedData, initialHead]],
G: GlobalError,
s: typeof ctx.renderOpts.postponed === 'string',
S: staticGenerationStore.isStaticGeneration,
} satisfies InitialRSCPayload
}

Expand Down
4 changes: 4 additions & 0 deletions packages/next/src/server/app-render/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ export type InitialRSCPayload = {
G: React.ComponentType<any>
/** postponed */
s: boolean
/** isPrerender */
S: boolean
}

// Response from `createFromFetch` for normal rendering
Expand All @@ -231,6 +233,8 @@ export type NavigationFlightResponse = {
b: string
/** flightData */
f: FlightData
/** isPrerender */
S: boolean
}

// Response from `createFromFetch` for server actions. Action's flight data can be null
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/app-dir/app-prefetch/prefetching.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ describe('app dir - prefetching', () => {
0
)
})

// navigate to the static page
await browser.elementByCss('[href="/static-page"]').click()

// We still shouldn't see any requests
await retry(async () => {
expect(rscRequests.filter((req) => req === '/static-page').length).toBe(
0
)
})
})

it('should not re-fetch the initial dynamic page if the same page is prefetched with prefetch={true}', async () => {
Expand Down

0 comments on commit ca96740

Please sign in to comment.