react-router 0.0.0-experimental-c19b79d → 0.0.0-experimental-31a822c5f
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/CHANGELOG.md +105 -0
- package/dist/development/browser-B4aBBnx8.d.ts +310 -0
- package/dist/development/browser-CN2w9Cbu.d.mts +310 -0
- package/dist/development/{chunk-LUB73E44.js → chunk-CZ7KRWQZ.js} +827 -64
- package/dist/development/{chunk-AGOH44BE.mjs → chunk-FXUONXY4.mjs} +132 -808
- package/dist/development/chunk-SE36CWVW.js +1308 -0
- package/dist/development/chunk-T5RKBXBV.js +188 -0
- package/dist/development/{chunk-IMKEG5CI.mjs → chunk-WTUOISGV.mjs} +2 -2
- package/dist/development/dom-export.d.mts +48 -3
- package/dist/development/dom-export.d.ts +48 -1
- package/dist/development/dom-export.js +703 -18
- package/dist/development/dom-export.mjs +687 -9
- package/dist/development/{index-react-server-client-DKvU8YRr.d.ts → index-react-server-client-BOJoTiaG.d.ts} +134 -134
- package/dist/{production/index-react-server-client-2EDmGlsZ.d.mts → development/index-react-server-client-CuQLmpku.d.mts} +1 -2
- package/dist/development/index-react-server-client.d.mts +2 -3
- package/dist/development/index-react-server-client.d.ts +2 -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.js +1 -1
- package/dist/development/index-react-server.mjs +1 -1
- package/dist/development/index.d.mts +9 -316
- package/dist/development/index.d.ts +9 -358
- package/dist/development/index.js +82 -914
- package/dist/development/index.mjs +3 -9
- package/dist/development/lib/types/internal.d.mts +2 -3
- package/dist/development/lib/types/internal.d.ts +2 -2
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/lib/types/internal.mjs +1 -1
- package/dist/{production/register-BrVEYTED.d.mts → development/register-BblEgJPm.d.mts} +1 -1
- package/dist/development/{register-D8NQoPsO.d.ts → register-D18raRVf.d.ts} +1 -1
- package/dist/development/{context-BqL5Eckq.d.mts → route-data-nQS6GSUI.d.mts} +472 -2
- package/dist/development/{routeModules-BmVo7q9e.d.ts → routeModules-9wlxglVk.d.ts} +12 -12
- package/dist/production/browser-B4aBBnx8.d.ts +310 -0
- package/dist/production/browser-CN2w9Cbu.d.mts +310 -0
- package/dist/production/{chunk-2L5AG5Y5.js → chunk-DRKUM6HW.js} +827 -64
- package/dist/production/{chunk-AODJW4D3.mjs → chunk-IGF74WUC.mjs} +132 -808
- package/dist/production/{chunk-UOQCOPF6.mjs → chunk-RUSRTUHT.mjs} +2 -2
- package/dist/production/chunk-UU3LJMU6.js +188 -0
- package/dist/production/chunk-YVVCGSEG.js +1308 -0
- package/dist/production/dom-export.d.mts +48 -3
- package/dist/production/dom-export.d.ts +48 -1
- package/dist/production/dom-export.js +703 -18
- package/dist/production/dom-export.mjs +687 -9
- package/dist/production/{index-react-server-client-DKvU8YRr.d.ts → index-react-server-client-BOJoTiaG.d.ts} +134 -134
- package/dist/{development/index-react-server-client-2EDmGlsZ.d.mts → production/index-react-server-client-CuQLmpku.d.mts} +1 -2
- package/dist/production/index-react-server-client.d.mts +2 -3
- package/dist/production/index-react-server-client.d.ts +2 -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.js +1 -1
- package/dist/production/index-react-server.mjs +1 -1
- package/dist/production/index.d.mts +9 -316
- package/dist/production/index.d.ts +9 -358
- package/dist/production/index.js +82 -914
- package/dist/production/index.mjs +3 -9
- package/dist/production/lib/types/internal.d.mts +2 -3
- package/dist/production/lib/types/internal.d.ts +2 -2
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/lib/types/internal.mjs +1 -1
- package/dist/{development/register-BrVEYTED.d.mts → production/register-BblEgJPm.d.mts} +1 -1
- package/dist/production/{register-D8NQoPsO.d.ts → register-D18raRVf.d.ts} +1 -1
- package/dist/production/{context-BqL5Eckq.d.mts → route-data-nQS6GSUI.d.mts} +472 -2
- package/dist/production/{routeModules-BmVo7q9e.d.ts → routeModules-9wlxglVk.d.ts} +12 -12
- package/package.json +1 -1
- package/dist/development/browser-z32v5KVN.d.mts +0 -46
- package/dist/development/chunk-2G2U5HGB.js +0 -2089
- package/dist/development/route-data-CDwqkzPE.d.mts +0 -473
- package/dist/production/browser-z32v5KVN.d.mts +0 -46
- package/dist/production/chunk-FGRCWJDI.js +0 -2089
- package/dist/production/route-data-CDwqkzPE.d.mts +0 -473
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v0.0.0-experimental-
|
|
2
|
+
* react-router v0.0.0-experimental-31a822c5f
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -10,26 +10,40 @@
|
|
|
10
10
|
*/
|
|
11
11
|
"use client";
|
|
12
12
|
import {
|
|
13
|
+
RSCRouterGlobalErrorBoundary,
|
|
13
14
|
deserializeErrors,
|
|
14
|
-
getHydrationData
|
|
15
|
-
|
|
15
|
+
getHydrationData,
|
|
16
|
+
populateRSCRouteModules
|
|
17
|
+
} from "./chunk-IGF74WUC.mjs";
|
|
16
18
|
import {
|
|
17
19
|
CRITICAL_CSS_DATA_ATTRIBUTE,
|
|
20
|
+
ErrorResponseImpl,
|
|
18
21
|
FrameworkContext,
|
|
22
|
+
RSCRouterContext,
|
|
19
23
|
RemixErrorBoundary,
|
|
20
24
|
RouterProvider,
|
|
25
|
+
UNSTABLE_TransitionEnabledRouterProvider,
|
|
21
26
|
createBrowserHistory,
|
|
22
27
|
createClientRoutes,
|
|
23
28
|
createClientRoutesWithHMRRevalidationOptOut,
|
|
29
|
+
createContext,
|
|
30
|
+
createRequestInit,
|
|
24
31
|
createRouter,
|
|
25
32
|
decodeViaTurboStream,
|
|
26
33
|
getPatchRoutesOnNavigationFunction,
|
|
34
|
+
getSingleFetchDataStrategyImpl,
|
|
27
35
|
getTurboStreamSingleFetchDataStrategy,
|
|
28
36
|
hydrationRouteProperties,
|
|
29
37
|
invariant,
|
|
38
|
+
isMutationMethod,
|
|
30
39
|
mapRouteProperties,
|
|
40
|
+
noActionDefinedError,
|
|
41
|
+
setIsHydrated,
|
|
42
|
+
shouldHydrateRouteLoader,
|
|
43
|
+
singleFetchUrl,
|
|
44
|
+
stripIndexParam,
|
|
31
45
|
useFogOFWarDiscovery
|
|
32
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-RUSRTUHT.mjs";
|
|
33
47
|
|
|
34
48
|
// lib/dom-export/dom-router-provider.tsx
|
|
35
49
|
import * as React from "react";
|
|
@@ -183,7 +197,7 @@ function HydratedRouter(props) {
|
|
|
183
197
|
document.querySelectorAll(`[${CRITICAL_CSS_DATA_ATTRIBUTE}]`).forEach((element) => element.remove());
|
|
184
198
|
}
|
|
185
199
|
}, [criticalCss]);
|
|
186
|
-
let [
|
|
200
|
+
let [location2, setLocation] = React2.useState(router.state.location);
|
|
187
201
|
React2.useLayoutEffect(() => {
|
|
188
202
|
if (ssrInfo && ssrInfo.router && !ssrInfo.routerInitialized) {
|
|
189
203
|
ssrInfo.routerInitialized = true;
|
|
@@ -193,12 +207,12 @@ function HydratedRouter(props) {
|
|
|
193
207
|
React2.useLayoutEffect(() => {
|
|
194
208
|
if (ssrInfo && ssrInfo.router) {
|
|
195
209
|
return ssrInfo.router.subscribe((newState) => {
|
|
196
|
-
if (newState.location !==
|
|
210
|
+
if (newState.location !== location2) {
|
|
197
211
|
setLocation(newState.location);
|
|
198
212
|
}
|
|
199
213
|
});
|
|
200
214
|
}
|
|
201
|
-
}, [
|
|
215
|
+
}, [location2]);
|
|
202
216
|
invariant(ssrInfo, "ssrInfo unavailable for HydratedRouter");
|
|
203
217
|
useFogOFWarDiscovery(
|
|
204
218
|
router,
|
|
@@ -224,7 +238,7 @@ function HydratedRouter(props) {
|
|
|
224
238
|
routeDiscovery: ssrInfo.context.routeDiscovery
|
|
225
239
|
}
|
|
226
240
|
},
|
|
227
|
-
/* @__PURE__ */ React2.createElement(RemixErrorBoundary, { location }, /* @__PURE__ */ React2.createElement(
|
|
241
|
+
/* @__PURE__ */ React2.createElement(RemixErrorBoundary, { location: location2 }, /* @__PURE__ */ React2.createElement(
|
|
228
242
|
RouterProvider2,
|
|
229
243
|
{
|
|
230
244
|
router,
|
|
@@ -234,7 +248,671 @@ function HydratedRouter(props) {
|
|
|
234
248
|
), /* @__PURE__ */ React2.createElement(React2.Fragment, null))
|
|
235
249
|
);
|
|
236
250
|
}
|
|
251
|
+
|
|
252
|
+
// lib/rsc/browser.tsx
|
|
253
|
+
import * as React3 from "react";
|
|
254
|
+
import * as ReactDOM2 from "react-dom";
|
|
255
|
+
function createCallServer({
|
|
256
|
+
createFromReadableStream,
|
|
257
|
+
createTemporaryReferenceSet,
|
|
258
|
+
encodeReply,
|
|
259
|
+
fetch: fetchImplementation = fetch
|
|
260
|
+
}) {
|
|
261
|
+
const globalVar = window;
|
|
262
|
+
let landedActionId = 0;
|
|
263
|
+
return async (id, args) => {
|
|
264
|
+
let actionId = globalVar.__routerActionID = (globalVar.__routerActionID ?? (globalVar.__routerActionID = 0)) + 1;
|
|
265
|
+
const temporaryReferences = createTemporaryReferenceSet();
|
|
266
|
+
const payloadPromise = fetchImplementation(
|
|
267
|
+
new Request(location.href, {
|
|
268
|
+
body: await encodeReply(args, { temporaryReferences }),
|
|
269
|
+
method: "POST",
|
|
270
|
+
headers: {
|
|
271
|
+
Accept: "text/x-component",
|
|
272
|
+
"rsc-action-id": id
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
).then((response) => {
|
|
276
|
+
if (!response.body) {
|
|
277
|
+
throw new Error("No response body");
|
|
278
|
+
}
|
|
279
|
+
return createFromReadableStream(response.body, {
|
|
280
|
+
temporaryReferences
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
globalVar.__reactRouterDataRouter.__setPendingRerender(
|
|
284
|
+
Promise.resolve(payloadPromise).then(async (payload) => {
|
|
285
|
+
if (payload.type === "redirect") {
|
|
286
|
+
if (payload.reload || isExternalLocation(payload.location)) {
|
|
287
|
+
window.location.href = payload.location;
|
|
288
|
+
return () => {
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
return () => {
|
|
292
|
+
globalVar.__reactRouterDataRouter.navigate(payload.location, {
|
|
293
|
+
replace: payload.replace
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
if (payload.type !== "action") {
|
|
298
|
+
throw new Error("Unexpected payload type");
|
|
299
|
+
}
|
|
300
|
+
const rerender = await payload.rerender;
|
|
301
|
+
if (rerender && landedActionId < actionId && globalVar.__routerActionID <= actionId) {
|
|
302
|
+
if (rerender.type === "redirect") {
|
|
303
|
+
if (rerender.reload || isExternalLocation(rerender.location)) {
|
|
304
|
+
window.location.href = rerender.location;
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
return () => {
|
|
308
|
+
globalVar.__reactRouterDataRouter.navigate(rerender.location, {
|
|
309
|
+
replace: rerender.replace
|
|
310
|
+
});
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
return () => {
|
|
314
|
+
let lastMatch;
|
|
315
|
+
for (const match of rerender.matches) {
|
|
316
|
+
globalVar.__reactRouterDataRouter.patchRoutes(
|
|
317
|
+
lastMatch?.id ?? null,
|
|
318
|
+
[createRouteFromServerManifest(match)],
|
|
319
|
+
true
|
|
320
|
+
);
|
|
321
|
+
lastMatch = match;
|
|
322
|
+
}
|
|
323
|
+
window.__reactRouterDataRouter._internalSetStateDoNotUseOrYouWillBreakYourApp(
|
|
324
|
+
{
|
|
325
|
+
loaderData: Object.assign(
|
|
326
|
+
{},
|
|
327
|
+
globalVar.__reactRouterDataRouter.state.loaderData,
|
|
328
|
+
rerender.loaderData
|
|
329
|
+
),
|
|
330
|
+
errors: rerender.errors ? Object.assign(
|
|
331
|
+
{},
|
|
332
|
+
globalVar.__reactRouterDataRouter.state.errors,
|
|
333
|
+
rerender.errors
|
|
334
|
+
) : null
|
|
335
|
+
}
|
|
336
|
+
);
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
return () => {
|
|
340
|
+
};
|
|
341
|
+
}).catch(() => {
|
|
342
|
+
})
|
|
343
|
+
);
|
|
344
|
+
return payloadPromise.then((payload) => {
|
|
345
|
+
if (payload.type !== "action" && payload.type !== "redirect") {
|
|
346
|
+
throw new Error("Unexpected payload type");
|
|
347
|
+
}
|
|
348
|
+
return payload.actionResult;
|
|
349
|
+
});
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function createRouterFromPayload({
|
|
353
|
+
fetchImplementation,
|
|
354
|
+
createFromReadableStream,
|
|
355
|
+
getContext,
|
|
356
|
+
payload
|
|
357
|
+
}) {
|
|
358
|
+
const globalVar = window;
|
|
359
|
+
if (globalVar.__reactRouterDataRouter && globalVar.__reactRouterRouteModules)
|
|
360
|
+
return {
|
|
361
|
+
router: globalVar.__reactRouterDataRouter,
|
|
362
|
+
routeModules: globalVar.__reactRouterRouteModules
|
|
363
|
+
};
|
|
364
|
+
if (payload.type !== "render") throw new Error("Invalid payload type");
|
|
365
|
+
globalVar.__reactRouterRouteModules = globalVar.__reactRouterRouteModules ?? {};
|
|
366
|
+
populateRSCRouteModules(globalVar.__reactRouterRouteModules, payload.matches);
|
|
367
|
+
let patches = /* @__PURE__ */ new Map();
|
|
368
|
+
payload.patches?.forEach((patch) => {
|
|
369
|
+
invariant(patch.parentId, "Invalid patch parentId");
|
|
370
|
+
if (!patches.has(patch.parentId)) {
|
|
371
|
+
patches.set(patch.parentId, []);
|
|
372
|
+
}
|
|
373
|
+
patches.get(patch.parentId)?.push(patch);
|
|
374
|
+
});
|
|
375
|
+
let routes = payload.matches.reduceRight((previous, match) => {
|
|
376
|
+
const route = createRouteFromServerManifest(
|
|
377
|
+
match,
|
|
378
|
+
payload
|
|
379
|
+
);
|
|
380
|
+
if (previous.length > 0) {
|
|
381
|
+
route.children = previous;
|
|
382
|
+
let childrenToPatch = patches.get(match.id);
|
|
383
|
+
if (childrenToPatch) {
|
|
384
|
+
route.children.push(
|
|
385
|
+
...childrenToPatch.map((r) => createRouteFromServerManifest(r))
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return [route];
|
|
390
|
+
}, []);
|
|
391
|
+
globalVar.__reactRouterDataRouter = createRouter({
|
|
392
|
+
routes,
|
|
393
|
+
getContext,
|
|
394
|
+
basename: payload.basename,
|
|
395
|
+
history: createBrowserHistory(),
|
|
396
|
+
hydrationData: getHydrationData({
|
|
397
|
+
state: {
|
|
398
|
+
loaderData: payload.loaderData,
|
|
399
|
+
actionData: payload.actionData,
|
|
400
|
+
errors: payload.errors
|
|
401
|
+
},
|
|
402
|
+
routes,
|
|
403
|
+
getRouteInfo: (routeId) => {
|
|
404
|
+
let match = payload.matches.find((m) => m.id === routeId);
|
|
405
|
+
invariant(match, "Route not found in payload");
|
|
406
|
+
return {
|
|
407
|
+
clientLoader: match.clientLoader,
|
|
408
|
+
hasLoader: match.hasLoader,
|
|
409
|
+
hasHydrateFallback: match.hydrateFallbackElement != null
|
|
410
|
+
};
|
|
411
|
+
},
|
|
412
|
+
location: payload.location,
|
|
413
|
+
basename: payload.basename,
|
|
414
|
+
isSpaMode: false
|
|
415
|
+
}),
|
|
416
|
+
async patchRoutesOnNavigation({ path, signal }) {
|
|
417
|
+
if (discoveredPaths.has(path)) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
await fetchAndApplyManifestPatches(
|
|
421
|
+
[path],
|
|
422
|
+
createFromReadableStream,
|
|
423
|
+
fetchImplementation,
|
|
424
|
+
signal
|
|
425
|
+
);
|
|
426
|
+
},
|
|
427
|
+
// FIXME: Pass `build.ssr` into this function
|
|
428
|
+
dataStrategy: getRSCSingleFetchDataStrategy(
|
|
429
|
+
() => globalVar.__reactRouterDataRouter,
|
|
430
|
+
true,
|
|
431
|
+
payload.basename,
|
|
432
|
+
createFromReadableStream,
|
|
433
|
+
fetchImplementation
|
|
434
|
+
)
|
|
435
|
+
});
|
|
436
|
+
if (globalVar.__reactRouterDataRouter.state.initialized) {
|
|
437
|
+
globalVar.__routerInitialized = true;
|
|
438
|
+
globalVar.__reactRouterDataRouter.initialize();
|
|
439
|
+
} else {
|
|
440
|
+
globalVar.__routerInitialized = false;
|
|
441
|
+
}
|
|
442
|
+
let lastLoaderData = void 0;
|
|
443
|
+
globalVar.__reactRouterDataRouter.subscribe(({ loaderData, actionData }) => {
|
|
444
|
+
if (lastLoaderData !== loaderData) {
|
|
445
|
+
globalVar.__routerActionID = (globalVar.__routerActionID ?? (globalVar.__routerActionID = 0)) + 1;
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
globalVar.__reactRouterDataRouter._updateRoutesForHMR = (routeUpdateByRouteId) => {
|
|
449
|
+
const oldRoutes = window.__reactRouterDataRouter.routes;
|
|
450
|
+
const newRoutes = [];
|
|
451
|
+
function walkRoutes(routes2, parentId) {
|
|
452
|
+
return routes2.map((route) => {
|
|
453
|
+
const routeUpdate = routeUpdateByRouteId.get(route.id);
|
|
454
|
+
if (routeUpdate) {
|
|
455
|
+
const {
|
|
456
|
+
routeModule,
|
|
457
|
+
hasAction,
|
|
458
|
+
hasComponent,
|
|
459
|
+
hasErrorBoundary,
|
|
460
|
+
hasLoader
|
|
461
|
+
} = routeUpdate;
|
|
462
|
+
const newRoute = createRouteFromServerManifest({
|
|
463
|
+
clientAction: routeModule.clientAction,
|
|
464
|
+
clientLoader: routeModule.clientLoader,
|
|
465
|
+
element: route.element,
|
|
466
|
+
errorElement: route.errorElement,
|
|
467
|
+
handle: route.handle,
|
|
468
|
+
hasAction,
|
|
469
|
+
hasComponent,
|
|
470
|
+
hasErrorBoundary,
|
|
471
|
+
hasLoader,
|
|
472
|
+
hydrateFallbackElement: route.hydrateFallbackElement,
|
|
473
|
+
id: route.id,
|
|
474
|
+
index: route.index,
|
|
475
|
+
links: routeModule.links,
|
|
476
|
+
meta: routeModule.meta,
|
|
477
|
+
parentId,
|
|
478
|
+
path: route.path,
|
|
479
|
+
shouldRevalidate: routeModule.shouldRevalidate
|
|
480
|
+
});
|
|
481
|
+
if (route.children) {
|
|
482
|
+
newRoute.children = walkRoutes(route.children, route.id);
|
|
483
|
+
}
|
|
484
|
+
return newRoute;
|
|
485
|
+
}
|
|
486
|
+
const updatedRoute = { ...route };
|
|
487
|
+
if (route.children) {
|
|
488
|
+
updatedRoute.children = walkRoutes(route.children, route.id);
|
|
489
|
+
}
|
|
490
|
+
return updatedRoute;
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
newRoutes.push(
|
|
494
|
+
...walkRoutes(oldRoutes, void 0)
|
|
495
|
+
);
|
|
496
|
+
window.__reactRouterDataRouter._internalSetRoutes(newRoutes);
|
|
497
|
+
};
|
|
498
|
+
return {
|
|
499
|
+
router: globalVar.__reactRouterDataRouter,
|
|
500
|
+
routeModules: globalVar.__reactRouterRouteModules
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
var renderedRoutesContext = createContext();
|
|
504
|
+
function getRSCSingleFetchDataStrategy(getRouter, ssr, basename, createFromReadableStream, fetchImplementation) {
|
|
505
|
+
let dataStrategy = getSingleFetchDataStrategyImpl(
|
|
506
|
+
getRouter,
|
|
507
|
+
(match) => {
|
|
508
|
+
let M = match;
|
|
509
|
+
return {
|
|
510
|
+
hasLoader: M.route.hasLoader,
|
|
511
|
+
hasClientLoader: M.route.hasClientLoader,
|
|
512
|
+
hasComponent: M.route.hasComponent,
|
|
513
|
+
hasAction: M.route.hasAction,
|
|
514
|
+
hasClientAction: M.route.hasClientAction,
|
|
515
|
+
hasShouldRevalidate: M.route.hasShouldRevalidate
|
|
516
|
+
};
|
|
517
|
+
},
|
|
518
|
+
// pass map into fetchAndDecode so it can add payloads
|
|
519
|
+
getFetchAndDecodeViaRSC(createFromReadableStream, fetchImplementation),
|
|
520
|
+
ssr,
|
|
521
|
+
basename,
|
|
522
|
+
// If the route has a component but we don't have an element, we need to hit
|
|
523
|
+
// the server loader flow regardless of whether the client loader calls
|
|
524
|
+
// `serverLoader` or not, otherwise we'll have nothing to render.
|
|
525
|
+
(match) => {
|
|
526
|
+
let M = match;
|
|
527
|
+
return M.route.hasComponent && !M.route.element;
|
|
528
|
+
}
|
|
529
|
+
);
|
|
530
|
+
return async (args) => args.runClientMiddleware(async () => {
|
|
531
|
+
let context = args.context;
|
|
532
|
+
context.set(renderedRoutesContext, []);
|
|
533
|
+
let results = await dataStrategy(args);
|
|
534
|
+
const renderedRoutesById = /* @__PURE__ */ new Map();
|
|
535
|
+
for (const route of context.get(renderedRoutesContext)) {
|
|
536
|
+
if (!renderedRoutesById.has(route.id)) {
|
|
537
|
+
renderedRoutesById.set(route.id, []);
|
|
538
|
+
}
|
|
539
|
+
renderedRoutesById.get(route.id).push(route);
|
|
540
|
+
}
|
|
541
|
+
for (const match of args.matches) {
|
|
542
|
+
const renderedRoutes = renderedRoutesById.get(match.route.id);
|
|
543
|
+
if (renderedRoutes) {
|
|
544
|
+
for (const rendered of renderedRoutes) {
|
|
545
|
+
window.__reactRouterDataRouter.patchRoutes(
|
|
546
|
+
rendered.parentId ?? null,
|
|
547
|
+
[createRouteFromServerManifest(rendered)],
|
|
548
|
+
true
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return results;
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
function getFetchAndDecodeViaRSC(createFromReadableStream, fetchImplementation) {
|
|
557
|
+
return async (args, basename, targetRoutes) => {
|
|
558
|
+
let { request, context } = args;
|
|
559
|
+
let url = singleFetchUrl(request.url, basename, "rsc");
|
|
560
|
+
if (request.method === "GET") {
|
|
561
|
+
url = stripIndexParam(url);
|
|
562
|
+
if (targetRoutes) {
|
|
563
|
+
url.searchParams.set("_routes", targetRoutes.join(","));
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
let res = await fetchImplementation(
|
|
567
|
+
new Request(url, await createRequestInit(request))
|
|
568
|
+
);
|
|
569
|
+
if (res.status >= 400 && !res.headers.has("X-Remix-Response")) {
|
|
570
|
+
throw new ErrorResponseImpl(res.status, res.statusText, await res.text());
|
|
571
|
+
}
|
|
572
|
+
invariant(res.body, "No response body to decode");
|
|
573
|
+
try {
|
|
574
|
+
const payload = await createFromReadableStream(res.body, {
|
|
575
|
+
temporaryReferences: void 0
|
|
576
|
+
});
|
|
577
|
+
if (payload.type === "redirect") {
|
|
578
|
+
return {
|
|
579
|
+
status: res.status,
|
|
580
|
+
data: {
|
|
581
|
+
redirect: {
|
|
582
|
+
redirect: payload.location,
|
|
583
|
+
reload: payload.reload,
|
|
584
|
+
replace: payload.replace,
|
|
585
|
+
revalidate: false,
|
|
586
|
+
status: payload.status
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
if (payload.type !== "render") {
|
|
592
|
+
throw new Error("Unexpected payload type");
|
|
593
|
+
}
|
|
594
|
+
context.get(renderedRoutesContext).push(...payload.matches);
|
|
595
|
+
let results = { routes: {} };
|
|
596
|
+
const dataKey = isMutationMethod(request.method) ? "actionData" : "loaderData";
|
|
597
|
+
for (let [routeId, data] of Object.entries(payload[dataKey] || {})) {
|
|
598
|
+
results.routes[routeId] = { data };
|
|
599
|
+
}
|
|
600
|
+
if (payload.errors) {
|
|
601
|
+
for (let [routeId, error] of Object.entries(payload.errors)) {
|
|
602
|
+
results.routes[routeId] = { error };
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return { status: res.status, data: results };
|
|
606
|
+
} catch (e) {
|
|
607
|
+
throw new Error("Unable to decode RSC response");
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
function RSCHydratedRouter({
|
|
612
|
+
createFromReadableStream,
|
|
613
|
+
fetch: fetchImplementation = fetch,
|
|
614
|
+
payload,
|
|
615
|
+
routeDiscovery = "eager",
|
|
616
|
+
getContext
|
|
617
|
+
}) {
|
|
618
|
+
if (payload.type !== "render") throw new Error("Invalid payload type");
|
|
619
|
+
let { router: router2, routeModules } = React3.useMemo(
|
|
620
|
+
() => createRouterFromPayload({
|
|
621
|
+
payload,
|
|
622
|
+
fetchImplementation,
|
|
623
|
+
getContext,
|
|
624
|
+
createFromReadableStream
|
|
625
|
+
}),
|
|
626
|
+
[createFromReadableStream, payload, fetchImplementation, getContext]
|
|
627
|
+
);
|
|
628
|
+
React3.useEffect(() => {
|
|
629
|
+
setIsHydrated();
|
|
630
|
+
}, []);
|
|
631
|
+
React3.useLayoutEffect(() => {
|
|
632
|
+
const globalVar = window;
|
|
633
|
+
if (!globalVar.__routerInitialized) {
|
|
634
|
+
globalVar.__routerInitialized = true;
|
|
635
|
+
globalVar.__reactRouterDataRouter.initialize();
|
|
636
|
+
}
|
|
637
|
+
}, []);
|
|
638
|
+
let [location2, setLocation] = React3.useState(router2.state.location);
|
|
639
|
+
React3.useLayoutEffect(
|
|
640
|
+
() => router2.subscribe((newState) => {
|
|
641
|
+
if (newState.location !== location2) {
|
|
642
|
+
setLocation(newState.location);
|
|
643
|
+
}
|
|
644
|
+
}),
|
|
645
|
+
[router2, location2]
|
|
646
|
+
);
|
|
647
|
+
React3.useEffect(() => {
|
|
648
|
+
if (routeDiscovery === "lazy" || // @ts-expect-error - TS doesn't know about this yet
|
|
649
|
+
window.navigator?.connection?.saveData === true) {
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
function registerElement(el) {
|
|
653
|
+
let path = el.tagName === "FORM" ? el.getAttribute("action") : el.getAttribute("href");
|
|
654
|
+
if (!path) {
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
let pathname = el.tagName === "A" ? el.pathname : new URL(path, window.location.origin).pathname;
|
|
658
|
+
if (!discoveredPaths.has(pathname)) {
|
|
659
|
+
nextPaths.add(pathname);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
async function fetchPatches() {
|
|
663
|
+
document.querySelectorAll("a[data-discover], form[data-discover]").forEach(registerElement);
|
|
664
|
+
let paths = Array.from(nextPaths.keys()).filter((path) => {
|
|
665
|
+
if (discoveredPaths.has(path)) {
|
|
666
|
+
nextPaths.delete(path);
|
|
667
|
+
return false;
|
|
668
|
+
}
|
|
669
|
+
return true;
|
|
670
|
+
});
|
|
671
|
+
if (paths.length === 0) {
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
try {
|
|
675
|
+
await fetchAndApplyManifestPatches(
|
|
676
|
+
paths,
|
|
677
|
+
createFromReadableStream,
|
|
678
|
+
fetchImplementation
|
|
679
|
+
);
|
|
680
|
+
} catch (e) {
|
|
681
|
+
console.error("Failed to fetch manifest patches", e);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
let debouncedFetchPatches = debounce(fetchPatches, 100);
|
|
685
|
+
fetchPatches();
|
|
686
|
+
let observer = new MutationObserver(() => debouncedFetchPatches());
|
|
687
|
+
observer.observe(document.documentElement, {
|
|
688
|
+
subtree: true,
|
|
689
|
+
childList: true,
|
|
690
|
+
attributes: true,
|
|
691
|
+
attributeFilter: ["data-discover", "href", "action"]
|
|
692
|
+
});
|
|
693
|
+
}, [routeDiscovery, createFromReadableStream, fetchImplementation]);
|
|
694
|
+
const frameworkContext = {
|
|
695
|
+
future: {
|
|
696
|
+
// These flags have no runtime impact so can always be false. If we add
|
|
697
|
+
// flags that drive runtime behavior they'll need to be proxied through.
|
|
698
|
+
v8_middleware: false,
|
|
699
|
+
unstable_subResourceIntegrity: false
|
|
700
|
+
},
|
|
701
|
+
isSpaMode: false,
|
|
702
|
+
ssr: true,
|
|
703
|
+
criticalCss: "",
|
|
704
|
+
manifest: {
|
|
705
|
+
routes: {},
|
|
706
|
+
version: "1",
|
|
707
|
+
url: "",
|
|
708
|
+
entry: {
|
|
709
|
+
module: "",
|
|
710
|
+
imports: []
|
|
711
|
+
}
|
|
712
|
+
},
|
|
713
|
+
routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" },
|
|
714
|
+
routeModules
|
|
715
|
+
};
|
|
716
|
+
return /* @__PURE__ */ React3.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React3.createElement(RSCRouterGlobalErrorBoundary, { location: location2 }, /* @__PURE__ */ React3.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React3.createElement(UNSTABLE_TransitionEnabledRouterProvider, { router: router2, flushSync: ReactDOM2.flushSync }))));
|
|
717
|
+
}
|
|
718
|
+
function createRouteFromServerManifest(match, payload) {
|
|
719
|
+
let hasInitialData = payload && match.id in payload.loaderData;
|
|
720
|
+
let initialData = payload?.loaderData[match.id];
|
|
721
|
+
let hasInitialError = payload?.errors && match.id in payload.errors;
|
|
722
|
+
let initialError = payload?.errors?.[match.id];
|
|
723
|
+
let isHydrationRequest = match.clientLoader?.hydrate === true || !match.hasLoader || // If the route has a component but we don't have an element, we need to hit
|
|
724
|
+
// the server loader flow regardless of whether the client loader calls
|
|
725
|
+
// `serverLoader` or not, otherwise we'll have nothing to render.
|
|
726
|
+
match.hasComponent && !match.element;
|
|
727
|
+
invariant(window.__reactRouterRouteModules);
|
|
728
|
+
populateRSCRouteModules(window.__reactRouterRouteModules, match);
|
|
729
|
+
let dataRoute = {
|
|
730
|
+
id: match.id,
|
|
731
|
+
element: match.element,
|
|
732
|
+
errorElement: match.errorElement,
|
|
733
|
+
handle: match.handle,
|
|
734
|
+
hasErrorBoundary: match.hasErrorBoundary,
|
|
735
|
+
hydrateFallbackElement: match.hydrateFallbackElement,
|
|
736
|
+
index: match.index,
|
|
737
|
+
loader: match.clientLoader ? async (args, singleFetch) => {
|
|
738
|
+
try {
|
|
739
|
+
let result = await match.clientLoader({
|
|
740
|
+
...args,
|
|
741
|
+
serverLoader: () => {
|
|
742
|
+
preventInvalidServerHandlerCall(
|
|
743
|
+
"loader",
|
|
744
|
+
match.id,
|
|
745
|
+
match.hasLoader
|
|
746
|
+
);
|
|
747
|
+
if (isHydrationRequest) {
|
|
748
|
+
if (hasInitialData) {
|
|
749
|
+
return initialData;
|
|
750
|
+
}
|
|
751
|
+
if (hasInitialError) {
|
|
752
|
+
throw initialError;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
return callSingleFetch(singleFetch);
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
return result;
|
|
759
|
+
} finally {
|
|
760
|
+
isHydrationRequest = false;
|
|
761
|
+
}
|
|
762
|
+
} : (
|
|
763
|
+
// We always make the call in this RSC world since even if we don't
|
|
764
|
+
// have a `loader` we may need to get the `element` implementation
|
|
765
|
+
(_, singleFetch) => callSingleFetch(singleFetch)
|
|
766
|
+
),
|
|
767
|
+
action: match.clientAction ? (args, singleFetch) => match.clientAction({
|
|
768
|
+
...args,
|
|
769
|
+
serverAction: async () => {
|
|
770
|
+
preventInvalidServerHandlerCall(
|
|
771
|
+
"action",
|
|
772
|
+
match.id,
|
|
773
|
+
match.hasLoader
|
|
774
|
+
);
|
|
775
|
+
return await callSingleFetch(singleFetch);
|
|
776
|
+
}
|
|
777
|
+
}) : match.hasAction ? (_, singleFetch) => callSingleFetch(singleFetch) : () => {
|
|
778
|
+
throw noActionDefinedError("action", match.id);
|
|
779
|
+
},
|
|
780
|
+
path: match.path,
|
|
781
|
+
shouldRevalidate: match.shouldRevalidate,
|
|
782
|
+
// We always have a "loader" in this RSC world since even if we don't
|
|
783
|
+
// have a `loader` we may need to get the `element` implementation
|
|
784
|
+
hasLoader: true,
|
|
785
|
+
hasClientLoader: match.clientLoader != null,
|
|
786
|
+
hasAction: match.hasAction,
|
|
787
|
+
hasClientAction: match.clientAction != null,
|
|
788
|
+
hasShouldRevalidate: match.shouldRevalidate != null
|
|
789
|
+
};
|
|
790
|
+
if (typeof dataRoute.loader === "function") {
|
|
791
|
+
dataRoute.loader.hydrate = shouldHydrateRouteLoader(
|
|
792
|
+
match.id,
|
|
793
|
+
match.clientLoader,
|
|
794
|
+
match.hasLoader,
|
|
795
|
+
false
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
return dataRoute;
|
|
799
|
+
}
|
|
800
|
+
function callSingleFetch(singleFetch) {
|
|
801
|
+
invariant(typeof singleFetch === "function", "Invalid singleFetch parameter");
|
|
802
|
+
return singleFetch();
|
|
803
|
+
}
|
|
804
|
+
function preventInvalidServerHandlerCall(type, routeId, hasHandler) {
|
|
805
|
+
if (!hasHandler) {
|
|
806
|
+
let fn = type === "action" ? "serverAction()" : "serverLoader()";
|
|
807
|
+
let msg = `You are trying to call ${fn} on a route that does not have a server ${type} (routeId: "${routeId}")`;
|
|
808
|
+
console.error(msg);
|
|
809
|
+
throw new ErrorResponseImpl(400, "Bad Request", new Error(msg), true);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
var nextPaths = /* @__PURE__ */ new Set();
|
|
813
|
+
var discoveredPathsMaxSize = 1e3;
|
|
814
|
+
var discoveredPaths = /* @__PURE__ */ new Set();
|
|
815
|
+
var URL_LIMIT = 7680;
|
|
816
|
+
function getManifestUrl(paths) {
|
|
817
|
+
if (paths.length === 0) {
|
|
818
|
+
return null;
|
|
819
|
+
}
|
|
820
|
+
if (paths.length === 1) {
|
|
821
|
+
return new URL(`${paths[0]}.manifest`, window.location.origin);
|
|
822
|
+
}
|
|
823
|
+
const globalVar = window;
|
|
824
|
+
let basename = (globalVar.__reactRouterDataRouter.basename ?? "").replace(
|
|
825
|
+
/^\/|\/$/g,
|
|
826
|
+
""
|
|
827
|
+
);
|
|
828
|
+
let url = new URL(`${basename}/.manifest`, window.location.origin);
|
|
829
|
+
url.searchParams.set("paths", paths.sort().join(","));
|
|
830
|
+
return url;
|
|
831
|
+
}
|
|
832
|
+
async function fetchAndApplyManifestPatches(paths, createFromReadableStream, fetchImplementation, signal) {
|
|
833
|
+
let url = getManifestUrl(paths);
|
|
834
|
+
if (url == null) {
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
if (url.toString().length > URL_LIMIT) {
|
|
838
|
+
nextPaths.clear();
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
let response = await fetchImplementation(new Request(url, { signal }));
|
|
842
|
+
if (!response.body || response.status < 200 || response.status >= 300) {
|
|
843
|
+
throw new Error("Unable to fetch new route matches from the server");
|
|
844
|
+
}
|
|
845
|
+
let payload = await createFromReadableStream(response.body, {
|
|
846
|
+
temporaryReferences: void 0
|
|
847
|
+
});
|
|
848
|
+
if (payload.type !== "manifest") {
|
|
849
|
+
throw new Error("Failed to patch routes");
|
|
850
|
+
}
|
|
851
|
+
paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
|
|
852
|
+
payload.patches.forEach((p) => {
|
|
853
|
+
window.__reactRouterDataRouter.patchRoutes(
|
|
854
|
+
p.parentId ?? null,
|
|
855
|
+
[createRouteFromServerManifest(p)]
|
|
856
|
+
);
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
function addToFifoQueue(path, queue) {
|
|
860
|
+
if (queue.size >= discoveredPathsMaxSize) {
|
|
861
|
+
let first = queue.values().next().value;
|
|
862
|
+
queue.delete(first);
|
|
863
|
+
}
|
|
864
|
+
queue.add(path);
|
|
865
|
+
}
|
|
866
|
+
function debounce(callback, wait) {
|
|
867
|
+
let timeoutId;
|
|
868
|
+
return (...args) => {
|
|
869
|
+
window.clearTimeout(timeoutId);
|
|
870
|
+
timeoutId = window.setTimeout(() => callback(...args), wait);
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
function isExternalLocation(location2) {
|
|
874
|
+
const newLocation = new URL(location2, window.location.href);
|
|
875
|
+
return newLocation.origin !== window.location.origin;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// lib/rsc/html-stream/browser.ts
|
|
879
|
+
function getRSCStream() {
|
|
880
|
+
let encoder = new TextEncoder();
|
|
881
|
+
let streamController = null;
|
|
882
|
+
let rscStream = new ReadableStream({
|
|
883
|
+
start(controller) {
|
|
884
|
+
if (typeof window === "undefined") {
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
let handleChunk = (chunk) => {
|
|
888
|
+
if (typeof chunk === "string") {
|
|
889
|
+
controller.enqueue(encoder.encode(chunk));
|
|
890
|
+
} else {
|
|
891
|
+
controller.enqueue(chunk);
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
window.__FLIGHT_DATA || (window.__FLIGHT_DATA = []);
|
|
895
|
+
window.__FLIGHT_DATA.forEach(handleChunk);
|
|
896
|
+
window.__FLIGHT_DATA.push = (chunk) => {
|
|
897
|
+
handleChunk(chunk);
|
|
898
|
+
return 0;
|
|
899
|
+
};
|
|
900
|
+
streamController = controller;
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
if (typeof document !== "undefined" && document.readyState === "loading") {
|
|
904
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
905
|
+
streamController?.close();
|
|
906
|
+
});
|
|
907
|
+
} else {
|
|
908
|
+
streamController?.close();
|
|
909
|
+
}
|
|
910
|
+
return rscStream;
|
|
911
|
+
}
|
|
237
912
|
export {
|
|
238
913
|
HydratedRouter,
|
|
239
|
-
RouterProvider2 as RouterProvider
|
|
914
|
+
RouterProvider2 as RouterProvider,
|
|
915
|
+
RSCHydratedRouter as unstable_RSCHydratedRouter,
|
|
916
|
+
createCallServer as unstable_createCallServer,
|
|
917
|
+
getRSCStream as unstable_getRSCStream
|
|
240
918
|
};
|