react-router 0.0.0-experimental-c19b79d → 0.0.0-experimental-e0b6ce9
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/development/{chunk-AGOH44BE.mjs → chunk-4FI4BC6Y.mjs} +67 -51
- package/dist/development/{chunk-IMKEG5CI.mjs → chunk-F6CT5MEB.mjs} +314 -30
- package/dist/development/{chunk-LUB73E44.js → chunk-INO4IHBF.js} +352 -71
- package/dist/development/{chunk-2G2U5HGB.js → chunk-ITZFCV4J.js} +164 -161
- package/dist/development/dom-export.d.mts +59 -4
- package/dist/development/dom-export.d.ts +59 -3
- package/dist/development/dom-export.js +8 -5
- package/dist/development/dom-export.mjs +8 -5
- package/dist/development/{index-react-server-client-DKvU8YRr.d.ts → index-react-server-client-CYIi6gi0.d.mts} +198 -134
- package/dist/{production/index-react-server-client-DKvU8YRr.d.ts → development/index-react-server-client-ChBGplLn.d.ts} +198 -134
- package/dist/development/index-react-server-client.d.mts +3 -3
- package/dist/development/index-react-server-client.d.ts +3 -2
- package/dist/development/index-react-server-client.js +4 -4
- package/dist/development/index-react-server-client.mjs +2 -2
- package/dist/development/index-react-server.d.mts +90 -1
- package/dist/development/index-react-server.d.ts +90 -1
- package/dist/development/index-react-server.js +188 -9
- package/dist/development/index-react-server.mjs +188 -9
- package/dist/development/index.d.mts +13 -20
- package/dist/development/index.d.ts +13 -18
- package/dist/development/index.js +161 -147
- package/dist/development/index.mjs +3 -5
- package/dist/development/instrumentation-BGrNA7uj.d.ts +1122 -0
- package/dist/development/lib/types/internal.d.mts +3 -3
- package/dist/development/lib/types/internal.d.ts +3 -2
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/lib/types/internal.mjs +1 -1
- package/dist/development/{register-BrVEYTED.d.mts → register-DiOIlEq5.d.mts} +1 -7
- package/dist/{production/register-BrVEYTED.d.mts → development/register-DiOIlEq5.d.ts} +1 -7
- package/dist/development/{route-data-CDwqkzPE.d.mts → routeModules-Cy4Xsfoi.d.mts} +157 -147
- package/dist/{production/routeModules-BmVo7q9e.d.ts → development/routeModules-DqotkItD.d.ts} +73 -1046
- package/dist/{production/context-BqL5Eckq.d.mts → development/router-DWv6Clt-.d.mts} +1390 -1253
- package/dist/production/{chunk-AODJW4D3.mjs → chunk-52MYED7O.mjs} +67 -51
- package/dist/production/{chunk-FGRCWJDI.js → chunk-DASXXYNZ.js} +164 -161
- package/dist/production/{chunk-2L5AG5Y5.js → chunk-K7VXYOZD.js} +352 -71
- package/dist/production/{chunk-UOQCOPF6.mjs → chunk-LKSLGWXX.mjs} +314 -30
- package/dist/production/dom-export.d.mts +59 -4
- package/dist/production/dom-export.d.ts +59 -3
- package/dist/production/dom-export.js +8 -5
- package/dist/production/dom-export.mjs +8 -5
- package/dist/production/{index-react-server-client-2EDmGlsZ.d.mts → index-react-server-client-CYIi6gi0.d.mts} +140 -77
- package/dist/{development/index-react-server-client-2EDmGlsZ.d.mts → production/index-react-server-client-ChBGplLn.d.ts} +140 -77
- package/dist/production/index-react-server-client.d.mts +3 -3
- package/dist/production/index-react-server-client.d.ts +3 -2
- package/dist/production/index-react-server-client.js +4 -4
- package/dist/production/index-react-server-client.mjs +2 -2
- package/dist/production/index-react-server.d.mts +90 -1
- package/dist/production/index-react-server.d.ts +90 -1
- package/dist/production/index-react-server.js +188 -9
- package/dist/production/index-react-server.mjs +188 -9
- package/dist/production/index.d.mts +13 -20
- package/dist/production/index.d.ts +13 -18
- package/dist/production/index.js +161 -147
- package/dist/production/index.mjs +3 -5
- package/dist/production/instrumentation-BGrNA7uj.d.ts +1122 -0
- package/dist/production/lib/types/internal.d.mts +3 -3
- package/dist/production/lib/types/internal.d.ts +3 -2
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/lib/types/internal.mjs +1 -1
- package/dist/{development/register-D8NQoPsO.d.ts → production/register-DiOIlEq5.d.mts} +1 -7
- package/dist/production/{register-D8NQoPsO.d.ts → register-DiOIlEq5.d.ts} +1 -7
- package/dist/production/{route-data-CDwqkzPE.d.mts → routeModules-Cy4Xsfoi.d.mts} +157 -147
- package/dist/{development/routeModules-BmVo7q9e.d.ts → production/routeModules-DqotkItD.d.ts} +73 -1046
- package/dist/{development/context-BqL5Eckq.d.mts → production/router-DWv6Clt-.d.mts} +1390 -1253
- package/package.json +1 -1
|
@@ -27,7 +27,7 @@ function _interopNamespace(e) {
|
|
|
27
27
|
var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* react-router v0.0.0-experimental-
|
|
30
|
+
* react-router v0.0.0-experimental-e0b6ce9
|
|
31
31
|
*
|
|
32
32
|
* Copyright (c) Remix Software Inc.
|
|
33
33
|
*
|
|
@@ -107,6 +107,139 @@ function parsePath(path) {
|
|
|
107
107
|
return parsedPath;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
// lib/router/instrumentation.ts
|
|
111
|
+
var UninstrumentedSymbol = Symbol("Uninstrumented");
|
|
112
|
+
function getRouteInstrumentationUpdates(fns, route) {
|
|
113
|
+
let aggregated = {
|
|
114
|
+
lazy: [],
|
|
115
|
+
"lazy.loader": [],
|
|
116
|
+
"lazy.action": [],
|
|
117
|
+
"lazy.middleware": [],
|
|
118
|
+
middleware: [],
|
|
119
|
+
loader: [],
|
|
120
|
+
action: []
|
|
121
|
+
};
|
|
122
|
+
fns.forEach(
|
|
123
|
+
(fn) => fn({
|
|
124
|
+
id: route.id,
|
|
125
|
+
index: route.index,
|
|
126
|
+
path: route.path,
|
|
127
|
+
instrument(i) {
|
|
128
|
+
let keys = Object.keys(aggregated);
|
|
129
|
+
for (let key of keys) {
|
|
130
|
+
if (i[key]) {
|
|
131
|
+
aggregated[key].push(i[key]);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
let updates = {};
|
|
138
|
+
if (typeof route.lazy === "function" && aggregated.lazy.length > 0) {
|
|
139
|
+
let instrumented = wrapImpl(aggregated.lazy, route.lazy, () => void 0);
|
|
140
|
+
if (instrumented) {
|
|
141
|
+
updates.lazy = instrumented;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (typeof route.lazy === "object") {
|
|
145
|
+
let lazyObject = route.lazy;
|
|
146
|
+
["middleware", "loader", "action"].forEach((key) => {
|
|
147
|
+
let lazyFn = lazyObject[key];
|
|
148
|
+
let instrumentations = aggregated[`lazy.${key}`];
|
|
149
|
+
if (typeof lazyFn === "function" && instrumentations.length > 0) {
|
|
150
|
+
let instrumented = wrapImpl(instrumentations, lazyFn, () => void 0);
|
|
151
|
+
if (instrumented) {
|
|
152
|
+
updates.lazy = Object.assign(updates.lazy || {}, {
|
|
153
|
+
[key]: instrumented
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
["loader", "action"].forEach((key) => {
|
|
160
|
+
let handler = route[key];
|
|
161
|
+
if (typeof handler === "function" && aggregated[key].length > 0) {
|
|
162
|
+
let original = handler[UninstrumentedSymbol] ?? handler;
|
|
163
|
+
let instrumented = wrapImpl(
|
|
164
|
+
aggregated[key],
|
|
165
|
+
original,
|
|
166
|
+
(...args) => getHandlerInfo(args[0])
|
|
167
|
+
);
|
|
168
|
+
if (instrumented) {
|
|
169
|
+
instrumented[UninstrumentedSymbol] = original;
|
|
170
|
+
updates[key] = instrumented;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
if (route.middleware && route.middleware.length > 0 && aggregated.middleware.length > 0) {
|
|
175
|
+
updates.middleware = route.middleware.map((middleware) => {
|
|
176
|
+
let original = middleware[UninstrumentedSymbol] ?? middleware;
|
|
177
|
+
let instrumented = wrapImpl(
|
|
178
|
+
aggregated.middleware,
|
|
179
|
+
original,
|
|
180
|
+
(...args) => getHandlerInfo(args[0])
|
|
181
|
+
);
|
|
182
|
+
if (instrumented) {
|
|
183
|
+
instrumented[UninstrumentedSymbol] = original;
|
|
184
|
+
return instrumented;
|
|
185
|
+
}
|
|
186
|
+
return middleware;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return updates;
|
|
190
|
+
}
|
|
191
|
+
function wrapImpl(impls, handler, getInfo) {
|
|
192
|
+
if (impls.length === 0) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
return async (...args) => {
|
|
196
|
+
let value;
|
|
197
|
+
let info = getInfo(...args);
|
|
198
|
+
await recurseRight(
|
|
199
|
+
impls,
|
|
200
|
+
info,
|
|
201
|
+
async () => {
|
|
202
|
+
value = await handler(...args);
|
|
203
|
+
},
|
|
204
|
+
impls.length - 1
|
|
205
|
+
);
|
|
206
|
+
return value;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
async function recurseRight(impls, info, handler, index) {
|
|
210
|
+
let impl = impls[index];
|
|
211
|
+
if (!impl) {
|
|
212
|
+
await handler();
|
|
213
|
+
} else {
|
|
214
|
+
await impl(async () => {
|
|
215
|
+
await recurseRight(impls, info, handler, index - 1);
|
|
216
|
+
}, info);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function getHandlerInfo(args) {
|
|
220
|
+
let { request, context, params, unstable_pattern } = args;
|
|
221
|
+
return {
|
|
222
|
+
request: getReadonlyRequest(request),
|
|
223
|
+
params: { ...params },
|
|
224
|
+
unstable_pattern,
|
|
225
|
+
context: getReadonlyContext(context)
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function getReadonlyRequest(request) {
|
|
229
|
+
return {
|
|
230
|
+
method: request.method,
|
|
231
|
+
url: request.url,
|
|
232
|
+
headers: {
|
|
233
|
+
get: (...args) => request.headers.get(...args)
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function getReadonlyContext(context) {
|
|
238
|
+
return {
|
|
239
|
+
get: (ctx) => context.get(ctx)
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
110
243
|
// lib/router/utils.ts
|
|
111
244
|
function createContext(defaultValue) {
|
|
112
245
|
return { defaultValue };
|
|
@@ -200,19 +333,23 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath = [],
|
|
|
200
333
|
if (isIndexRoute(route)) {
|
|
201
334
|
let indexRoute = {
|
|
202
335
|
...route,
|
|
203
|
-
...mapRouteProperties(route),
|
|
204
336
|
id
|
|
205
337
|
};
|
|
206
|
-
manifest[id] =
|
|
338
|
+
manifest[id] = mergeRouteUpdates(
|
|
339
|
+
indexRoute,
|
|
340
|
+
mapRouteProperties(indexRoute)
|
|
341
|
+
);
|
|
207
342
|
return indexRoute;
|
|
208
343
|
} else {
|
|
209
344
|
let pathOrLayoutRoute = {
|
|
210
345
|
...route,
|
|
211
|
-
...mapRouteProperties(route),
|
|
212
346
|
id,
|
|
213
347
|
children: void 0
|
|
214
348
|
};
|
|
215
|
-
manifest[id] =
|
|
349
|
+
manifest[id] = mergeRouteUpdates(
|
|
350
|
+
pathOrLayoutRoute,
|
|
351
|
+
mapRouteProperties(pathOrLayoutRoute)
|
|
352
|
+
);
|
|
216
353
|
if (route.children) {
|
|
217
354
|
pathOrLayoutRoute.children = convertRoutesToDataRoutes(
|
|
218
355
|
route.children,
|
|
@@ -226,6 +363,17 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath = [],
|
|
|
226
363
|
}
|
|
227
364
|
});
|
|
228
365
|
}
|
|
366
|
+
function mergeRouteUpdates(route, updates) {
|
|
367
|
+
return Object.assign(route, {
|
|
368
|
+
...updates,
|
|
369
|
+
...typeof updates.lazy === "object" && updates.lazy != null ? {
|
|
370
|
+
lazy: {
|
|
371
|
+
...route.lazy,
|
|
372
|
+
...updates.lazy
|
|
373
|
+
}
|
|
374
|
+
} : {}
|
|
375
|
+
});
|
|
376
|
+
}
|
|
229
377
|
function matchRoutes(routes, locationArg, basename = "/") {
|
|
230
378
|
return matchRoutesImpl(routes, locationArg, basename, false);
|
|
231
379
|
}
|
|
@@ -652,6 +800,9 @@ var ErrorResponseImpl = class {
|
|
|
652
800
|
function isRouteErrorResponse(error) {
|
|
653
801
|
return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
|
|
654
802
|
}
|
|
803
|
+
function getRoutePattern(paths) {
|
|
804
|
+
return paths.filter(Boolean).join("/").replace(/\/\/*/g, "/");
|
|
805
|
+
}
|
|
655
806
|
|
|
656
807
|
// lib/router/router.ts
|
|
657
808
|
var validMutationMethodsArr = [
|
|
@@ -682,7 +833,20 @@ function createStaticHandler(routes, opts) {
|
|
|
682
833
|
);
|
|
683
834
|
let manifest = {};
|
|
684
835
|
let basename = (opts ? opts.basename : null) || "/";
|
|
685
|
-
let
|
|
836
|
+
let _mapRouteProperties = opts?.mapRouteProperties || defaultMapRouteProperties;
|
|
837
|
+
let mapRouteProperties = _mapRouteProperties;
|
|
838
|
+
if (opts?.unstable_instrumentations) {
|
|
839
|
+
let instrumentations = opts.unstable_instrumentations;
|
|
840
|
+
mapRouteProperties = (route) => {
|
|
841
|
+
return {
|
|
842
|
+
..._mapRouteProperties(route),
|
|
843
|
+
...getRouteInstrumentationUpdates(
|
|
844
|
+
instrumentations.map((i) => i.route).filter(Boolean),
|
|
845
|
+
route
|
|
846
|
+
)
|
|
847
|
+
};
|
|
848
|
+
};
|
|
849
|
+
}
|
|
686
850
|
let dataRoutes = convertRoutesToDataRoutes(
|
|
687
851
|
routes,
|
|
688
852
|
mapRouteProperties,
|
|
@@ -752,6 +916,7 @@ function createStaticHandler(routes, opts) {
|
|
|
752
916
|
let response = await runServerMiddlewarePipeline(
|
|
753
917
|
{
|
|
754
918
|
request,
|
|
919
|
+
unstable_pattern: getRoutePattern(matches.map((m) => m.route.path)),
|
|
755
920
|
matches,
|
|
756
921
|
params: matches[0].params,
|
|
757
922
|
// If we're calling middleware then it must be enabled so we can cast
|
|
@@ -897,6 +1062,7 @@ function createStaticHandler(routes, opts) {
|
|
|
897
1062
|
let response = await runServerMiddlewarePipeline(
|
|
898
1063
|
{
|
|
899
1064
|
request,
|
|
1065
|
+
unstable_pattern: getRoutePattern(matches.map((m) => m.route.path)),
|
|
900
1066
|
matches,
|
|
901
1067
|
params: matches[0].params,
|
|
902
1068
|
// If we're calling middleware then it must be enabled so we can cast
|
|
@@ -1172,12 +1338,14 @@ function createStaticHandler(routes, opts) {
|
|
|
1172
1338
|
// Up to but not including the boundary
|
|
1173
1339
|
matches.findIndex((m) => m.route.id === pendingActionResult[0]) - 1
|
|
1174
1340
|
) : void 0;
|
|
1341
|
+
let pattern = getRoutePattern(matches.map((m) => m.route.path));
|
|
1175
1342
|
dsMatches = matches.map((match, index) => {
|
|
1176
1343
|
if (maxIdx != null && index > maxIdx) {
|
|
1177
1344
|
return getDataStrategyMatch(
|
|
1178
1345
|
mapRouteProperties,
|
|
1179
1346
|
manifest,
|
|
1180
1347
|
request,
|
|
1348
|
+
pattern,
|
|
1181
1349
|
match,
|
|
1182
1350
|
[],
|
|
1183
1351
|
requestContext,
|
|
@@ -1188,6 +1356,7 @@ function createStaticHandler(routes, opts) {
|
|
|
1188
1356
|
mapRouteProperties,
|
|
1189
1357
|
manifest,
|
|
1190
1358
|
request,
|
|
1359
|
+
pattern,
|
|
1191
1360
|
match,
|
|
1192
1361
|
[],
|
|
1193
1362
|
requestContext,
|
|
@@ -1526,12 +1695,17 @@ function runServerMiddlewarePipeline(args, handler, errorHandler) {
|
|
|
1526
1695
|
}
|
|
1527
1696
|
}
|
|
1528
1697
|
async function runMiddlewarePipeline(args, handler, processResult, isResult, errorHandler) {
|
|
1529
|
-
let { matches, request, params, context } = args;
|
|
1698
|
+
let { matches, request, params, context, unstable_pattern } = args;
|
|
1530
1699
|
let tuples = matches.flatMap(
|
|
1531
1700
|
(m) => m.route.middleware ? m.route.middleware.map((fn) => [m.route.id, fn]) : []
|
|
1532
1701
|
);
|
|
1533
1702
|
let result = await callRouteMiddleware(
|
|
1534
|
-
{
|
|
1703
|
+
{
|
|
1704
|
+
request,
|
|
1705
|
+
params,
|
|
1706
|
+
context,
|
|
1707
|
+
unstable_pattern
|
|
1708
|
+
},
|
|
1535
1709
|
tuples,
|
|
1536
1710
|
handler,
|
|
1537
1711
|
processResult,
|
|
@@ -1609,7 +1783,7 @@ function getDataStrategyMatchLazyPromises(mapRouteProperties, manifest, request,
|
|
|
1609
1783
|
handler: lazyRoutePromises.lazyHandlerPromise
|
|
1610
1784
|
};
|
|
1611
1785
|
}
|
|
1612
|
-
function getDataStrategyMatch(mapRouteProperties, manifest, request, match, lazyRoutePropertiesToSkip, scopedContext, shouldLoad, unstable_shouldRevalidateArgs = null) {
|
|
1786
|
+
function getDataStrategyMatch(mapRouteProperties, manifest, request, unstable_pattern, match, lazyRoutePropertiesToSkip, scopedContext, shouldLoad, unstable_shouldRevalidateArgs = null) {
|
|
1613
1787
|
let isUsingNewApi = false;
|
|
1614
1788
|
let _lazyPromises = getDataStrategyMatchLazyPromises(
|
|
1615
1789
|
mapRouteProperties,
|
|
@@ -1643,6 +1817,7 @@ function getDataStrategyMatch(mapRouteProperties, manifest, request, match, lazy
|
|
|
1643
1817
|
if (callHandler && !isMiddlewareOnlyRoute) {
|
|
1644
1818
|
return callLoaderOrAction({
|
|
1645
1819
|
request,
|
|
1820
|
+
unstable_pattern,
|
|
1646
1821
|
match,
|
|
1647
1822
|
lazyHandlerPromise: _lazyPromises?.handler,
|
|
1648
1823
|
lazyRoutePromise: _lazyPromises?.route,
|
|
@@ -1676,6 +1851,7 @@ function getTargetedDataStrategyMatches(mapRouteProperties, manifest, request, m
|
|
|
1676
1851
|
mapRouteProperties,
|
|
1677
1852
|
manifest,
|
|
1678
1853
|
request,
|
|
1854
|
+
getRoutePattern(matches.map((m) => m.route.path)),
|
|
1679
1855
|
match,
|
|
1680
1856
|
lazyRoutePropertiesToSkip,
|
|
1681
1857
|
scopedContext,
|
|
@@ -1690,6 +1866,7 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
|
|
|
1690
1866
|
}
|
|
1691
1867
|
let dataStrategyArgs = {
|
|
1692
1868
|
request,
|
|
1869
|
+
unstable_pattern: getRoutePattern(matches.map((m) => m.route.path)),
|
|
1693
1870
|
params: matches[0].params,
|
|
1694
1871
|
context: scopedContext,
|
|
1695
1872
|
matches
|
|
@@ -1717,6 +1894,7 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
|
|
|
1717
1894
|
}
|
|
1718
1895
|
async function callLoaderOrAction({
|
|
1719
1896
|
request,
|
|
1897
|
+
unstable_pattern,
|
|
1720
1898
|
match,
|
|
1721
1899
|
lazyHandlerPromise,
|
|
1722
1900
|
lazyRoutePromise,
|
|
@@ -1743,6 +1921,7 @@ async function callLoaderOrAction({
|
|
|
1743
1921
|
return handler(
|
|
1744
1922
|
{
|
|
1745
1923
|
request,
|
|
1924
|
+
unstable_pattern,
|
|
1746
1925
|
params: match.params,
|
|
1747
1926
|
context: scopedContext
|
|
1748
1927
|
},
|
|
@@ -6,7 +6,7 @@ export { BrowserRouter, Form, HashRouter, Link, Links, MemoryRouter, Meta, NavLi
|
|
|
6
6
|
import { serialize, parse } from 'cookie';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* react-router v0.0.0-experimental-
|
|
9
|
+
* react-router v0.0.0-experimental-e0b6ce9
|
|
10
10
|
*
|
|
11
11
|
* Copyright (c) Remix Software Inc.
|
|
12
12
|
*
|
|
@@ -86,6 +86,139 @@ function parsePath(path) {
|
|
|
86
86
|
return parsedPath;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
// lib/router/instrumentation.ts
|
|
90
|
+
var UninstrumentedSymbol = Symbol("Uninstrumented");
|
|
91
|
+
function getRouteInstrumentationUpdates(fns, route) {
|
|
92
|
+
let aggregated = {
|
|
93
|
+
lazy: [],
|
|
94
|
+
"lazy.loader": [],
|
|
95
|
+
"lazy.action": [],
|
|
96
|
+
"lazy.middleware": [],
|
|
97
|
+
middleware: [],
|
|
98
|
+
loader: [],
|
|
99
|
+
action: []
|
|
100
|
+
};
|
|
101
|
+
fns.forEach(
|
|
102
|
+
(fn) => fn({
|
|
103
|
+
id: route.id,
|
|
104
|
+
index: route.index,
|
|
105
|
+
path: route.path,
|
|
106
|
+
instrument(i) {
|
|
107
|
+
let keys = Object.keys(aggregated);
|
|
108
|
+
for (let key of keys) {
|
|
109
|
+
if (i[key]) {
|
|
110
|
+
aggregated[key].push(i[key]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
let updates = {};
|
|
117
|
+
if (typeof route.lazy === "function" && aggregated.lazy.length > 0) {
|
|
118
|
+
let instrumented = wrapImpl(aggregated.lazy, route.lazy, () => void 0);
|
|
119
|
+
if (instrumented) {
|
|
120
|
+
updates.lazy = instrumented;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (typeof route.lazy === "object") {
|
|
124
|
+
let lazyObject = route.lazy;
|
|
125
|
+
["middleware", "loader", "action"].forEach((key) => {
|
|
126
|
+
let lazyFn = lazyObject[key];
|
|
127
|
+
let instrumentations = aggregated[`lazy.${key}`];
|
|
128
|
+
if (typeof lazyFn === "function" && instrumentations.length > 0) {
|
|
129
|
+
let instrumented = wrapImpl(instrumentations, lazyFn, () => void 0);
|
|
130
|
+
if (instrumented) {
|
|
131
|
+
updates.lazy = Object.assign(updates.lazy || {}, {
|
|
132
|
+
[key]: instrumented
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
["loader", "action"].forEach((key) => {
|
|
139
|
+
let handler = route[key];
|
|
140
|
+
if (typeof handler === "function" && aggregated[key].length > 0) {
|
|
141
|
+
let original = handler[UninstrumentedSymbol] ?? handler;
|
|
142
|
+
let instrumented = wrapImpl(
|
|
143
|
+
aggregated[key],
|
|
144
|
+
original,
|
|
145
|
+
(...args) => getHandlerInfo(args[0])
|
|
146
|
+
);
|
|
147
|
+
if (instrumented) {
|
|
148
|
+
instrumented[UninstrumentedSymbol] = original;
|
|
149
|
+
updates[key] = instrumented;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (route.middleware && route.middleware.length > 0 && aggregated.middleware.length > 0) {
|
|
154
|
+
updates.middleware = route.middleware.map((middleware) => {
|
|
155
|
+
let original = middleware[UninstrumentedSymbol] ?? middleware;
|
|
156
|
+
let instrumented = wrapImpl(
|
|
157
|
+
aggregated.middleware,
|
|
158
|
+
original,
|
|
159
|
+
(...args) => getHandlerInfo(args[0])
|
|
160
|
+
);
|
|
161
|
+
if (instrumented) {
|
|
162
|
+
instrumented[UninstrumentedSymbol] = original;
|
|
163
|
+
return instrumented;
|
|
164
|
+
}
|
|
165
|
+
return middleware;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return updates;
|
|
169
|
+
}
|
|
170
|
+
function wrapImpl(impls, handler, getInfo) {
|
|
171
|
+
if (impls.length === 0) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
return async (...args) => {
|
|
175
|
+
let value;
|
|
176
|
+
let info = getInfo(...args);
|
|
177
|
+
await recurseRight(
|
|
178
|
+
impls,
|
|
179
|
+
info,
|
|
180
|
+
async () => {
|
|
181
|
+
value = await handler(...args);
|
|
182
|
+
},
|
|
183
|
+
impls.length - 1
|
|
184
|
+
);
|
|
185
|
+
return value;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
async function recurseRight(impls, info, handler, index) {
|
|
189
|
+
let impl = impls[index];
|
|
190
|
+
if (!impl) {
|
|
191
|
+
await handler();
|
|
192
|
+
} else {
|
|
193
|
+
await impl(async () => {
|
|
194
|
+
await recurseRight(impls, info, handler, index - 1);
|
|
195
|
+
}, info);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function getHandlerInfo(args) {
|
|
199
|
+
let { request, context, params, unstable_pattern } = args;
|
|
200
|
+
return {
|
|
201
|
+
request: getReadonlyRequest(request),
|
|
202
|
+
params: { ...params },
|
|
203
|
+
unstable_pattern,
|
|
204
|
+
context: getReadonlyContext(context)
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function getReadonlyRequest(request) {
|
|
208
|
+
return {
|
|
209
|
+
method: request.method,
|
|
210
|
+
url: request.url,
|
|
211
|
+
headers: {
|
|
212
|
+
get: (...args) => request.headers.get(...args)
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function getReadonlyContext(context) {
|
|
217
|
+
return {
|
|
218
|
+
get: (ctx) => context.get(ctx)
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
89
222
|
// lib/router/utils.ts
|
|
90
223
|
function createContext(defaultValue) {
|
|
91
224
|
return { defaultValue };
|
|
@@ -179,19 +312,23 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath = [],
|
|
|
179
312
|
if (isIndexRoute(route)) {
|
|
180
313
|
let indexRoute = {
|
|
181
314
|
...route,
|
|
182
|
-
...mapRouteProperties(route),
|
|
183
315
|
id
|
|
184
316
|
};
|
|
185
|
-
manifest[id] =
|
|
317
|
+
manifest[id] = mergeRouteUpdates(
|
|
318
|
+
indexRoute,
|
|
319
|
+
mapRouteProperties(indexRoute)
|
|
320
|
+
);
|
|
186
321
|
return indexRoute;
|
|
187
322
|
} else {
|
|
188
323
|
let pathOrLayoutRoute = {
|
|
189
324
|
...route,
|
|
190
|
-
...mapRouteProperties(route),
|
|
191
325
|
id,
|
|
192
326
|
children: void 0
|
|
193
327
|
};
|
|
194
|
-
manifest[id] =
|
|
328
|
+
manifest[id] = mergeRouteUpdates(
|
|
329
|
+
pathOrLayoutRoute,
|
|
330
|
+
mapRouteProperties(pathOrLayoutRoute)
|
|
331
|
+
);
|
|
195
332
|
if (route.children) {
|
|
196
333
|
pathOrLayoutRoute.children = convertRoutesToDataRoutes(
|
|
197
334
|
route.children,
|
|
@@ -205,6 +342,17 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath = [],
|
|
|
205
342
|
}
|
|
206
343
|
});
|
|
207
344
|
}
|
|
345
|
+
function mergeRouteUpdates(route, updates) {
|
|
346
|
+
return Object.assign(route, {
|
|
347
|
+
...updates,
|
|
348
|
+
...typeof updates.lazy === "object" && updates.lazy != null ? {
|
|
349
|
+
lazy: {
|
|
350
|
+
...route.lazy,
|
|
351
|
+
...updates.lazy
|
|
352
|
+
}
|
|
353
|
+
} : {}
|
|
354
|
+
});
|
|
355
|
+
}
|
|
208
356
|
function matchRoutes(routes, locationArg, basename = "/") {
|
|
209
357
|
return matchRoutesImpl(routes, locationArg, basename, false);
|
|
210
358
|
}
|
|
@@ -631,6 +779,9 @@ var ErrorResponseImpl = class {
|
|
|
631
779
|
function isRouteErrorResponse(error) {
|
|
632
780
|
return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
|
|
633
781
|
}
|
|
782
|
+
function getRoutePattern(paths) {
|
|
783
|
+
return paths.filter(Boolean).join("/").replace(/\/\/*/g, "/");
|
|
784
|
+
}
|
|
634
785
|
|
|
635
786
|
// lib/router/router.ts
|
|
636
787
|
var validMutationMethodsArr = [
|
|
@@ -661,7 +812,20 @@ function createStaticHandler(routes, opts) {
|
|
|
661
812
|
);
|
|
662
813
|
let manifest = {};
|
|
663
814
|
let basename = (opts ? opts.basename : null) || "/";
|
|
664
|
-
let
|
|
815
|
+
let _mapRouteProperties = opts?.mapRouteProperties || defaultMapRouteProperties;
|
|
816
|
+
let mapRouteProperties = _mapRouteProperties;
|
|
817
|
+
if (opts?.unstable_instrumentations) {
|
|
818
|
+
let instrumentations = opts.unstable_instrumentations;
|
|
819
|
+
mapRouteProperties = (route) => {
|
|
820
|
+
return {
|
|
821
|
+
..._mapRouteProperties(route),
|
|
822
|
+
...getRouteInstrumentationUpdates(
|
|
823
|
+
instrumentations.map((i) => i.route).filter(Boolean),
|
|
824
|
+
route
|
|
825
|
+
)
|
|
826
|
+
};
|
|
827
|
+
};
|
|
828
|
+
}
|
|
665
829
|
let dataRoutes = convertRoutesToDataRoutes(
|
|
666
830
|
routes,
|
|
667
831
|
mapRouteProperties,
|
|
@@ -731,6 +895,7 @@ function createStaticHandler(routes, opts) {
|
|
|
731
895
|
let response = await runServerMiddlewarePipeline(
|
|
732
896
|
{
|
|
733
897
|
request,
|
|
898
|
+
unstable_pattern: getRoutePattern(matches.map((m) => m.route.path)),
|
|
734
899
|
matches,
|
|
735
900
|
params: matches[0].params,
|
|
736
901
|
// If we're calling middleware then it must be enabled so we can cast
|
|
@@ -876,6 +1041,7 @@ function createStaticHandler(routes, opts) {
|
|
|
876
1041
|
let response = await runServerMiddlewarePipeline(
|
|
877
1042
|
{
|
|
878
1043
|
request,
|
|
1044
|
+
unstable_pattern: getRoutePattern(matches.map((m) => m.route.path)),
|
|
879
1045
|
matches,
|
|
880
1046
|
params: matches[0].params,
|
|
881
1047
|
// If we're calling middleware then it must be enabled so we can cast
|
|
@@ -1151,12 +1317,14 @@ function createStaticHandler(routes, opts) {
|
|
|
1151
1317
|
// Up to but not including the boundary
|
|
1152
1318
|
matches.findIndex((m) => m.route.id === pendingActionResult[0]) - 1
|
|
1153
1319
|
) : void 0;
|
|
1320
|
+
let pattern = getRoutePattern(matches.map((m) => m.route.path));
|
|
1154
1321
|
dsMatches = matches.map((match, index) => {
|
|
1155
1322
|
if (maxIdx != null && index > maxIdx) {
|
|
1156
1323
|
return getDataStrategyMatch(
|
|
1157
1324
|
mapRouteProperties,
|
|
1158
1325
|
manifest,
|
|
1159
1326
|
request,
|
|
1327
|
+
pattern,
|
|
1160
1328
|
match,
|
|
1161
1329
|
[],
|
|
1162
1330
|
requestContext,
|
|
@@ -1167,6 +1335,7 @@ function createStaticHandler(routes, opts) {
|
|
|
1167
1335
|
mapRouteProperties,
|
|
1168
1336
|
manifest,
|
|
1169
1337
|
request,
|
|
1338
|
+
pattern,
|
|
1170
1339
|
match,
|
|
1171
1340
|
[],
|
|
1172
1341
|
requestContext,
|
|
@@ -1505,12 +1674,17 @@ function runServerMiddlewarePipeline(args, handler, errorHandler) {
|
|
|
1505
1674
|
}
|
|
1506
1675
|
}
|
|
1507
1676
|
async function runMiddlewarePipeline(args, handler, processResult, isResult, errorHandler) {
|
|
1508
|
-
let { matches, request, params, context } = args;
|
|
1677
|
+
let { matches, request, params, context, unstable_pattern } = args;
|
|
1509
1678
|
let tuples = matches.flatMap(
|
|
1510
1679
|
(m) => m.route.middleware ? m.route.middleware.map((fn) => [m.route.id, fn]) : []
|
|
1511
1680
|
);
|
|
1512
1681
|
let result = await callRouteMiddleware(
|
|
1513
|
-
{
|
|
1682
|
+
{
|
|
1683
|
+
request,
|
|
1684
|
+
params,
|
|
1685
|
+
context,
|
|
1686
|
+
unstable_pattern
|
|
1687
|
+
},
|
|
1514
1688
|
tuples,
|
|
1515
1689
|
handler,
|
|
1516
1690
|
processResult,
|
|
@@ -1588,7 +1762,7 @@ function getDataStrategyMatchLazyPromises(mapRouteProperties, manifest, request,
|
|
|
1588
1762
|
handler: lazyRoutePromises.lazyHandlerPromise
|
|
1589
1763
|
};
|
|
1590
1764
|
}
|
|
1591
|
-
function getDataStrategyMatch(mapRouteProperties, manifest, request, match, lazyRoutePropertiesToSkip, scopedContext, shouldLoad, unstable_shouldRevalidateArgs = null) {
|
|
1765
|
+
function getDataStrategyMatch(mapRouteProperties, manifest, request, unstable_pattern, match, lazyRoutePropertiesToSkip, scopedContext, shouldLoad, unstable_shouldRevalidateArgs = null) {
|
|
1592
1766
|
let isUsingNewApi = false;
|
|
1593
1767
|
let _lazyPromises = getDataStrategyMatchLazyPromises(
|
|
1594
1768
|
mapRouteProperties,
|
|
@@ -1622,6 +1796,7 @@ function getDataStrategyMatch(mapRouteProperties, manifest, request, match, lazy
|
|
|
1622
1796
|
if (callHandler && !isMiddlewareOnlyRoute) {
|
|
1623
1797
|
return callLoaderOrAction({
|
|
1624
1798
|
request,
|
|
1799
|
+
unstable_pattern,
|
|
1625
1800
|
match,
|
|
1626
1801
|
lazyHandlerPromise: _lazyPromises?.handler,
|
|
1627
1802
|
lazyRoutePromise: _lazyPromises?.route,
|
|
@@ -1655,6 +1830,7 @@ function getTargetedDataStrategyMatches(mapRouteProperties, manifest, request, m
|
|
|
1655
1830
|
mapRouteProperties,
|
|
1656
1831
|
manifest,
|
|
1657
1832
|
request,
|
|
1833
|
+
getRoutePattern(matches.map((m) => m.route.path)),
|
|
1658
1834
|
match,
|
|
1659
1835
|
lazyRoutePropertiesToSkip,
|
|
1660
1836
|
scopedContext,
|
|
@@ -1669,6 +1845,7 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
|
|
|
1669
1845
|
}
|
|
1670
1846
|
let dataStrategyArgs = {
|
|
1671
1847
|
request,
|
|
1848
|
+
unstable_pattern: getRoutePattern(matches.map((m) => m.route.path)),
|
|
1672
1849
|
params: matches[0].params,
|
|
1673
1850
|
context: scopedContext,
|
|
1674
1851
|
matches
|
|
@@ -1696,6 +1873,7 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
|
|
|
1696
1873
|
}
|
|
1697
1874
|
async function callLoaderOrAction({
|
|
1698
1875
|
request,
|
|
1876
|
+
unstable_pattern,
|
|
1699
1877
|
match,
|
|
1700
1878
|
lazyHandlerPromise,
|
|
1701
1879
|
lazyRoutePromise,
|
|
@@ -1722,6 +1900,7 @@ async function callLoaderOrAction({
|
|
|
1722
1900
|
return handler(
|
|
1723
1901
|
{
|
|
1724
1902
|
request,
|
|
1903
|
+
unstable_pattern,
|
|
1725
1904
|
params: match.params,
|
|
1726
1905
|
context: scopedContext
|
|
1727
1906
|
},
|