@rangojs/router 0.0.0-experimental.110 → 0.0.0-experimental.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/rango.js +41 -37
- package/dist/vite/index.js +144 -191
- package/package.json +17 -14
- package/skills/handler-use/SKILL.md +1 -1
- package/skills/rango/SKILL.md +20 -0
- package/src/browser/action-coordinator.ts +53 -36
- package/src/browser/event-controller.ts +42 -66
- package/src/browser/navigation-bridge.ts +4 -0
- package/src/browser/navigation-client.ts +12 -15
- package/src/browser/navigation-store.ts +7 -8
- package/src/browser/navigation-transaction.ts +7 -21
- package/src/browser/partial-update.ts +8 -16
- package/src/browser/react/NavigationProvider.tsx +29 -40
- package/src/browser/react/use-params.ts +3 -4
- package/src/browser/response-adapter.ts +25 -0
- package/src/browser/rsc-router.tsx +16 -2
- package/src/browser/server-action-bridge.ts +23 -30
- package/src/browser/types.ts +2 -0
- package/src/build/generate-manifest.ts +29 -31
- package/src/build/generate-route-types.ts +2 -0
- package/src/build/route-types/router-processing.ts +37 -9
- package/src/build/runtime-discovery.ts +9 -20
- package/src/decode-loader-results.ts +36 -0
- package/src/errors.ts +29 -0
- package/src/index.rsc.ts +1 -0
- package/src/index.ts +1 -0
- package/src/response-utils.ts +9 -0
- package/src/route-content-wrapper.tsx +6 -28
- package/src/route-definition/dsl-helpers.ts +231 -259
- package/src/route-definition/helper-factories.ts +29 -139
- package/src/route-definition/use-item-types.ts +32 -0
- package/src/route-types.ts +19 -41
- package/src/router/content-negotiation.ts +15 -2
- package/src/router/intercept-resolution.ts +4 -18
- package/src/router/match-result.ts +32 -30
- package/src/router/middleware.ts +46 -78
- package/src/router/preview-match.ts +3 -1
- package/src/router/request-classification.ts +4 -28
- package/src/rsc/handler.ts +20 -65
- package/src/rsc/helpers.ts +3 -2
- package/src/rsc/origin-guard.ts +28 -10
- package/src/rsc/response-route-handler.ts +32 -52
- package/src/rsc/rsc-rendering.ts +27 -53
- package/src/rsc/runtime-warnings.ts +9 -10
- package/src/rsc/server-action.ts +13 -37
- package/src/rsc/ssr-setup.ts +16 -0
- package/src/segment-system.tsx +5 -39
- package/src/server/context.ts +76 -35
- package/src/urls/include-helper.ts +10 -53
- package/src/urls/index.ts +0 -3
- package/src/urls/path-helper.ts +17 -52
- package/src/urls/pattern-types.ts +2 -19
- package/src/urls/response-types.ts +20 -19
- package/src/urls/type-extraction.ts +20 -115
- package/src/urls/urls-function.ts +1 -5
- package/src/vite/discovery/discover-routers.ts +10 -22
- package/src/vite/discovery/route-types-writer.ts +38 -82
- package/src/vite/plugins/cjs-to-esm.ts +3 -7
- package/src/vite/plugins/expose-ids/handler-transform.ts +8 -61
- package/src/vite/plugins/expose-ids/loader-transform.ts +3 -5
- package/src/vite/plugins/expose-internal-ids.ts +34 -62
- package/src/vite/plugins/version-injector.ts +2 -12
- package/src/vite/router-discovery.ts +71 -26
- package/src/vite/utils/shared-utils.ts +13 -1
- package/src/browser/action-response-classifier.ts +0 -99
|
@@ -11,122 +11,40 @@ import {
|
|
|
11
11
|
when,
|
|
12
12
|
errorBoundary,
|
|
13
13
|
notFoundBoundary,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
route,
|
|
15
|
+
loader,
|
|
16
|
+
loading,
|
|
17
|
+
transition,
|
|
18
18
|
} from "./dsl-helpers.js";
|
|
19
19
|
import RootLayout from "../server/root-layout";
|
|
20
20
|
import { invariant } from "../errors";
|
|
21
21
|
|
|
22
|
-
/*
|
|
23
|
-
* Create revalidate helper
|
|
24
|
-
*/
|
|
25
|
-
const createRevalidateHelper = <TEnv>(): RouteHelpers<
|
|
26
|
-
any,
|
|
27
|
-
TEnv
|
|
28
|
-
>["revalidate"] => {
|
|
29
|
-
return revalidate as RouteHelpers<any, TEnv>["revalidate"];
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Create errorBoundary helper
|
|
34
|
-
*/
|
|
35
|
-
const createErrorBoundaryHelper = <TEnv>(): RouteHelpers<
|
|
36
|
-
any,
|
|
37
|
-
TEnv
|
|
38
|
-
>["errorBoundary"] => {
|
|
39
|
-
return errorBoundary as RouteHelpers<any, TEnv>["errorBoundary"];
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Create notFoundBoundary helper
|
|
44
|
-
*/
|
|
45
|
-
const createNotFoundBoundaryHelper = <TEnv>(): RouteHelpers<
|
|
46
|
-
any,
|
|
47
|
-
TEnv
|
|
48
|
-
>["notFoundBoundary"] => {
|
|
49
|
-
return notFoundBoundary as RouteHelpers<any, TEnv>["notFoundBoundary"];
|
|
50
|
-
};
|
|
51
|
-
|
|
52
22
|
/**
|
|
53
|
-
*
|
|
23
|
+
* Assemble the RouteHelpers object. The helpers are the DSL functions
|
|
24
|
+
* themselves; the single cast erases the phantom generics (and the extra
|
|
25
|
+
* `route` key) that the per-router RouteHelpers<T, TEnv> type carries but the
|
|
26
|
+
* runtime functions do not.
|
|
54
27
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
28
|
+
function buildRouteHelpers<T extends RouteDefinition, TEnv>(): RouteHelpers<
|
|
29
|
+
T,
|
|
57
30
|
TEnv
|
|
58
|
-
>
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
>(): RouteHelpers<T, TEnv>["intercept"] => {
|
|
76
|
-
return intercept as RouteHelpers<T, TEnv>["intercept"];
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Create loader helper
|
|
81
|
-
*/
|
|
82
|
-
const createLoaderHelper = <TEnv>(): RouteHelpers<any, TEnv>["loader"] => {
|
|
83
|
-
return loaderFn as RouteHelpers<any, TEnv>["loader"];
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Create loading helper
|
|
88
|
-
*/
|
|
89
|
-
const createLoadingHelper = (): RouteHelpers<any, any>["loading"] => {
|
|
90
|
-
return loadingFn;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Create route helper
|
|
95
|
-
*/
|
|
96
|
-
const createRouteHelper = <
|
|
97
|
-
const T extends RouteDefinition,
|
|
98
|
-
TEnv,
|
|
99
|
-
>(): RouteHelpers<T, TEnv>["route"] => {
|
|
100
|
-
return routeFn as unknown as RouteHelpers<T, TEnv>["route"];
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Create layout helper
|
|
105
|
-
*/
|
|
106
|
-
const createLayoutHelper = <TEnv>(): RouteHelpers<any, TEnv>["layout"] => {
|
|
107
|
-
return layout as RouteHelpers<any, TEnv>["layout"];
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Create when helper for intercept conditions
|
|
112
|
-
*/
|
|
113
|
-
const createWhenHelper = (): RouteHelpers<any, any>["when"] => {
|
|
114
|
-
return when;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Create cache helper for cache configuration
|
|
119
|
-
*/
|
|
120
|
-
const createCacheHelper = (): RouteHelpers<any, any>["cache"] => {
|
|
121
|
-
return cache;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Create transition helper
|
|
126
|
-
*/
|
|
127
|
-
const createTransitionHelper = (): RouteHelpers<any, any>["transition"] => {
|
|
128
|
-
return transitionFn as RouteHelpers<any, any>["transition"];
|
|
129
|
-
};
|
|
31
|
+
> {
|
|
32
|
+
return {
|
|
33
|
+
route,
|
|
34
|
+
layout,
|
|
35
|
+
parallel,
|
|
36
|
+
intercept,
|
|
37
|
+
middleware,
|
|
38
|
+
revalidate,
|
|
39
|
+
loader,
|
|
40
|
+
loading,
|
|
41
|
+
errorBoundary,
|
|
42
|
+
notFoundBoundary,
|
|
43
|
+
when,
|
|
44
|
+
cache,
|
|
45
|
+
transition,
|
|
46
|
+
} as unknown as RouteHelpers<T, TEnv>;
|
|
47
|
+
}
|
|
130
48
|
|
|
131
49
|
/**
|
|
132
50
|
* Branded type for route handlers that carries the route type info.
|
|
@@ -152,21 +70,7 @@ export function map<const T extends RouteDefinition, TEnv = DefaultEnv>(
|
|
|
152
70
|
"map() expects a builder function as its argument",
|
|
153
71
|
);
|
|
154
72
|
// Create helpers
|
|
155
|
-
const helpers
|
|
156
|
-
route: createRouteHelper<T, TEnv>(),
|
|
157
|
-
layout: createLayoutHelper<TEnv>(),
|
|
158
|
-
parallel: createParallelHelper<TEnv>(),
|
|
159
|
-
intercept: createInterceptHelper<T, TEnv>(),
|
|
160
|
-
middleware: createMiddlewareHelper<TEnv>(),
|
|
161
|
-
revalidate: createRevalidateHelper<TEnv>(),
|
|
162
|
-
loader: createLoaderHelper<TEnv>(),
|
|
163
|
-
loading: createLoadingHelper(),
|
|
164
|
-
errorBoundary: createErrorBoundaryHelper<TEnv>(),
|
|
165
|
-
notFoundBoundary: createNotFoundBoundaryHelper<TEnv>(),
|
|
166
|
-
when: createWhenHelper(),
|
|
167
|
-
cache: createCacheHelper(),
|
|
168
|
-
transition: createTransitionHelper(),
|
|
169
|
-
};
|
|
73
|
+
const helpers = buildRouteHelpers<T, TEnv>();
|
|
170
74
|
|
|
171
75
|
return [layout(RootLayout, () => builder(helpers))].flat(3);
|
|
172
76
|
};
|
|
@@ -182,19 +86,5 @@ export function createRouteHelpers<
|
|
|
182
86
|
T extends RouteDefinition,
|
|
183
87
|
TEnv,
|
|
184
88
|
>(): RouteHelpers<T, TEnv> {
|
|
185
|
-
return
|
|
186
|
-
route: createRouteHelper<T, TEnv>(),
|
|
187
|
-
layout: createLayoutHelper<TEnv>(),
|
|
188
|
-
parallel: createParallelHelper<TEnv>(),
|
|
189
|
-
intercept: createInterceptHelper<T, TEnv>(),
|
|
190
|
-
middleware: createMiddlewareHelper<TEnv>(),
|
|
191
|
-
revalidate: createRevalidateHelper<TEnv>(),
|
|
192
|
-
loader: createLoaderHelper<TEnv>(),
|
|
193
|
-
loading: createLoadingHelper(),
|
|
194
|
-
errorBoundary: createErrorBoundaryHelper<TEnv>(),
|
|
195
|
-
notFoundBoundary: createNotFoundBoundaryHelper<TEnv>(),
|
|
196
|
-
when: createWhenHelper(),
|
|
197
|
-
cache: createCacheHelper(),
|
|
198
|
-
transition: createTransitionHelper(),
|
|
199
|
-
};
|
|
89
|
+
return buildRouteHelpers<T, TEnv>();
|
|
200
90
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AllUseItems, WhenItem } from "../route-types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The set of valid use-item `type` discriminants — the single runtime source of
|
|
5
|
+
* truth for "is this a well-formed use item?" shape validation.
|
|
6
|
+
*
|
|
7
|
+
* Declared via a `Record<...>` so that adding a member to the union without
|
|
8
|
+
* updating this map is a compile error. `when` is included because when() items
|
|
9
|
+
* are valid inside intercept() even though WhenItem is not part of AllUseItems
|
|
10
|
+
* (it lives only in InterceptUseItem). This is shape validation only; per-mount-
|
|
11
|
+
* site rules remain the narrower hand-written tables in resolve-handler-use.ts.
|
|
12
|
+
*/
|
|
13
|
+
const USE_ITEM_TYPES: Record<AllUseItems["type"] | WhenItem["type"], true> = {
|
|
14
|
+
layout: true,
|
|
15
|
+
route: true,
|
|
16
|
+
middleware: true,
|
|
17
|
+
revalidate: true,
|
|
18
|
+
parallel: true,
|
|
19
|
+
intercept: true,
|
|
20
|
+
loader: true,
|
|
21
|
+
loading: true,
|
|
22
|
+
errorBoundary: true,
|
|
23
|
+
notFoundBoundary: true,
|
|
24
|
+
when: true,
|
|
25
|
+
cache: true,
|
|
26
|
+
transition: true,
|
|
27
|
+
include: true,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const ALL_USE_ITEM_TYPES: ReadonlySet<string> = new Set(
|
|
31
|
+
Object.keys(USE_ITEM_TYPES),
|
|
32
|
+
);
|
package/src/route-types.ts
CHANGED
|
@@ -5,47 +5,43 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Brand for UrlPatterns nominal typing (see pattern-types.ts). The route-item
|
|
9
|
+
* types below are discriminated by their `type` literal, so they carry no brand.
|
|
9
10
|
*/
|
|
10
|
-
export declare const LayoutBrand: unique symbol;
|
|
11
|
-
export declare const RouteBrand: unique symbol;
|
|
12
|
-
export declare const ParallelBrand: unique symbol;
|
|
13
|
-
export declare const InterceptBrand: unique symbol;
|
|
14
|
-
export declare const MiddlewareBrand: unique symbol;
|
|
15
|
-
export declare const RevalidateBrand: unique symbol;
|
|
16
|
-
export declare const LoaderBrand: unique symbol;
|
|
17
|
-
export declare const LoadingBrand: unique symbol;
|
|
18
|
-
export declare const ErrorBoundaryBrand: unique symbol;
|
|
19
|
-
export declare const NotFoundBoundaryBrand: unique symbol;
|
|
20
|
-
export declare const WhenBrand: unique symbol;
|
|
21
|
-
export declare const CacheBrand: unique symbol;
|
|
22
|
-
export declare const TransitionBrand: unique symbol;
|
|
23
|
-
export declare const IncludeBrand: unique symbol;
|
|
24
11
|
export declare const UrlPatternsBrand: unique symbol;
|
|
25
12
|
|
|
26
13
|
export type LayoutItem = {
|
|
27
14
|
name: string;
|
|
28
15
|
type: "layout";
|
|
29
16
|
uses?: AllUseItems[];
|
|
30
|
-
[LayoutBrand]: void;
|
|
31
17
|
};
|
|
32
18
|
|
|
33
19
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
20
|
+
* Phantom inference fields attached to wrapper items (layout/cache/transition)
|
|
21
|
+
* so the urls() type extractor can read their child routes/responses. The fields
|
|
22
|
+
* never exist at runtime.
|
|
36
23
|
*/
|
|
37
|
-
|
|
24
|
+
type WithChildren<
|
|
25
|
+
TBase,
|
|
38
26
|
TChildRoutes extends Record<string, any> = Record<string, string>,
|
|
39
27
|
TChildResponses extends Record<string, unknown> = Record<string, unknown>,
|
|
40
|
-
> =
|
|
28
|
+
> = TBase & {
|
|
41
29
|
readonly __childRoutes?: TChildRoutes;
|
|
42
30
|
readonly __childResponses?: TChildResponses;
|
|
43
31
|
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Typed layout item that carries child routes as phantom type
|
|
35
|
+
* Used for type inference in urls() API
|
|
36
|
+
*/
|
|
37
|
+
export type TypedLayoutItem<
|
|
38
|
+
TChildRoutes extends Record<string, any> = Record<string, string>,
|
|
39
|
+
TChildResponses extends Record<string, unknown> = Record<string, unknown>,
|
|
40
|
+
> = WithChildren<LayoutItem, TChildRoutes, TChildResponses>;
|
|
44
41
|
export type RouteItem = {
|
|
45
42
|
name: string;
|
|
46
43
|
type: "route";
|
|
47
44
|
uses?: AllUseItems[];
|
|
48
|
-
[RouteBrand]: void;
|
|
49
45
|
};
|
|
50
46
|
|
|
51
47
|
/**
|
|
@@ -67,64 +63,53 @@ export type ParallelItem = {
|
|
|
67
63
|
name: string;
|
|
68
64
|
type: "parallel";
|
|
69
65
|
uses?: ParallelUseItem[];
|
|
70
|
-
[ParallelBrand]: void;
|
|
71
66
|
};
|
|
72
67
|
export type InterceptItem = {
|
|
73
68
|
name: string;
|
|
74
69
|
type: "intercept";
|
|
75
70
|
uses?: InterceptUseItem[];
|
|
76
|
-
[InterceptBrand]: void;
|
|
77
71
|
};
|
|
78
72
|
export type LoaderItem = {
|
|
79
73
|
name: string;
|
|
80
74
|
type: "loader";
|
|
81
75
|
uses?: LoaderUseItem[];
|
|
82
|
-
[LoaderBrand]: void;
|
|
83
76
|
};
|
|
84
77
|
export type MiddlewareItem = {
|
|
85
78
|
name: string;
|
|
86
79
|
type: "middleware";
|
|
87
80
|
uses?: AllUseItems[];
|
|
88
|
-
[MiddlewareBrand]: void;
|
|
89
81
|
};
|
|
90
82
|
export type RevalidateItem = {
|
|
91
83
|
name: string;
|
|
92
84
|
type: "revalidate";
|
|
93
85
|
uses?: AllUseItems[];
|
|
94
|
-
[RevalidateBrand]: void;
|
|
95
86
|
};
|
|
96
87
|
export type LoadingItem = {
|
|
97
88
|
name: string;
|
|
98
89
|
type: "loading";
|
|
99
|
-
[LoadingBrand]: void;
|
|
100
90
|
};
|
|
101
91
|
export type ErrorBoundaryItem = {
|
|
102
92
|
name: string;
|
|
103
93
|
type: "errorBoundary";
|
|
104
94
|
uses?: AllUseItems[];
|
|
105
|
-
[ErrorBoundaryBrand]: void;
|
|
106
95
|
};
|
|
107
96
|
export type NotFoundBoundaryItem = {
|
|
108
97
|
name: string;
|
|
109
98
|
type: "notFoundBoundary";
|
|
110
99
|
uses?: AllUseItems[];
|
|
111
|
-
[NotFoundBoundaryBrand]: void;
|
|
112
100
|
};
|
|
113
101
|
export type WhenItem = {
|
|
114
102
|
name: string;
|
|
115
103
|
type: "when";
|
|
116
|
-
[WhenBrand]: void;
|
|
117
104
|
};
|
|
118
105
|
export type CacheItem = {
|
|
119
106
|
name: string;
|
|
120
107
|
type: "cache";
|
|
121
108
|
uses?: AllUseItems[];
|
|
122
|
-
[CacheBrand]: void;
|
|
123
109
|
};
|
|
124
110
|
export type TransitionItem = {
|
|
125
111
|
name: string;
|
|
126
112
|
type: "transition";
|
|
127
|
-
[TransitionBrand]: void;
|
|
128
113
|
};
|
|
129
114
|
|
|
130
115
|
/**
|
|
@@ -134,10 +119,7 @@ export type TransitionItem = {
|
|
|
134
119
|
export type TypedTransitionItem<
|
|
135
120
|
TChildRoutes extends Record<string, any> = Record<string, string>,
|
|
136
121
|
TChildResponses extends Record<string, unknown> = Record<string, unknown>,
|
|
137
|
-
> = TransitionItem
|
|
138
|
-
readonly __childRoutes?: TChildRoutes;
|
|
139
|
-
readonly __childResponses?: TChildResponses;
|
|
140
|
-
};
|
|
122
|
+
> = WithChildren<TransitionItem, TChildRoutes, TChildResponses>;
|
|
141
123
|
|
|
142
124
|
/**
|
|
143
125
|
* Typed cache item that carries child routes as phantom type
|
|
@@ -146,10 +128,7 @@ export type TypedTransitionItem<
|
|
|
146
128
|
export type TypedCacheItem<
|
|
147
129
|
TChildRoutes extends Record<string, any> = Record<string, string>,
|
|
148
130
|
TChildResponses extends Record<string, unknown> = Record<string, unknown>,
|
|
149
|
-
> = CacheItem
|
|
150
|
-
readonly __childRoutes?: TChildRoutes;
|
|
151
|
-
readonly __childResponses?: TChildResponses;
|
|
152
|
-
};
|
|
131
|
+
> = WithChildren<CacheItem, TChildRoutes, TChildResponses>;
|
|
153
132
|
|
|
154
133
|
/**
|
|
155
134
|
* Include item for URL pattern composition (used by urls() API)
|
|
@@ -184,7 +163,6 @@ export type IncludeItem = {
|
|
|
184
163
|
*/
|
|
185
164
|
includeScope?: string;
|
|
186
165
|
};
|
|
187
|
-
[IncludeBrand]: void;
|
|
188
166
|
};
|
|
189
167
|
|
|
190
168
|
/**
|
|
@@ -135,8 +135,8 @@ export interface NegotiationResult {
|
|
|
135
135
|
manifestEntry: EntryData;
|
|
136
136
|
/** Route middleware for the winning variant */
|
|
137
137
|
routeMiddleware: CollectedMiddleware[];
|
|
138
|
-
/**
|
|
139
|
-
negotiated:
|
|
138
|
+
/** True when negotiation selected a variant; false for a plain response route. */
|
|
139
|
+
negotiated: boolean;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/**
|
|
@@ -155,6 +155,19 @@ export async function negotiateRoute(
|
|
|
155
155
|
): Promise<NegotiationResult | null> {
|
|
156
156
|
const { matched, manifestEntry, routeMiddleware, responseType } = snapshot;
|
|
157
157
|
if (!matched.negotiateVariants || matched.negotiateVariants.length === 0) {
|
|
158
|
+
// No variants: a plain response route still yields a result (negotiated:false)
|
|
159
|
+
// so callers don't re-derive it; RSC routes (no responseType/handler) -> null.
|
|
160
|
+
const handler =
|
|
161
|
+
manifestEntry.type === "route" ? manifestEntry.handler : undefined;
|
|
162
|
+
if (responseType && handler) {
|
|
163
|
+
return {
|
|
164
|
+
responseType,
|
|
165
|
+
handler: handler as Function,
|
|
166
|
+
manifestEntry,
|
|
167
|
+
routeMiddleware,
|
|
168
|
+
negotiated: false,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
158
171
|
return null;
|
|
159
172
|
}
|
|
160
173
|
|
|
@@ -66,28 +66,14 @@ export function findInterceptForRoute(
|
|
|
66
66
|
let current: EntryData | null = fromEntry;
|
|
67
67
|
|
|
68
68
|
while (current) {
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
// current first, then its sibling layouts — same order as before.
|
|
70
|
+
for (const source of [current, ...current.layout]) {
|
|
71
|
+
for (const intercept of source.intercept) {
|
|
71
72
|
if (
|
|
72
73
|
intercept.routeName === targetRouteKey &&
|
|
73
74
|
evaluateInterceptWhen(intercept, selectorContext, isAction)
|
|
74
75
|
) {
|
|
75
|
-
return { intercept, entry:
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (current.layout && current.layout.length > 0) {
|
|
81
|
-
for (const siblingLayout of current.layout) {
|
|
82
|
-
if (siblingLayout.intercept && siblingLayout.intercept.length > 0) {
|
|
83
|
-
for (const intercept of siblingLayout.intercept) {
|
|
84
|
-
if (
|
|
85
|
-
intercept.routeName === targetRouteKey &&
|
|
86
|
-
evaluateInterceptWhen(intercept, selectorContext, isAction)
|
|
87
|
-
) {
|
|
88
|
-
return { intercept, entry: siblingLayout };
|
|
89
|
-
}
|
|
90
|
-
}
|
|
76
|
+
return { intercept, entry: source };
|
|
91
77
|
}
|
|
92
78
|
}
|
|
93
79
|
}
|
|
@@ -138,34 +138,38 @@ export async function collectSegments(
|
|
|
138
138
|
function deduplicateLoaderSegments(
|
|
139
139
|
segments: ResolvedSegment[],
|
|
140
140
|
logPrefix: string,
|
|
141
|
-
): ResolvedSegment[] {
|
|
142
|
-
//
|
|
143
|
-
// and
|
|
141
|
+
): { segments: ResolvedSegment[]; removedIds: Set<string> } {
|
|
142
|
+
// Single pass: original (non-inherited) loaderIds, all loaderIds grouped by
|
|
143
|
+
// namespace, and namespaces of segments that declare loading().
|
|
144
144
|
const originalLoaders = new Set<string>();
|
|
145
|
-
const
|
|
145
|
+
const loaderIdsByNamespace = new Map<string, string[]>();
|
|
146
|
+
const namespacesWithLoading = new Set<string>();
|
|
146
147
|
for (const s of segments) {
|
|
147
|
-
if (s.type === "loader" && s.loaderId
|
|
148
|
-
originalLoaders.add(s.loaderId);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
148
|
+
if (s.type === "loader" && s.loaderId) {
|
|
149
|
+
if (!s._inherited) originalLoaders.add(s.loaderId);
|
|
150
|
+
const ids = loaderIdsByNamespace.get(s.namespace);
|
|
151
|
+
if (ids) ids.push(s.loaderId);
|
|
152
|
+
else loaderIdsByNamespace.set(s.namespace, [s.loaderId]);
|
|
153
|
+
} else if (
|
|
154
|
+
s.type !== "loader" &&
|
|
155
|
+
s.loading !== undefined &&
|
|
156
|
+
s.loading !== false
|
|
157
|
+
) {
|
|
158
|
+
namespacesWithLoading.add(s.namespace);
|
|
152
159
|
}
|
|
153
160
|
}
|
|
154
|
-
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
loadersWithLoading.add(l.loaderId);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
161
|
+
|
|
162
|
+
// An inherited loader is needed when it shares a namespace with a
|
|
163
|
+
// loading-bearing segment (its data sits behind that LoaderBoundary).
|
|
164
|
+
const loadersWithLoading = new Set<string>();
|
|
165
|
+
for (const ns of namespacesWithLoading) {
|
|
166
|
+
for (const id of loaderIdsByNamespace.get(ns) ?? []) {
|
|
167
|
+
loadersWithLoading.add(id);
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
170
|
|
|
167
171
|
const result: ResolvedSegment[] = [];
|
|
168
|
-
|
|
172
|
+
const removedIds = new Set<string>();
|
|
169
173
|
|
|
170
174
|
for (const s of segments) {
|
|
171
175
|
if (
|
|
@@ -175,17 +179,20 @@ function deduplicateLoaderSegments(
|
|
|
175
179
|
originalLoaders.has(s.loaderId) &&
|
|
176
180
|
!loadersWithLoading.has(s.loaderId)
|
|
177
181
|
) {
|
|
178
|
-
|
|
182
|
+
removedIds.add(s.id);
|
|
179
183
|
continue;
|
|
180
184
|
}
|
|
181
185
|
result.push(s);
|
|
182
186
|
}
|
|
183
187
|
|
|
184
|
-
if (
|
|
185
|
-
debugLog(
|
|
188
|
+
if (removedIds.size > 0) {
|
|
189
|
+
debugLog(
|
|
190
|
+
logPrefix,
|
|
191
|
+
`deduped ${removedIds.size} inherited loader segment(s)`,
|
|
192
|
+
);
|
|
186
193
|
}
|
|
187
194
|
|
|
188
|
-
return result;
|
|
195
|
+
return { segments: result, removedIds };
|
|
189
196
|
}
|
|
190
197
|
|
|
191
198
|
/**
|
|
@@ -244,7 +251,7 @@ export function buildMatchResult<TEnv>(
|
|
|
244
251
|
);
|
|
245
252
|
}
|
|
246
253
|
|
|
247
|
-
const dedupedSegments = deduplicateLoaderSegments(
|
|
254
|
+
const { segments: dedupedSegments, removedIds } = deduplicateLoaderSegments(
|
|
248
255
|
segmentsToRender,
|
|
249
256
|
logPrefix,
|
|
250
257
|
);
|
|
@@ -262,11 +269,6 @@ export function buildMatchResult<TEnv>(
|
|
|
262
269
|
|
|
263
270
|
// Remove deduped loader IDs from matched so the client doesn't treat
|
|
264
271
|
// them as missing segments and trigger a fallback refetch.
|
|
265
|
-
const removedIds = new Set(
|
|
266
|
-
segmentsToRender
|
|
267
|
-
.filter((s) => !dedupedSegments.includes(s))
|
|
268
|
-
.map((s) => s.id),
|
|
269
|
-
);
|
|
270
272
|
const matchedIds =
|
|
271
273
|
removedIds.size > 0 ? allIds.filter((id) => !removedIds.has(id)) : allIds;
|
|
272
274
|
|