Unverified Commit 9b312dbb authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Ensure route group with separate root layout does not get wrapped in <div> (#38792)

Ensures the `<html>` is not wrapped in an extra div when the root layout is nested in a route group.


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have 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 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.md#adding-examples)
parent bae0482b
...@@ -56,6 +56,7 @@ export function InnerLayoutRouter({ ...@@ -56,6 +56,7 @@ export function InnerLayoutRouter({
tree, tree,
// isActive, // isActive,
path, path,
rootLayoutIncluded,
}: { }: {
parallelRouterKey: string parallelRouterKey: string
url: string url: string
...@@ -65,6 +66,7 @@ export function InnerLayoutRouter({ ...@@ -65,6 +66,7 @@ export function InnerLayoutRouter({
tree: FlightRouterState tree: FlightRouterState
isActive: boolean isActive: boolean
path: string path: string
rootLayoutIncluded: boolean
}) { }) {
const { const {
changeByServerResponse, changeByServerResponse,
...@@ -216,19 +218,24 @@ export function InnerLayoutRouter({ ...@@ -216,19 +218,24 @@ export function InnerLayoutRouter({
throw createInfinitePromise() throw createInfinitePromise()
} }
return ( const subtree = (
<div ref={focusAndScrollRef}> <AppTreeContext.Provider
<AppTreeContext.Provider value={{
value={{ tree: tree[1][parallelRouterKey],
tree: tree[1][parallelRouterKey], childNodes: childNode.parallelRoutes,
childNodes: childNode.parallelRoutes, // TODO-APP: overriding of url for parallel routes
// TODO-APP: overriding of url for parallel routes url: url,
url: url, }}
}} >
> {childNode.subTreeData}
{childNode.subTreeData} </AppTreeContext.Provider>
</AppTreeContext.Provider> )
</div>
// Ensure root layout is not wrapped in a div
return rootLayoutIncluded ? (
<div ref={focusAndScrollRef}>{subtree}</div>
) : (
subtree
) )
} }
...@@ -251,11 +258,13 @@ export default function OuterLayoutRouter({ ...@@ -251,11 +258,13 @@ export default function OuterLayoutRouter({
segmentPath, segmentPath,
childProp, childProp,
loading, loading,
rootLayoutIncluded,
}: { }: {
parallelRouterKey: string parallelRouterKey: string
segmentPath: FlightSegmentPath segmentPath: FlightSegmentPath
childProp: ChildProp childProp: ChildProp
loading: React.ReactNode | undefined loading: React.ReactNode | undefined
rootLayoutIncluded: boolean
}) { }) {
const { childNodes, tree, url } = useContext(AppTreeContext) const { childNodes, tree, url } = useContext(AppTreeContext)
...@@ -297,6 +306,7 @@ export default function OuterLayoutRouter({ ...@@ -297,6 +306,7 @@ export default function OuterLayoutRouter({
segmentPath={segmentPath} segmentPath={segmentPath}
path={preservedSegment} path={preservedSegment}
isActive={currentChildSegment === preservedSegment} isActive={currentChildSegment === preservedSegment}
rootLayoutIncluded={rootLayoutIncluded}
/> />
</LoadingBoundary> </LoadingBoundary>
) )
......
...@@ -543,15 +543,21 @@ export async function renderToHTML( ...@@ -543,15 +543,21 @@ export async function renderToHTML(
tree: [segment, parallelRoutes, { layout, loading, page }], tree: [segment, parallelRoutes, { layout, loading, page }],
parentParams, parentParams,
firstItem, firstItem,
rootLayoutIncluded,
}: { }: {
createSegmentPath: CreateSegmentPath createSegmentPath: CreateSegmentPath
tree: LoaderTree tree: LoaderTree
parentParams: { [key: string]: any } parentParams: { [key: string]: any }
rootLayoutIncluded?: boolean
firstItem?: boolean firstItem?: boolean
}): { Component: React.ComponentType } => { }): { Component: React.ComponentType } => {
const Loading = loading ? interopDefault(loading()) : undefined const Loading = loading ? interopDefault(loading()) : undefined
const layoutOrPageMod = layout ? layout() : page ? page() : undefined const isLayout = typeof layout !== 'undefined'
const isPage = typeof page !== undefined const isPage = typeof page !== 'undefined'
const layoutOrPageMod = isLayout ? layout() : isPage ? page() : undefined
const rootLayoutAtThisLevel = isLayout && !rootLayoutIncluded
const rootLayoutIncludedAtThisLevelOrAbove =
rootLayoutIncluded || rootLayoutAtThisLevel
const isClientComponentModule = const isClientComponentModule =
layoutOrPageMod && !layoutOrPageMod.hasOwnProperty('__next_rsc__') layoutOrPageMod && !layoutOrPageMod.hasOwnProperty('__next_rsc__')
...@@ -600,6 +606,7 @@ export async function renderToHTML( ...@@ -600,6 +606,7 @@ export async function renderToHTML(
}, },
tree: parallelRoutes[currentValue], tree: parallelRoutes[currentValue],
parentParams: currentParams, parentParams: currentParams,
rootLayoutIncluded: rootLayoutIncludedAtThisLevelOrAbove,
}) })
const childSegmentParam = getDynamicParamFromSegment( const childSegmentParam = getDynamicParamFromSegment(
...@@ -622,6 +629,7 @@ export async function renderToHTML( ...@@ -622,6 +629,7 @@ export async function renderToHTML(
segmentPath={createSegmentPath(currentSegmentPath)} segmentPath={createSegmentPath(currentSegmentPath)}
loading={Loading ? <Loading /> : undefined} loading={Loading ? <Loading /> : undefined}
childProp={childProp} childProp={childProp}
rootLayoutIncluded={rootLayoutIncludedAtThisLevelOrAbove}
/> />
) )
......
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