Unverified Commit 1d37afb3 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Disable isNavigatingToNewRootLayout (#41457)

Hannes is going to change the approach to be compatible with static.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent bc3d8be4
...@@ -7,7 +7,7 @@ import type { FontLoaderManifest } from '../build/webpack/plugins/font-loader-ma ...@@ -7,7 +7,7 @@ import type { FontLoaderManifest } from '../build/webpack/plugins/font-loader-ma
// @ts-ignore // @ts-ignore
import React, { experimental_use as use } from 'react' import React, { experimental_use as use } from 'react'
import { ParsedUrlQuery, stringify as stringifyQuery } from 'querystring' import { ParsedUrlQuery } from 'querystring'
import { createFromReadableStream } from 'next/dist/compiled/react-server-dom-webpack' import { createFromReadableStream } from 'next/dist/compiled/react-server-dom-webpack'
import { NextParsedUrlQuery } from './request-meta' import { NextParsedUrlQuery } from './request-meta'
import RenderResult from './render-result' import RenderResult from './render-result'
...@@ -668,56 +668,6 @@ async function renderToString(element: React.ReactElement) { ...@@ -668,56 +668,6 @@ async function renderToString(element: React.ReactElement) {
return streamToString(renderStream) return streamToString(renderStream)
} }
function getRootLayoutPath(
[segment, parallelRoutes, { layout }]: LoaderTree,
rootLayoutPath = ''
): string | undefined {
rootLayoutPath += `${segment}/`
const isLayout = typeof layout !== 'undefined'
if (isLayout) return rootLayoutPath
// We can't assume it's `parallelRoutes.children` here in case the root layout is `app/@something/layout.js`
// But it's not possible to be more than one parallelRoutes before the root layout is found
const child = Object.values(parallelRoutes)[0]
if (!child) return
return getRootLayoutPath(child, rootLayoutPath)
}
function findRootLayoutInFlightRouterState(
[segment, parallelRoutes]: FlightRouterState,
rootLayoutSegments: string,
segments = ''
): boolean {
segments += `${segment}/`
if (segments === rootLayoutSegments) {
return true
} else if (segments.length > rootLayoutSegments.length) {
return false
}
// We can't assume it's `parallelRoutes.children` here in case the root layout is `app/@something/layout.js`
// But it's not possible to be more than one parallelRoutes before the root layout is found
const child = Object.values(parallelRoutes)[0]
if (!child) return false
return findRootLayoutInFlightRouterState(child, rootLayoutSegments, segments)
}
function isNavigatingToNewRootLayout(
loaderTree: LoaderTree,
flightRouterState: FlightRouterState
): boolean {
const newRootLayout = getRootLayoutPath(loaderTree)
// should always have a root layout
if (newRootLayout) {
const hasSameRootLayout = findRootLayoutInFlightRouterState(
flightRouterState,
newRootLayout
)
return !hasSameRootLayout
}
return false
}
export async function renderToHTMLOrFlight( export async function renderToHTMLOrFlight(
req: IncomingMessage, req: IncomingMessage,
res: ServerResponse, res: ServerResponse,
...@@ -810,28 +760,6 @@ export async function renderToHTMLOrFlight( ...@@ -810,28 +760,6 @@ export async function renderToHTMLOrFlight(
*/ */
const loaderTree: LoaderTree = ComponentMod.tree const loaderTree: LoaderTree = ComponentMod.tree
// If navigating to a new root layout we need to do a full page navigation.
if (
isFlight &&
Array.isArray(providedFlightRouterState) &&
isNavigatingToNewRootLayout(loaderTree, providedFlightRouterState)
) {
stripInternalQueries(query)
const search = stringifyQuery(query)
// Empty so that the client-side router will do a full page navigation.
const flightData: FlightData = req.url! + (search ? `?${search}` : '')
return new FlightRenderResult(
ComponentMod.renderToReadableStream(
flightData,
serverComponentManifest,
{
onError: flightDataRendererErrorHandler,
}
).pipeThrough(createBufferedTransformStream())
)
}
stripInternalQueries(query) stripInternalQueries(query)
const LayoutRouter = const LayoutRouter =
......
...@@ -4,7 +4,7 @@ import { NextInstance } from 'test/lib/next-modes/base' ...@@ -4,7 +4,7 @@ import { NextInstance } from 'test/lib/next-modes/base'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { getRedboxSource, hasRedbox } from 'next-test-utils' import { getRedboxSource, hasRedbox } from 'next-test-utils'
describe('app-dir root layout', () => { describe.skip('app-dir root layout', () => {
const isDev = (global as any).isNextDev const isDev = (global as any).isNextDev
if ((global as any).isNextDeploy) { if ((global as any).isNextDeploy) {
......
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