Unverified Commit b2e898df authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

rename fetchServerResponse response properties (#68814)

This was mirroring the single-key responses that we do on the responses
from the server, but since this is never serialized or passed from
server -> client, there's no reason to make it harder to read!
parent 4a0a8785
...@@ -102,11 +102,11 @@ export function createInitialRouterState({ ...@@ -102,11 +102,11 @@ export function createInitialRouterState({
createPrefetchCacheEntryForInitialLoad({ createPrefetchCacheEntryForInitialLoad({
url, url,
data: { data: {
f: initialFlightData, flightData: initialFlightData,
c: undefined, canonicalUrl: undefined,
i: !!couldBeIntercepted, couldBeIntercepted: !!couldBeIntercepted,
// TODO: the server should probably send a value for this. Default to false for now. // TODO: the server should probably send a value for this. Default to false for now.
p: false, isPrerender: false,
}, },
tree: initialState.tree, tree: initialState.tree,
prefetchCache: initialState.prefetchCache, prefetchCache: initialState.prefetchCache,
......
...@@ -57,10 +57,10 @@ function urlToUrlWithoutFlightMarker(url: string): URL { ...@@ -57,10 +57,10 @@ function urlToUrlWithoutFlightMarker(url: string): URL {
function doMpaNavigation(url: string): FetchServerResponseResult { function doMpaNavigation(url: string): FetchServerResponseResult {
return { return {
f: urlToUrlWithoutFlightMarker(url).toString(), flightData: urlToUrlWithoutFlightMarker(url).toString(),
c: undefined, canonicalUrl: undefined,
i: false, couldBeIntercepted: false,
p: false, isPrerender: false,
} }
} }
...@@ -206,10 +206,10 @@ export async function fetchServerResponse( ...@@ -206,10 +206,10 @@ export async function fetchServerResponse(
} }
return { return {
f: response.f, flightData: response.f,
c: canonicalUrl, canonicalUrl: canonicalUrl,
i: interception, couldBeIntercepted: interception,
p: isPrerender, isPrerender: isPrerender,
} }
} catch (err) { } catch (err) {
console.error( console.error(
...@@ -220,10 +220,10 @@ export async function fetchServerResponse( ...@@ -220,10 +220,10 @@ export async function fetchServerResponse(
// TODO-APP: Add a test for the case where a CORS request fails, e.g. external url redirect coming from the response. // TODO-APP: Add a test for the case where a CORS request fails, e.g. external url redirect coming from the response.
// See https://github.com/vercel/next.js/issues/43605#issuecomment-1451617521 for a reproduction. // See https://github.com/vercel/next.js/issues/43605#issuecomment-1451617521 for a reproduction.
return { return {
f: url.toString(), flightData: url.toString(),
c: undefined, canonicalUrl: undefined,
i: false, couldBeIntercepted: false,
p: false, isPrerender: false,
} }
} }
} }
...@@ -353,7 +353,7 @@ export function listenForDynamicRequest( ...@@ -353,7 +353,7 @@ export function listenForDynamicRequest(
responsePromise: Promise<FetchServerResponseResult> responsePromise: Promise<FetchServerResponseResult>
) { ) {
responsePromise.then( responsePromise.then(
({ f: flightData }: FetchServerResponseResult) => { ({ flightData }: FetchServerResponseResult) => {
for (const flightDataPath of flightData) { for (const flightDataPath of flightData) {
const segmentPath = flightDataPath.slice(0, -3) const segmentPath = flightDataPath.slice(0, -3)
const serverRouterState = flightDataPath[flightDataPath.length - 3] const serverRouterState = flightDataPath[flightDataPath.length - 3]
......
...@@ -247,7 +247,7 @@ export function createPrefetchCacheEntryForInitialLoad({ ...@@ -247,7 +247,7 @@ export function createPrefetchCacheEntryForInitialLoad({
// prefetch cache so that we can skip an extra prefetch request later, since we already have the data. // prefetch cache so that we can skip an extra prefetch request later, since we already have the data.
const kind = PrefetchKind.AUTO const kind = PrefetchKind.AUTO
// if the prefetch corresponds with an interception route, we use the nextUrl to prefix the cache key // if the prefetch corresponds with an interception route, we use the nextUrl to prefix the cache key
const prefetchCacheKey = data.i const prefetchCacheKey = data.couldBeIntercepted
? createPrefetchCacheKey(url, kind, nextUrl) ? createPrefetchCacheKey(url, kind, nextUrl)
: createPrefetchCacheKey(url, kind) : createPrefetchCacheKey(url, kind)
...@@ -300,7 +300,7 @@ function createLazyPrefetchEntry({ ...@@ -300,7 +300,7 @@ function createLazyPrefetchEntry({
// (which is currently directly influenced by the server response) // (which is currently directly influenced by the server response)
let newCacheKey let newCacheKey
if (prefetchResponse.i) { if (prefetchResponse.couldBeIntercepted) {
// Determine if we need to prefix the cache key with the nextUrl // Determine if we need to prefix the cache key with the nextUrl
newCacheKey = prefixExistingPrefetchCacheEntry({ newCacheKey = prefixExistingPrefetchCacheEntry({
url, url,
...@@ -313,7 +313,7 @@ function createLazyPrefetchEntry({ ...@@ -313,7 +313,7 @@ function createLazyPrefetchEntry({
// If the prefetch was a cache hit, we want to update the existing cache entry to reflect that it was a full prefetch. // If the prefetch was a cache hit, we want to update the existing cache entry to reflect that it was a full prefetch.
// This is because we know that a static response will contain the full RSC payload, and can be updated to respect the `static` // This is because we know that a static response will contain the full RSC payload, and can be updated to respect the `static`
// staleTime. // staleTime.
if (prefetchResponse.p) { if (prefetchResponse.isPrerender) {
const existingCacheEntry = prefetchCache.get( const existingCacheEntry = prefetchCache.get(
// if we prefixed the cache key due to route interception, we want to use the new key. Otherwise we use the original key // if we prefixed the cache key due to route interception, we want to use the new key. Otherwise we use the original key
newCacheKey ?? prefetchCacheKey newCacheKey ?? prefetchCacheKey
......
...@@ -42,7 +42,7 @@ function hmrRefreshReducerImpl( ...@@ -42,7 +42,7 @@ function hmrRefreshReducerImpl(
}) })
return cache.lazyData.then( return cache.lazyData.then(
({ f: flightData, c: canonicalUrlOverride }) => { ({ flightData, canonicalUrl: canonicalUrlOverride }) => {
// Handle case when navigating to page in `pages` from `app` // Handle case when navigating to page in `pages` from `app`
if (typeof flightData === 'string') { if (typeof flightData === 'string') {
return handleExternalUrl( return handleExternalUrl(
......
...@@ -137,7 +137,7 @@ function navigateReducer_noPPR( ...@@ -137,7 +137,7 @@ function navigateReducer_noPPR(
prefetchQueue.bump(data) prefetchQueue.bump(data)
return data.then( return data.then(
({ f: flightData, c: canonicalUrlOverride }) => { ({ flightData, canonicalUrl: canonicalUrlOverride }) => {
let isFirstRead = false let isFirstRead = false
// we only want to mark this once // we only want to mark this once
if (!prefetchValues.lastUsedTime) { if (!prefetchValues.lastUsedTime) {
...@@ -353,7 +353,7 @@ function navigateReducer_PPR( ...@@ -353,7 +353,7 @@ function navigateReducer_PPR(
prefetchQueue.bump(data) prefetchQueue.bump(data)
return data.then( return data.then(
({ f: flightData, c: canonicalUrlOverride }) => { ({ flightData, canonicalUrl: canonicalUrlOverride }) => {
let isFirstRead = false let isFirstRead = false
// we only want to mark this once // we only want to mark this once
if (!prefetchValues.lastUsedTime) { if (!prefetchValues.lastUsedTime) {
...@@ -450,6 +450,7 @@ function navigateReducer_PPR( ...@@ -450,6 +450,7 @@ function navigateReducer_PPR(
head, head,
mutable.onlyHashChange mutable.onlyHashChange
) )
if (task !== null) { if (task !== null) {
// We've created a new Cache Node tree that contains a prefetched // We've created a new Cache Node tree that contains a prefetched
// version of the next page. This can be rendered instantly. // version of the next page. This can be rendered instantly.
...@@ -480,14 +481,17 @@ function navigateReducer_PPR( ...@@ -480,14 +481,17 @@ function navigateReducer_PPR(
// root multiple times per navigation, like if the server sends us // root multiple times per navigation, like if the server sends us
// a different response than we expected. For now, we revert back // a different response than we expected. For now, we revert back
// to the lazy fetching mechanism in that case.) // to the lazy fetching mechanism in that case.)
listenForDynamicRequest( const dynamicRequest = fetchServerResponse(url, {
task, flightRouterState: currentTree,
fetchServerResponse(url, { nextUrl: state.nextUrl,
flightRouterState: currentTree, buildId: state.buildId,
nextUrl: state.nextUrl, })
buildId: state.buildId,
}) listenForDynamicRequest(task, dynamicRequest)
) // We store the dynamic request on the `lazyData` property of the CacheNode
// because we're not going to await the dynamic request here. Since we're not blocking
// on the dynamic request, `layout-router` will
// task.node.lazyData = dynamicRequest
mutable.cache = newCache mutable.cache = newCache
} }
......
...@@ -49,7 +49,7 @@ export function refreshReducer( ...@@ -49,7 +49,7 @@ export function refreshReducer(
}) })
return cache.lazyData.then( return cache.lazyData.then(
async ({ f: flightData, c: canonicalUrlOverride }) => { async ({ flightData, canonicalUrl: canonicalUrlOverride }) => {
// Handle case when navigating to page in `pages` from `app` // Handle case when navigating to page in `pages` from `app`
if (typeof flightData === 'string') { if (typeof flightData === 'string') {
return handleExternalUrl( return handleExternalUrl(
......
...@@ -19,7 +19,7 @@ export function serverPatchReducer( ...@@ -19,7 +19,7 @@ export function serverPatchReducer(
action: ServerPatchAction action: ServerPatchAction
): ReducerState { ): ReducerState {
const { const {
serverResponse: { f: flightData, c: canonicalUrlOverride }, serverResponse: { flightData, canonicalUrl: canonicalUrlOverride },
} = action } = action
const mutable: Mutable = {} const mutable: Mutable = {}
......
...@@ -71,7 +71,7 @@ async function refreshInactiveParallelSegmentsImpl({ ...@@ -71,7 +71,7 @@ async function refreshInactiveParallelSegmentsImpl({
nextUrl: includeNextUrl ? state.nextUrl : null, nextUrl: includeNextUrl ? state.nextUrl : null,
buildId: state.buildId, buildId: state.buildId,
} }
).then(({ f: flightData }) => { ).then(({ flightData }) => {
if (typeof flightData !== 'string') { if (typeof flightData !== 'string') {
for (const flightDataPath of flightData) { for (const flightDataPath of flightData) {
// we only pass the new cache as this function is called after clearing the router cache // we only pass the new cache as this function is called after clearing the router cache
......
...@@ -237,14 +237,10 @@ export type ActionFlightResponse = { ...@@ -237,14 +237,10 @@ export type ActionFlightResponse = {
} }
export type FetchServerResponseResult = { export type FetchServerResponseResult = {
/** flightData */ flightData: FlightData
f: FlightData canonicalUrl: URL | undefined
/** canonicalUrl */ couldBeIntercepted: boolean
c: URL | undefined isPrerender: boolean
/** couldBeIntercepted */
i: boolean
/** isPrerender */
p: boolean
} }
export type RSCPayload = export type RSCPayload =
......
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