-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parallel routes: fix client reference manifest grouping for catch-all…
… segments (#60482) ### What? When using catch-all routes in conjunction with parallel routes, and when importing a client component (`"use client"`), the build would fail with the following error: > Could not find the module "PathToClientComponent" in the React Client Manifest. This is probably a bug in the React Server Components bundler. ### Why? `flight-manifest-plugin` generates manifests for each page entry. The `clientModules` portion of this manifest is used by React to load the appropriate client module. When React attempts to render a component tree and detects a module that it cannot find, it will throw this error. To illustrate why it isn't in the tree, consider the following example: ``` app page.tsx layout.tsx @slot [...catchAll] page.tsx ``` ```tsx // app/layout.tsx export default function Layout({children, slot}) { return <>{children} {slot}</> } ``` ```tsx // app/@slot/[...catchAll]/page.tsx import Link from 'next/link' export default function Page() { return <Link href="/">Test</Link> } ``` When visiting `/`, we'd expect both the catch-all `@slot` and the root page to render. At build time, we'll generate a client reference manifest for `/` and `/[...catchAll]` since both are page components. However, the `@slot` imports a client component. When we attempt to load the client reference manifest for `/`, it will ignore the catch-all slot's manifest, resulting in the error. ### How? The `entryNameToGroupName` function seems to already exist to handle this scenario for other cases. For example, `app/(group)/@named/foo/page` needs to know about any manifests associated with `app/foo`. This updates the code to apply similar handling to catchAll segments. When applying this change to the example mentioned earlier, it will properly merge the manifests for both `app/@slot/[...catchAll]/page.tsx` and `app/page.tsx` because both will be part of the `/` group. Closes NEXT-1908 Fixes #59747 Fixes #59510
- Loading branch information
Showing
7 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...parallel-routes-and-interception/app/parallel-catchall/[...catchAll]/client-component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use client' | ||
|
||
export function ClientComponent() { | ||
return <div>catchall page client component</div> | ||
} |
8 changes: 7 additions & 1 deletion
8
...e2e/app-dir/parallel-routes-and-interception/app/parallel-catchall/[...catchAll]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
import { ClientComponent } from './client-component' | ||
|
||
export default function Page() { | ||
return 'main catchall' | ||
return ( | ||
<div> | ||
main catchall <ClientComponent /> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
test/e2e/app-dir/parallel-routes-catchall/app/@slot/[...catchAll]/client-component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use client' | ||
|
||
export function ClientComponent() { | ||
return <div>catchall slot client component</div> | ||
} |
8 changes: 7 additions & 1 deletion
8
test/e2e/app-dir/parallel-routes-catchall/app/@slot/[...catchAll]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
import { ClientComponent } from './client-component' | ||
|
||
export default function Page() { | ||
return 'slot catchall' | ||
return ( | ||
<div> | ||
slot catchall <ClientComponent /> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters