Skip to content

Commit b6d4433

Browse files
authored
loader tree: add special segment name to virtual parallel route segments (#82383)
When constructing the loader tree for parallel route segments, we inject a `children` segment, which could contain things like slot level layout/error/loading files. We want a way to distinguish between these virtual segments that exist just for organizational purposes rather than relying on `children`. This updates the loader tree construction code to give these more unique names. In the future, we should see if we can remove the need for this virtual segment if there are no special files needed at that segment of the tree.
1 parent 08e5b06 commit b6d4433

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

crates/next-core/src/app_structure.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ async fn directory_tree_to_loader_tree_internal(
10541054
let current_level_is_parallel_route = is_parallel_route(&directory_name);
10551055

10561056
if current_level_is_parallel_route {
1057-
tree.segment = rcstr!("children");
1057+
tree.segment = rcstr!("__virtual_segment__");
10581058
}
10591059

10601060
if let Some(page) = (app_path == for_app_path || app_path.is_catchall())
@@ -1075,10 +1075,6 @@ async fn directory_tree_to_loader_tree_internal(
10751075
global_metadata: global_metadata.to_resolved().await?,
10761076
},
10771077
);
1078-
1079-
if current_level_is_parallel_route {
1080-
tree.segment = rcstr!("page$");
1081-
}
10821078
}
10831079

10841080
let mut duplicate = FxHashMap::default();

packages/next/src/build/webpack/loaders/next-app-loader/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const FILE_TYPES = {
7777
const GLOBAL_ERROR_FILE_TYPE = 'global-error'
7878
const GLOBAL_NOT_FOUND_FILE_TYPE = 'global-not-found'
7979
const PAGE_SEGMENT = 'page$'
80-
const PARALLEL_CHILDREN_SEGMENT = 'children$'
80+
const PARALLEL_VIRTUAL_SEGMENT = 'slot$'
8181

8282
const defaultGlobalErrorPath =
8383
'next/dist/client/components/builtin/global-error.js'
@@ -275,7 +275,7 @@ async function createTreeCodeFromPath(
275275

276276
if (
277277
normalizedParallelSegment !== PAGE_SEGMENT &&
278-
normalizedParallelSegment !== PARALLEL_CHILDREN_SEGMENT
278+
normalizedParallelSegment !== PARALLEL_VIRTUAL_SEGMENT
279279
) {
280280
// If we don't have a page segment, nor a special $children marker, it means we need to traverse the next directory
281281
// (ie, `normalizedParallelSegment` would correspond with the folder that contains the next level of pages/layout/etc)
@@ -396,8 +396,8 @@ async function createTreeCodeFromPath(
396396
// earlier logic (such as children$ and page$). These should never appear in the loader tree, and
397397
// should instead be the corresponding segment keys (ie `__PAGE__`) or the `children` parallel route.
398398
parallelSegmentKey =
399-
parallelSegmentKey === PARALLEL_CHILDREN_SEGMENT
400-
? 'children'
399+
parallelSegmentKey === PARALLEL_VIRTUAL_SEGMENT
400+
? '__virtual_segment__'
401401
: parallelSegmentKey === PAGE_SEGMENT
402402
? PAGE_SEGMENT_KEY
403403
: parallelSegmentKey
@@ -624,7 +624,7 @@ const nextAppLoader: AppLoader = async function nextAppLoader() {
624624
// If it was a parallel route but we weren't able to find the page segment (ie, maybe the page is nested further)
625625
// we first insert a special marker to ensure that we still process layout/default/etc at the slot level prior to continuing
626626
// on to the page segment.
627-
matched[rest[0]] = [PARALLEL_CHILDREN_SEGMENT, ...rest.slice(1)]
627+
matched[rest[0]] = [PARALLEL_VIRTUAL_SEGMENT, ...rest.slice(1)]
628628
continue
629629
}
630630

0 commit comments

Comments
 (0)