Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable isNavigatingToNewRootLayout #41457

Merged
merged 2 commits into from Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 1 addition & 73 deletions packages/next/server/app-render.tsx
Expand Up @@ -7,7 +7,7 @@ import type { FontLoaderManifest } from '../build/webpack/plugins/font-loader-ma
// @ts-ignore
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 { NextParsedUrlQuery } from './request-meta'
import RenderResult from './render-result'
Expand Down Expand Up @@ -668,56 +668,6 @@ async function renderToString(element: React.ReactElement) {
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(
req: IncomingMessage,
res: ServerResponse,
Expand Down Expand Up @@ -810,28 +760,6 @@ export async function renderToHTMLOrFlight(
*/
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)

const LayoutRouter =
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/root-layout.test.ts
Expand Up @@ -4,7 +4,7 @@ import { NextInstance } from 'test/lib/next-modes/base'
import webdriver from 'next-webdriver'
import { getRedboxSource, hasRedbox } from 'next-test-utils'

describe('app-dir root layout', () => {
describe.skip('app-dir root layout', () => {
const isDev = (global as any).isNextDev

if ((global as any).isNextDeploy) {
Expand Down