Skip to content

Commit

Permalink
Disable isNavigatingToNewRootLayout (vercel#41457)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
timneutkens authored and Kikobeats committed Oct 24, 2022
1 parent c255e10 commit 8488357
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 74 deletions.
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

0 comments on commit 8488357

Please sign in to comment.