Unverified Commit 0b907c71 authored by Wyatt Johnson's avatar Wyatt Johnson Committed by GitHub

[ppr] Don't mark RSC requests as /_next/data requests (backport of #66249) (#70083)

This is a backport of #66249 for 14.2.11.

---------
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent bfbc92aa
......@@ -1364,7 +1364,7 @@ export async function buildAppStaticPaths({
renderOpts: {
originalPathname: page,
incrementalCache,
supportsDynamicHTML: true,
supportsDynamicResponse: true,
isRevalidate: false,
// building static paths should never postpone
experimental: { ppr: false },
......
......@@ -89,7 +89,7 @@ export function getRender({
extendRenderOpts: {
buildId,
runtime: SERVER_RUNTIME.experimentalEdge,
supportsDynamicHTML: true,
supportsDynamicResponse: true,
disableOptimizedLoading: true,
serverActionsManifest,
serverActions,
......
......@@ -399,7 +399,7 @@ export async function exportAppImpl(
domainLocales: i18n?.domains,
disableOptimizedLoading: nextConfig.experimental.disableOptimizedLoading,
// Exported pages do not currently support dynamic HTML.
supportsDynamicHTML: false,
supportsDynamicResponse: false,
crossOrigin: nextConfig.crossOrigin,
optimizeCss: nextConfig.experimental.optimizeCss,
nextConfigOutput: nextConfig.output,
......
......@@ -67,7 +67,7 @@ export async function exportAppRoute(
experimental: { ppr: false },
originalPathname: page,
nextExport: true,
supportsDynamicHTML: false,
supportsDynamicResponse: false,
incrementalCache,
},
}
......
......@@ -269,7 +269,7 @@ async function exportPageImpl(
disableOptimizedLoading,
fontManifest: optimizeFonts ? requireFontManifest(distDir) : undefined,
locale,
supportsDynamicHTML: false,
supportsDynamicResponse: false,
originalPathname: page,
}
......
......@@ -621,7 +621,7 @@ async function renderToHTMLOrFlightImpl(
ComponentMod,
dev,
nextFontManifest,
supportsDynamicHTML,
supportsDynamicResponse,
serverActions,
appDirDevErrorLogger,
assetPrefix = '',
......@@ -730,7 +730,7 @@ async function renderToHTMLOrFlightImpl(
* These rules help ensure that other existing features like request caching,
* coalescing, and ISR continue working as intended.
*/
const generateStaticHTML = supportsDynamicHTML !== true
const generateStaticHTML = supportsDynamicResponse !== true
// Pull out the hooks/references from the component.
const { tree: loaderTree, taintObjectReference } = ComponentMod
......
......@@ -128,7 +128,7 @@ export interface RenderOptsPartial {
basePath: string
trailingSlash: boolean
clientReferenceManifest?: DeepReadonly<ClientReferenceManifest>
supportsDynamicHTML: boolean
supportsDynamicResponse: boolean
runtime?: ServerRuntime
serverComponents?: boolean
enableTainting?: boolean
......
......@@ -37,7 +37,7 @@ export type StaticGenerationContext = {
// mirrored.
RenderOptsPartial,
| 'originalPathname'
| 'supportsDynamicHTML'
| 'supportsDynamicResponse'
| 'isRevalidate'
| 'nextExport'
| 'isDraftMode'
......@@ -72,7 +72,7 @@ export const StaticGenerationAsyncStorageWrapper: AsyncStorageWrapper<
* coalescing, and ISR continue working as intended.
*/
const isStaticGeneration =
!renderOpts.supportsDynamicHTML &&
!renderOpts.supportsDynamicResponse &&
!renderOpts.isDraftMode &&
!renderOpts.isServerAction
......
This diff is collapsed.
......@@ -1868,7 +1868,7 @@ export default class NextNodeServer extends BaseServer {
}
// For edge to "fetch" we must always provide an absolute URL
const isDataReq = !!query.__nextDataReq
const isNextDataRequest = !!query.__nextDataReq
const initialUrl = new URL(
getRequestMeta(params.req, 'initURL') || '/',
'http://n'
......@@ -1879,7 +1879,7 @@ export default class NextNodeServer extends BaseServer {
...params.params,
}).toString()
if (isDataReq) {
if (isNextDataRequest) {
params.req.headers['x-nextjs-data'] = '1'
}
initialUrl.search = queryString
......
......@@ -249,7 +249,7 @@ export type RenderOptsPartial = {
ampValidator?: (html: string, pathname: string) => Promise<void>
ampSkipValidation?: boolean
ampOptimizerConfig?: { [key: string]: any }
isDataReq?: boolean
isNextDataRequest?: boolean
params?: ParsedUrlQuery
previewProps: __ApiPreviewProps | undefined
basePath: string
......@@ -271,7 +271,7 @@ export type RenderOptsPartial = {
defaultLocale?: string
domainLocales?: DomainLocale[]
disableOptimizedLoading?: boolean
supportsDynamicHTML: boolean
supportsDynamicResponse: boolean
isBot?: boolean
runtime?: ServerRuntime
serverComponents?: boolean
......@@ -452,7 +452,7 @@ export async function renderToHTMLImpl(
getStaticProps,
getStaticPaths,
getServerSideProps,
isDataReq,
isNextDataRequest,
params,
previewProps,
basePath,
......@@ -1184,7 +1184,7 @@ export async function renderToHTMLImpl(
// Avoid rendering page un-necessarily for getServerSideProps data request
// and getServerSideProps/getStaticProps redirects
if ((isDataReq && !isSSG) || metadata.isRedirect) {
if ((isNextDataRequest && !isSSG) || metadata.isRedirect) {
return new RenderResult(JSON.stringify(props), {
metadata,
})
......
......@@ -224,6 +224,11 @@ type NextQueryMetadata = {
__nextSsgPath?: string
_nextBubbleNoFallback?: '1'
/**
* When set to `1`, the request is for the `/_next/data` route using the pages
* router.
*/
__nextDataReq?: '1'
__nextCustomErrorRender?: '1'
[NEXT_RSC_UNION_QUERY]?: string
......
......@@ -122,9 +122,9 @@ export async function adapter(
const buildId = requestUrl.buildId
requestUrl.buildId = ''
const isDataReq = params.request.headers['x-nextjs-data']
const isNextDataRequest = params.request.headers['x-nextjs-data']
if (isDataReq && requestUrl.pathname === '/index') {
if (isNextDataRequest && requestUrl.pathname === '/index') {
requestUrl.pathname = '/'
}
......@@ -166,7 +166,7 @@ export async function adapter(
* need to know about this property neither use it. We add it for testing
* purposes.
*/
if (isDataReq) {
if (isNextDataRequest) {
Object.defineProperty(request, '__isData', {
enumerable: false,
value: true,
......@@ -278,7 +278,7 @@ export async function adapter(
)
if (
isDataReq &&
isNextDataRequest &&
// if the rewrite is external and external rewrite
// resolving config is enabled don't add this header
// so the upstream app can set it instead
......@@ -322,7 +322,7 @@ export async function adapter(
* it may end up with CORS error. Instead we map to an internal header so
* the client knows the destination.
*/
if (isDataReq) {
if (isNextDataRequest) {
response.headers.delete('Location')
response.headers.set(
'x-nextjs-redirect',
......
......@@ -96,7 +96,7 @@ export class EdgeRouteModuleWrapper {
notFoundRoutes: [],
},
renderOpts: {
supportsDynamicHTML: true,
supportsDynamicResponse: true,
// App Route's cannot be postponed.
experimental: { ppr: false },
},
......
import { TestPage } from '../../../components/page'
export default function Page({ params: { locale } }) {
return <TestPage pathname={`/${locale}/about`} />
}
import { locales } from '../../components/page'
export async function generateStaticParams() {
return locales.map((locale) => ({ locale }))
}
export default function Layout({ children, params: { locale } }) {
return (
<html lang={locale}>
<body>{children}</body>
</html>
)
}
import { TestPage } from '../../components/page'
export default function Page({ params: { locale } }) {
return <TestPage pathname={`/${locale}`} />
}
export default ({ children }) => {
return children
}
import { redirect } from 'next/navigation'
import { locales } from '../components/page'
export default () => {
// Redirect to the default locale
return redirect(`/${locales[0]}`)
}
import { unstable_noStore } from 'next/cache'
import Link from 'next/link'
import { Suspense } from 'react'
export const locales = ['en', 'fr']
export const links = [
{ href: '/', text: 'Home' },
...locales
.map((locale) => {
return [
{ href: `/${locale}`, text: locale },
{ href: `/${locale}/about`, text: `${locale} - About` },
]
})
.flat(),
]
function Dynamic() {
unstable_noStore()
return <div id="dynamic">Dynamic</div>
}
export function TestPage({ pathname }) {
return (
<div>
<ul>
{links.map(({ href, text }) => (
<li key={href}>
<Link href={href}>{text}</Link>
</li>
))}
</ul>
<code data-value={pathname}>{pathname}</code>
<Suspense fallback={<div>Loading...</div>}>
<Dynamic />
</Suspense>
</div>
)
}
module.exports = {
experimental: {
ppr: true,
},
}
import { nextTestSetup } from 'e2e-utils'
import { links, locales } from './components/page'
describe('ppr-navigations simple', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('can navigate between all the links and back', async () => {
const browser = await next.browser('/')
try {
for (const { href } of links) {
// Find the link element for the href and click it.
await browser.elementByCss(`a[href="${href}"]`).click()
// Wait for that page to load.
if (href === '/') {
// The root page redirects to the first locale.
await browser.waitForElementByCss(`[data-value="/${locales[0]}"]`)
} else {
await browser.waitForElementByCss(`[data-value="${href}"]`)
}
await browser.elementByCss('#dynamic')
}
} finally {
await browser.close()
}
})
})
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