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
|
*
|
|
@@ -22,13 +22,8 @@ import {
|
|
|
22
22
|
SingleFetchRedirectSymbol,
|
|
23
23
|
StaticRouterProvider,
|
|
24
24
|
StreamTransfer,
|
|
25
|
-
UNSTABLE_TransitionEnabledRouterProvider,
|
|
26
25
|
convertRoutesToDataRoutes,
|
|
27
|
-
createBrowserHistory,
|
|
28
|
-
createContext,
|
|
29
26
|
createMemoryRouter,
|
|
30
|
-
createRequestInit,
|
|
31
|
-
createRouter,
|
|
32
27
|
createServerRoutes,
|
|
33
28
|
createStaticHandler,
|
|
34
29
|
createStaticRouter,
|
|
@@ -36,31 +31,24 @@ import {
|
|
|
36
31
|
encode,
|
|
37
32
|
escapeHtml,
|
|
38
33
|
getManifestPath,
|
|
39
|
-
getSingleFetchDataStrategyImpl,
|
|
40
34
|
getStaticContextFromError,
|
|
41
|
-
invariant,
|
|
42
35
|
isDataWithResponseInit,
|
|
43
|
-
isMutationMethod,
|
|
44
36
|
isRedirectResponse,
|
|
45
37
|
isRedirectStatusCode,
|
|
46
38
|
isResponse,
|
|
47
39
|
isRouteErrorResponse,
|
|
48
40
|
matchRoutes,
|
|
49
|
-
noActionDefinedError,
|
|
50
41
|
redirect,
|
|
51
42
|
redirectDocument,
|
|
52
43
|
replace,
|
|
53
|
-
setIsHydrated,
|
|
54
44
|
shouldHydrateRouteLoader,
|
|
55
|
-
singleFetchUrl,
|
|
56
45
|
stripBasename,
|
|
57
|
-
stripIndexParam,
|
|
58
46
|
useRouteError,
|
|
59
47
|
warnOnce,
|
|
60
48
|
withComponentProps,
|
|
61
49
|
withErrorBoundaryProps,
|
|
62
50
|
withHydrateFallbackProps
|
|
63
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-WTUOISGV.mjs";
|
|
64
52
|
|
|
65
53
|
// lib/dom/ssr/server.tsx
|
|
66
54
|
import * as React from "react";
|
|
@@ -515,7 +503,7 @@ function matchServerRoutes(routes, pathname, basename) {
|
|
|
515
503
|
// lib/server-runtime/data.ts
|
|
516
504
|
async function callRouteHandler(handler, args) {
|
|
517
505
|
let result = await handler({
|
|
518
|
-
request: stripRoutesParam(
|
|
506
|
+
request: stripRoutesParam(stripIndexParam(args.request)),
|
|
519
507
|
params: args.params,
|
|
520
508
|
context: args.context
|
|
521
509
|
});
|
|
@@ -524,7 +512,7 @@ async function callRouteHandler(handler, args) {
|
|
|
524
512
|
}
|
|
525
513
|
return result;
|
|
526
514
|
}
|
|
527
|
-
function
|
|
515
|
+
function stripIndexParam(request) {
|
|
528
516
|
let url = new URL(request.url);
|
|
529
517
|
let indexValues = url.searchParams.getAll("index");
|
|
530
518
|
url.searchParams.delete("index");
|
|
@@ -564,7 +552,7 @@ function stripRoutesParam(request) {
|
|
|
564
552
|
}
|
|
565
553
|
|
|
566
554
|
// lib/server-runtime/invariant.ts
|
|
567
|
-
function
|
|
555
|
+
function invariant(value, message) {
|
|
568
556
|
if (value === false || value === null || typeof value === "undefined") {
|
|
569
557
|
console.error(
|
|
570
558
|
"The following error is a bug in React Router; please open an issue! https://github.com/remix-run/react-router/issues/new/choose"
|
|
@@ -630,7 +618,7 @@ function createStaticHandlerDataRoutes(manifest, future, parentId = "", routesBy
|
|
|
630
618
|
);
|
|
631
619
|
if (preRenderedData != null) {
|
|
632
620
|
let encoded = preRenderedData ? decodeURI(preRenderedData) : preRenderedData;
|
|
633
|
-
|
|
621
|
+
invariant(encoded, "Missing prerendered data for route");
|
|
634
622
|
let uint8array = new TextEncoder().encode(encoded);
|
|
635
623
|
let stream = new ReadableStream({
|
|
636
624
|
start(controller) {
|
|
@@ -651,12 +639,12 @@ function createStaticHandlerDataRoutes(manifest, future, parentId = "", routesBy
|
|
|
651
639
|
throw redirect(result.redirect, init);
|
|
652
640
|
}
|
|
653
641
|
} else {
|
|
654
|
-
|
|
642
|
+
invariant(
|
|
655
643
|
data2 && route.id in data2,
|
|
656
644
|
"Unable to decode prerendered data"
|
|
657
645
|
);
|
|
658
646
|
let result = data2[route.id];
|
|
659
|
-
|
|
647
|
+
invariant(
|
|
660
648
|
"data" in result,
|
|
661
649
|
"Unable to process prerendered data"
|
|
662
650
|
);
|
|
@@ -695,7 +683,7 @@ import { splitCookiesString } from "set-cookie-parser";
|
|
|
695
683
|
function getDocumentHeaders(context, build) {
|
|
696
684
|
return getDocumentHeadersImpl(context, (m) => {
|
|
697
685
|
let route = build.routes[m.route.id];
|
|
698
|
-
|
|
686
|
+
invariant(route, `Route with id "${m.route.id}" not found in build`);
|
|
699
687
|
return route.module.headers;
|
|
700
688
|
});
|
|
701
689
|
}
|
|
@@ -1674,41 +1662,95 @@ function href(path, ...args) {
|
|
|
1674
1662
|
return result || "/";
|
|
1675
1663
|
}
|
|
1676
1664
|
|
|
1677
|
-
// lib/rsc/
|
|
1665
|
+
// lib/rsc/server.ssr.tsx
|
|
1678
1666
|
import * as React4 from "react";
|
|
1679
|
-
import * as ReactDOM from "react-dom";
|
|
1680
1667
|
|
|
1681
|
-
// lib/
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
let
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
let routeInfo = getRouteInfo(routeId);
|
|
1699
|
-
if (shouldHydrateRouteLoader(
|
|
1700
|
-
routeId,
|
|
1701
|
-
routeInfo.clientLoader,
|
|
1702
|
-
routeInfo.hasLoader,
|
|
1703
|
-
isSpaMode
|
|
1704
|
-
) && (routeInfo.hasHydrateFallback || !routeInfo.hasLoader)) {
|
|
1705
|
-
delete hydrationData.loaderData[routeId];
|
|
1706
|
-
} else if (!routeInfo.hasLoader) {
|
|
1707
|
-
hydrationData.loaderData[routeId] = null;
|
|
1668
|
+
// lib/rsc/html-stream/server.ts
|
|
1669
|
+
var encoder2 = new TextEncoder();
|
|
1670
|
+
var trailer = "</body></html>";
|
|
1671
|
+
function injectRSCPayload(rscStream) {
|
|
1672
|
+
let decoder = new TextDecoder();
|
|
1673
|
+
let resolveFlightDataPromise;
|
|
1674
|
+
let flightDataPromise = new Promise(
|
|
1675
|
+
(resolve) => resolveFlightDataPromise = resolve
|
|
1676
|
+
);
|
|
1677
|
+
let startedRSC = false;
|
|
1678
|
+
let buffered = [];
|
|
1679
|
+
let timeout = null;
|
|
1680
|
+
function flushBufferedChunks(controller) {
|
|
1681
|
+
for (let chunk of buffered) {
|
|
1682
|
+
let buf = decoder.decode(chunk, { stream: true });
|
|
1683
|
+
if (buf.endsWith(trailer)) {
|
|
1684
|
+
buf = buf.slice(0, -trailer.length);
|
|
1708
1685
|
}
|
|
1686
|
+
controller.enqueue(encoder2.encode(buf));
|
|
1709
1687
|
}
|
|
1688
|
+
buffered.length = 0;
|
|
1689
|
+
timeout = null;
|
|
1710
1690
|
}
|
|
1711
|
-
return
|
|
1691
|
+
return new TransformStream({
|
|
1692
|
+
transform(chunk, controller) {
|
|
1693
|
+
buffered.push(chunk);
|
|
1694
|
+
if (timeout) {
|
|
1695
|
+
return;
|
|
1696
|
+
}
|
|
1697
|
+
timeout = setTimeout(async () => {
|
|
1698
|
+
flushBufferedChunks(controller);
|
|
1699
|
+
if (!startedRSC) {
|
|
1700
|
+
startedRSC = true;
|
|
1701
|
+
writeRSCStream(rscStream, controller).catch((err) => controller.error(err)).then(resolveFlightDataPromise);
|
|
1702
|
+
}
|
|
1703
|
+
}, 0);
|
|
1704
|
+
},
|
|
1705
|
+
async flush(controller) {
|
|
1706
|
+
await flightDataPromise;
|
|
1707
|
+
if (timeout) {
|
|
1708
|
+
clearTimeout(timeout);
|
|
1709
|
+
flushBufferedChunks(controller);
|
|
1710
|
+
}
|
|
1711
|
+
controller.enqueue(encoder2.encode("</body></html>"));
|
|
1712
|
+
}
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
async function writeRSCStream(rscStream, controller) {
|
|
1716
|
+
let decoder = new TextDecoder("utf-8", { fatal: true });
|
|
1717
|
+
const reader = rscStream.getReader();
|
|
1718
|
+
try {
|
|
1719
|
+
let read;
|
|
1720
|
+
while ((read = await reader.read()) && !read.done) {
|
|
1721
|
+
const chunk = read.value;
|
|
1722
|
+
try {
|
|
1723
|
+
writeChunk(
|
|
1724
|
+
JSON.stringify(decoder.decode(chunk, { stream: true })),
|
|
1725
|
+
controller
|
|
1726
|
+
);
|
|
1727
|
+
} catch (err) {
|
|
1728
|
+
let base64 = JSON.stringify(btoa(String.fromCodePoint(...chunk)));
|
|
1729
|
+
writeChunk(
|
|
1730
|
+
`Uint8Array.from(atob(${base64}), m => m.codePointAt(0))`,
|
|
1731
|
+
controller
|
|
1732
|
+
);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
} finally {
|
|
1736
|
+
reader.releaseLock();
|
|
1737
|
+
}
|
|
1738
|
+
let remaining = decoder.decode();
|
|
1739
|
+
if (remaining.length) {
|
|
1740
|
+
writeChunk(JSON.stringify(remaining), controller);
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
function writeChunk(chunk, controller) {
|
|
1744
|
+
controller.enqueue(
|
|
1745
|
+
encoder2.encode(
|
|
1746
|
+
`<script>${escapeScript(
|
|
1747
|
+
`(self.__FLIGHT_DATA||=[]).push(${chunk})`
|
|
1748
|
+
)}</script>`
|
|
1749
|
+
)
|
|
1750
|
+
);
|
|
1751
|
+
}
|
|
1752
|
+
function escapeScript(script) {
|
|
1753
|
+
return script.replace(/<!--/g, "<\\!--").replace(/<\/(script)/gi, "</\\$1");
|
|
1712
1754
|
}
|
|
1713
1755
|
|
|
1714
1756
|
// lib/rsc/errorBoundaries.tsx
|
|
@@ -1841,724 +1883,9 @@ function populateRSCRouteModules(routeModules, matches) {
|
|
|
1841
1883
|
}
|
|
1842
1884
|
var noopComponent = () => null;
|
|
1843
1885
|
|
|
1844
|
-
// lib/rsc/browser.tsx
|
|
1845
|
-
function createCallServer({
|
|
1846
|
-
createFromReadableStream,
|
|
1847
|
-
createTemporaryReferenceSet,
|
|
1848
|
-
encodeReply,
|
|
1849
|
-
fetch: fetchImplementation = fetch
|
|
1850
|
-
}) {
|
|
1851
|
-
const globalVar = window;
|
|
1852
|
-
let landedActionId = 0;
|
|
1853
|
-
return async (id, args) => {
|
|
1854
|
-
let actionId = globalVar.__routerActionID = (globalVar.__routerActionID ?? (globalVar.__routerActionID = 0)) + 1;
|
|
1855
|
-
const temporaryReferences = createTemporaryReferenceSet();
|
|
1856
|
-
const payloadPromise = fetchImplementation(
|
|
1857
|
-
new Request(location.href, {
|
|
1858
|
-
body: await encodeReply(args, { temporaryReferences }),
|
|
1859
|
-
method: "POST",
|
|
1860
|
-
headers: {
|
|
1861
|
-
Accept: "text/x-component",
|
|
1862
|
-
"rsc-action-id": id
|
|
1863
|
-
}
|
|
1864
|
-
})
|
|
1865
|
-
).then((response) => {
|
|
1866
|
-
if (!response.body) {
|
|
1867
|
-
throw new Error("No response body");
|
|
1868
|
-
}
|
|
1869
|
-
return createFromReadableStream(response.body, {
|
|
1870
|
-
temporaryReferences
|
|
1871
|
-
});
|
|
1872
|
-
});
|
|
1873
|
-
globalVar.__reactRouterDataRouter.__setPendingRerender(
|
|
1874
|
-
Promise.resolve(payloadPromise).then(async (payload) => {
|
|
1875
|
-
if (payload.type === "redirect") {
|
|
1876
|
-
if (payload.reload || isExternalLocation(payload.location)) {
|
|
1877
|
-
window.location.href = payload.location;
|
|
1878
|
-
return () => {
|
|
1879
|
-
};
|
|
1880
|
-
}
|
|
1881
|
-
return () => {
|
|
1882
|
-
globalVar.__reactRouterDataRouter.navigate(payload.location, {
|
|
1883
|
-
replace: payload.replace
|
|
1884
|
-
});
|
|
1885
|
-
};
|
|
1886
|
-
}
|
|
1887
|
-
if (payload.type !== "action") {
|
|
1888
|
-
throw new Error("Unexpected payload type");
|
|
1889
|
-
}
|
|
1890
|
-
const rerender = await payload.rerender;
|
|
1891
|
-
if (rerender && landedActionId < actionId && globalVar.__routerActionID <= actionId) {
|
|
1892
|
-
if (rerender.type === "redirect") {
|
|
1893
|
-
if (rerender.reload || isExternalLocation(rerender.location)) {
|
|
1894
|
-
window.location.href = rerender.location;
|
|
1895
|
-
return;
|
|
1896
|
-
}
|
|
1897
|
-
return () => {
|
|
1898
|
-
globalVar.__reactRouterDataRouter.navigate(rerender.location, {
|
|
1899
|
-
replace: rerender.replace
|
|
1900
|
-
});
|
|
1901
|
-
};
|
|
1902
|
-
}
|
|
1903
|
-
return () => {
|
|
1904
|
-
let lastMatch;
|
|
1905
|
-
for (const match of rerender.matches) {
|
|
1906
|
-
globalVar.__reactRouterDataRouter.patchRoutes(
|
|
1907
|
-
lastMatch?.id ?? null,
|
|
1908
|
-
[createRouteFromServerManifest(match)],
|
|
1909
|
-
true
|
|
1910
|
-
);
|
|
1911
|
-
lastMatch = match;
|
|
1912
|
-
}
|
|
1913
|
-
window.__reactRouterDataRouter._internalSetStateDoNotUseOrYouWillBreakYourApp(
|
|
1914
|
-
{
|
|
1915
|
-
loaderData: Object.assign(
|
|
1916
|
-
{},
|
|
1917
|
-
globalVar.__reactRouterDataRouter.state.loaderData,
|
|
1918
|
-
rerender.loaderData
|
|
1919
|
-
),
|
|
1920
|
-
errors: rerender.errors ? Object.assign(
|
|
1921
|
-
{},
|
|
1922
|
-
globalVar.__reactRouterDataRouter.state.errors,
|
|
1923
|
-
rerender.errors
|
|
1924
|
-
) : null
|
|
1925
|
-
}
|
|
1926
|
-
);
|
|
1927
|
-
};
|
|
1928
|
-
}
|
|
1929
|
-
return () => {
|
|
1930
|
-
};
|
|
1931
|
-
}).catch(() => {
|
|
1932
|
-
})
|
|
1933
|
-
);
|
|
1934
|
-
return payloadPromise.then((payload) => {
|
|
1935
|
-
if (payload.type !== "action" && payload.type !== "redirect") {
|
|
1936
|
-
throw new Error("Unexpected payload type");
|
|
1937
|
-
}
|
|
1938
|
-
return payload.actionResult;
|
|
1939
|
-
});
|
|
1940
|
-
};
|
|
1941
|
-
}
|
|
1942
|
-
function createRouterFromPayload({
|
|
1943
|
-
fetchImplementation,
|
|
1944
|
-
createFromReadableStream,
|
|
1945
|
-
getContext,
|
|
1946
|
-
payload
|
|
1947
|
-
}) {
|
|
1948
|
-
const globalVar = window;
|
|
1949
|
-
if (globalVar.__reactRouterDataRouter && globalVar.__reactRouterRouteModules)
|
|
1950
|
-
return {
|
|
1951
|
-
router: globalVar.__reactRouterDataRouter,
|
|
1952
|
-
routeModules: globalVar.__reactRouterRouteModules
|
|
1953
|
-
};
|
|
1954
|
-
if (payload.type !== "render") throw new Error("Invalid payload type");
|
|
1955
|
-
globalVar.__reactRouterRouteModules = globalVar.__reactRouterRouteModules ?? {};
|
|
1956
|
-
populateRSCRouteModules(globalVar.__reactRouterRouteModules, payload.matches);
|
|
1957
|
-
let patches = /* @__PURE__ */ new Map();
|
|
1958
|
-
payload.patches?.forEach((patch) => {
|
|
1959
|
-
invariant(patch.parentId, "Invalid patch parentId");
|
|
1960
|
-
if (!patches.has(patch.parentId)) {
|
|
1961
|
-
patches.set(patch.parentId, []);
|
|
1962
|
-
}
|
|
1963
|
-
patches.get(patch.parentId)?.push(patch);
|
|
1964
|
-
});
|
|
1965
|
-
let routes = payload.matches.reduceRight((previous, match) => {
|
|
1966
|
-
const route = createRouteFromServerManifest(
|
|
1967
|
-
match,
|
|
1968
|
-
payload
|
|
1969
|
-
);
|
|
1970
|
-
if (previous.length > 0) {
|
|
1971
|
-
route.children = previous;
|
|
1972
|
-
let childrenToPatch = patches.get(match.id);
|
|
1973
|
-
if (childrenToPatch) {
|
|
1974
|
-
route.children.push(
|
|
1975
|
-
...childrenToPatch.map((r) => createRouteFromServerManifest(r))
|
|
1976
|
-
);
|
|
1977
|
-
}
|
|
1978
|
-
}
|
|
1979
|
-
return [route];
|
|
1980
|
-
}, []);
|
|
1981
|
-
globalVar.__reactRouterDataRouter = createRouter({
|
|
1982
|
-
routes,
|
|
1983
|
-
getContext,
|
|
1984
|
-
basename: payload.basename,
|
|
1985
|
-
history: createBrowserHistory(),
|
|
1986
|
-
hydrationData: getHydrationData({
|
|
1987
|
-
state: {
|
|
1988
|
-
loaderData: payload.loaderData,
|
|
1989
|
-
actionData: payload.actionData,
|
|
1990
|
-
errors: payload.errors
|
|
1991
|
-
},
|
|
1992
|
-
routes,
|
|
1993
|
-
getRouteInfo: (routeId) => {
|
|
1994
|
-
let match = payload.matches.find((m) => m.id === routeId);
|
|
1995
|
-
invariant(match, "Route not found in payload");
|
|
1996
|
-
return {
|
|
1997
|
-
clientLoader: match.clientLoader,
|
|
1998
|
-
hasLoader: match.hasLoader,
|
|
1999
|
-
hasHydrateFallback: match.hydrateFallbackElement != null
|
|
2000
|
-
};
|
|
2001
|
-
},
|
|
2002
|
-
location: payload.location,
|
|
2003
|
-
basename: payload.basename,
|
|
2004
|
-
isSpaMode: false
|
|
2005
|
-
}),
|
|
2006
|
-
async patchRoutesOnNavigation({ path, signal }) {
|
|
2007
|
-
if (discoveredPaths.has(path)) {
|
|
2008
|
-
return;
|
|
2009
|
-
}
|
|
2010
|
-
await fetchAndApplyManifestPatches(
|
|
2011
|
-
[path],
|
|
2012
|
-
createFromReadableStream,
|
|
2013
|
-
fetchImplementation,
|
|
2014
|
-
signal
|
|
2015
|
-
);
|
|
2016
|
-
},
|
|
2017
|
-
// FIXME: Pass `build.ssr` into this function
|
|
2018
|
-
dataStrategy: getRSCSingleFetchDataStrategy(
|
|
2019
|
-
() => globalVar.__reactRouterDataRouter,
|
|
2020
|
-
true,
|
|
2021
|
-
payload.basename,
|
|
2022
|
-
createFromReadableStream,
|
|
2023
|
-
fetchImplementation
|
|
2024
|
-
)
|
|
2025
|
-
});
|
|
2026
|
-
if (globalVar.__reactRouterDataRouter.state.initialized) {
|
|
2027
|
-
globalVar.__routerInitialized = true;
|
|
2028
|
-
globalVar.__reactRouterDataRouter.initialize();
|
|
2029
|
-
} else {
|
|
2030
|
-
globalVar.__routerInitialized = false;
|
|
2031
|
-
}
|
|
2032
|
-
let lastLoaderData = void 0;
|
|
2033
|
-
globalVar.__reactRouterDataRouter.subscribe(({ loaderData, actionData }) => {
|
|
2034
|
-
if (lastLoaderData !== loaderData) {
|
|
2035
|
-
globalVar.__routerActionID = (globalVar.__routerActionID ?? (globalVar.__routerActionID = 0)) + 1;
|
|
2036
|
-
}
|
|
2037
|
-
});
|
|
2038
|
-
globalVar.__reactRouterDataRouter._updateRoutesForHMR = (routeUpdateByRouteId) => {
|
|
2039
|
-
const oldRoutes = window.__reactRouterDataRouter.routes;
|
|
2040
|
-
const newRoutes = [];
|
|
2041
|
-
function walkRoutes(routes2, parentId) {
|
|
2042
|
-
return routes2.map((route) => {
|
|
2043
|
-
const routeUpdate = routeUpdateByRouteId.get(route.id);
|
|
2044
|
-
if (routeUpdate) {
|
|
2045
|
-
const {
|
|
2046
|
-
routeModule,
|
|
2047
|
-
hasAction,
|
|
2048
|
-
hasComponent,
|
|
2049
|
-
hasErrorBoundary,
|
|
2050
|
-
hasLoader
|
|
2051
|
-
} = routeUpdate;
|
|
2052
|
-
const newRoute = createRouteFromServerManifest({
|
|
2053
|
-
clientAction: routeModule.clientAction,
|
|
2054
|
-
clientLoader: routeModule.clientLoader,
|
|
2055
|
-
element: route.element,
|
|
2056
|
-
errorElement: route.errorElement,
|
|
2057
|
-
handle: route.handle,
|
|
2058
|
-
hasAction,
|
|
2059
|
-
hasComponent,
|
|
2060
|
-
hasErrorBoundary,
|
|
2061
|
-
hasLoader,
|
|
2062
|
-
hydrateFallbackElement: route.hydrateFallbackElement,
|
|
2063
|
-
id: route.id,
|
|
2064
|
-
index: route.index,
|
|
2065
|
-
links: routeModule.links,
|
|
2066
|
-
meta: routeModule.meta,
|
|
2067
|
-
parentId,
|
|
2068
|
-
path: route.path,
|
|
2069
|
-
shouldRevalidate: routeModule.shouldRevalidate
|
|
2070
|
-
});
|
|
2071
|
-
if (route.children) {
|
|
2072
|
-
newRoute.children = walkRoutes(route.children, route.id);
|
|
2073
|
-
}
|
|
2074
|
-
return newRoute;
|
|
2075
|
-
}
|
|
2076
|
-
const updatedRoute = { ...route };
|
|
2077
|
-
if (route.children) {
|
|
2078
|
-
updatedRoute.children = walkRoutes(route.children, route.id);
|
|
2079
|
-
}
|
|
2080
|
-
return updatedRoute;
|
|
2081
|
-
});
|
|
2082
|
-
}
|
|
2083
|
-
newRoutes.push(
|
|
2084
|
-
...walkRoutes(oldRoutes, void 0)
|
|
2085
|
-
);
|
|
2086
|
-
window.__reactRouterDataRouter._internalSetRoutes(newRoutes);
|
|
2087
|
-
};
|
|
2088
|
-
return {
|
|
2089
|
-
router: globalVar.__reactRouterDataRouter,
|
|
2090
|
-
routeModules: globalVar.__reactRouterRouteModules
|
|
2091
|
-
};
|
|
2092
|
-
}
|
|
2093
|
-
var renderedRoutesContext = createContext();
|
|
2094
|
-
function getRSCSingleFetchDataStrategy(getRouter, ssr, basename, createFromReadableStream, fetchImplementation) {
|
|
2095
|
-
let dataStrategy = getSingleFetchDataStrategyImpl(
|
|
2096
|
-
getRouter,
|
|
2097
|
-
(match) => {
|
|
2098
|
-
let M = match;
|
|
2099
|
-
return {
|
|
2100
|
-
hasLoader: M.route.hasLoader,
|
|
2101
|
-
hasClientLoader: M.route.hasClientLoader,
|
|
2102
|
-
hasComponent: M.route.hasComponent,
|
|
2103
|
-
hasAction: M.route.hasAction,
|
|
2104
|
-
hasClientAction: M.route.hasClientAction,
|
|
2105
|
-
hasShouldRevalidate: M.route.hasShouldRevalidate
|
|
2106
|
-
};
|
|
2107
|
-
},
|
|
2108
|
-
// pass map into fetchAndDecode so it can add payloads
|
|
2109
|
-
getFetchAndDecodeViaRSC(createFromReadableStream, fetchImplementation),
|
|
2110
|
-
ssr,
|
|
2111
|
-
basename,
|
|
2112
|
-
// If the route has a component but we don't have an element, we need to hit
|
|
2113
|
-
// the server loader flow regardless of whether the client loader calls
|
|
2114
|
-
// `serverLoader` or not, otherwise we'll have nothing to render.
|
|
2115
|
-
(match) => {
|
|
2116
|
-
let M = match;
|
|
2117
|
-
return M.route.hasComponent && !M.route.element;
|
|
2118
|
-
}
|
|
2119
|
-
);
|
|
2120
|
-
return async (args) => args.runClientMiddleware(async () => {
|
|
2121
|
-
let context = args.context;
|
|
2122
|
-
context.set(renderedRoutesContext, []);
|
|
2123
|
-
let results = await dataStrategy(args);
|
|
2124
|
-
const renderedRoutesById = /* @__PURE__ */ new Map();
|
|
2125
|
-
for (const route of context.get(renderedRoutesContext)) {
|
|
2126
|
-
if (!renderedRoutesById.has(route.id)) {
|
|
2127
|
-
renderedRoutesById.set(route.id, []);
|
|
2128
|
-
}
|
|
2129
|
-
renderedRoutesById.get(route.id).push(route);
|
|
2130
|
-
}
|
|
2131
|
-
for (const match of args.matches) {
|
|
2132
|
-
const renderedRoutes = renderedRoutesById.get(match.route.id);
|
|
2133
|
-
if (renderedRoutes) {
|
|
2134
|
-
for (const rendered of renderedRoutes) {
|
|
2135
|
-
window.__reactRouterDataRouter.patchRoutes(
|
|
2136
|
-
rendered.parentId ?? null,
|
|
2137
|
-
[createRouteFromServerManifest(rendered)],
|
|
2138
|
-
true
|
|
2139
|
-
);
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
return results;
|
|
2144
|
-
});
|
|
2145
|
-
}
|
|
2146
|
-
function getFetchAndDecodeViaRSC(createFromReadableStream, fetchImplementation) {
|
|
2147
|
-
return async (args, basename, targetRoutes) => {
|
|
2148
|
-
let { request, context } = args;
|
|
2149
|
-
let url = singleFetchUrl(request.url, basename, "rsc");
|
|
2150
|
-
if (request.method === "GET") {
|
|
2151
|
-
url = stripIndexParam(url);
|
|
2152
|
-
if (targetRoutes) {
|
|
2153
|
-
url.searchParams.set("_routes", targetRoutes.join(","));
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
let res = await fetchImplementation(
|
|
2157
|
-
new Request(url, await createRequestInit(request))
|
|
2158
|
-
);
|
|
2159
|
-
if (res.status >= 400 && !res.headers.has("X-Remix-Response")) {
|
|
2160
|
-
throw new ErrorResponseImpl(res.status, res.statusText, await res.text());
|
|
2161
|
-
}
|
|
2162
|
-
invariant(res.body, "No response body to decode");
|
|
2163
|
-
try {
|
|
2164
|
-
const payload = await createFromReadableStream(res.body, {
|
|
2165
|
-
temporaryReferences: void 0
|
|
2166
|
-
});
|
|
2167
|
-
if (payload.type === "redirect") {
|
|
2168
|
-
return {
|
|
2169
|
-
status: res.status,
|
|
2170
|
-
data: {
|
|
2171
|
-
redirect: {
|
|
2172
|
-
redirect: payload.location,
|
|
2173
|
-
reload: payload.reload,
|
|
2174
|
-
replace: payload.replace,
|
|
2175
|
-
revalidate: false,
|
|
2176
|
-
status: payload.status
|
|
2177
|
-
}
|
|
2178
|
-
}
|
|
2179
|
-
};
|
|
2180
|
-
}
|
|
2181
|
-
if (payload.type !== "render") {
|
|
2182
|
-
throw new Error("Unexpected payload type");
|
|
2183
|
-
}
|
|
2184
|
-
context.get(renderedRoutesContext).push(...payload.matches);
|
|
2185
|
-
let results = { routes: {} };
|
|
2186
|
-
const dataKey = isMutationMethod(request.method) ? "actionData" : "loaderData";
|
|
2187
|
-
for (let [routeId, data2] of Object.entries(payload[dataKey] || {})) {
|
|
2188
|
-
results.routes[routeId] = { data: data2 };
|
|
2189
|
-
}
|
|
2190
|
-
if (payload.errors) {
|
|
2191
|
-
for (let [routeId, error] of Object.entries(payload.errors)) {
|
|
2192
|
-
results.routes[routeId] = { error };
|
|
2193
|
-
}
|
|
2194
|
-
}
|
|
2195
|
-
return { status: res.status, data: results };
|
|
2196
|
-
} catch (e) {
|
|
2197
|
-
throw new Error("Unable to decode RSC response");
|
|
2198
|
-
}
|
|
2199
|
-
};
|
|
2200
|
-
}
|
|
2201
|
-
function RSCHydratedRouter({
|
|
2202
|
-
createFromReadableStream,
|
|
2203
|
-
fetch: fetchImplementation = fetch,
|
|
2204
|
-
payload,
|
|
2205
|
-
routeDiscovery = "eager",
|
|
2206
|
-
getContext
|
|
2207
|
-
}) {
|
|
2208
|
-
if (payload.type !== "render") throw new Error("Invalid payload type");
|
|
2209
|
-
let { router, routeModules } = React4.useMemo(
|
|
2210
|
-
() => createRouterFromPayload({
|
|
2211
|
-
payload,
|
|
2212
|
-
fetchImplementation,
|
|
2213
|
-
getContext,
|
|
2214
|
-
createFromReadableStream
|
|
2215
|
-
}),
|
|
2216
|
-
[createFromReadableStream, payload, fetchImplementation, getContext]
|
|
2217
|
-
);
|
|
2218
|
-
React4.useEffect(() => {
|
|
2219
|
-
setIsHydrated();
|
|
2220
|
-
}, []);
|
|
2221
|
-
React4.useLayoutEffect(() => {
|
|
2222
|
-
const globalVar = window;
|
|
2223
|
-
if (!globalVar.__routerInitialized) {
|
|
2224
|
-
globalVar.__routerInitialized = true;
|
|
2225
|
-
globalVar.__reactRouterDataRouter.initialize();
|
|
2226
|
-
}
|
|
2227
|
-
}, []);
|
|
2228
|
-
let [location2, setLocation] = React4.useState(router.state.location);
|
|
2229
|
-
React4.useLayoutEffect(
|
|
2230
|
-
() => router.subscribe((newState) => {
|
|
2231
|
-
if (newState.location !== location2) {
|
|
2232
|
-
setLocation(newState.location);
|
|
2233
|
-
}
|
|
2234
|
-
}),
|
|
2235
|
-
[router, location2]
|
|
2236
|
-
);
|
|
2237
|
-
React4.useEffect(() => {
|
|
2238
|
-
if (routeDiscovery === "lazy" || // @ts-expect-error - TS doesn't know about this yet
|
|
2239
|
-
window.navigator?.connection?.saveData === true) {
|
|
2240
|
-
return;
|
|
2241
|
-
}
|
|
2242
|
-
function registerElement(el) {
|
|
2243
|
-
let path = el.tagName === "FORM" ? el.getAttribute("action") : el.getAttribute("href");
|
|
2244
|
-
if (!path) {
|
|
2245
|
-
return;
|
|
2246
|
-
}
|
|
2247
|
-
let pathname = el.tagName === "A" ? el.pathname : new URL(path, window.location.origin).pathname;
|
|
2248
|
-
if (!discoveredPaths.has(pathname)) {
|
|
2249
|
-
nextPaths.add(pathname);
|
|
2250
|
-
}
|
|
2251
|
-
}
|
|
2252
|
-
async function fetchPatches() {
|
|
2253
|
-
document.querySelectorAll("a[data-discover], form[data-discover]").forEach(registerElement);
|
|
2254
|
-
let paths = Array.from(nextPaths.keys()).filter((path) => {
|
|
2255
|
-
if (discoveredPaths.has(path)) {
|
|
2256
|
-
nextPaths.delete(path);
|
|
2257
|
-
return false;
|
|
2258
|
-
}
|
|
2259
|
-
return true;
|
|
2260
|
-
});
|
|
2261
|
-
if (paths.length === 0) {
|
|
2262
|
-
return;
|
|
2263
|
-
}
|
|
2264
|
-
try {
|
|
2265
|
-
await fetchAndApplyManifestPatches(
|
|
2266
|
-
paths,
|
|
2267
|
-
createFromReadableStream,
|
|
2268
|
-
fetchImplementation
|
|
2269
|
-
);
|
|
2270
|
-
} catch (e) {
|
|
2271
|
-
console.error("Failed to fetch manifest patches", e);
|
|
2272
|
-
}
|
|
2273
|
-
}
|
|
2274
|
-
let debouncedFetchPatches = debounce(fetchPatches, 100);
|
|
2275
|
-
fetchPatches();
|
|
2276
|
-
let observer = new MutationObserver(() => debouncedFetchPatches());
|
|
2277
|
-
observer.observe(document.documentElement, {
|
|
2278
|
-
subtree: true,
|
|
2279
|
-
childList: true,
|
|
2280
|
-
attributes: true,
|
|
2281
|
-
attributeFilter: ["data-discover", "href", "action"]
|
|
2282
|
-
});
|
|
2283
|
-
}, [routeDiscovery, createFromReadableStream, fetchImplementation]);
|
|
2284
|
-
const frameworkContext = {
|
|
2285
|
-
future: {
|
|
2286
|
-
// These flags have no runtime impact so can always be false. If we add
|
|
2287
|
-
// flags that drive runtime behavior they'll need to be proxied through.
|
|
2288
|
-
v8_middleware: false,
|
|
2289
|
-
unstable_subResourceIntegrity: false
|
|
2290
|
-
},
|
|
2291
|
-
isSpaMode: false,
|
|
2292
|
-
ssr: true,
|
|
2293
|
-
criticalCss: "",
|
|
2294
|
-
manifest: {
|
|
2295
|
-
routes: {},
|
|
2296
|
-
version: "1",
|
|
2297
|
-
url: "",
|
|
2298
|
-
entry: {
|
|
2299
|
-
module: "",
|
|
2300
|
-
imports: []
|
|
2301
|
-
}
|
|
2302
|
-
},
|
|
2303
|
-
routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" },
|
|
2304
|
-
routeModules
|
|
2305
|
-
};
|
|
2306
|
-
return /* @__PURE__ */ React4.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React4.createElement(RSCRouterGlobalErrorBoundary, { location: location2 }, /* @__PURE__ */ React4.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React4.createElement(UNSTABLE_TransitionEnabledRouterProvider, { router, flushSync: ReactDOM.flushSync }))));
|
|
2307
|
-
}
|
|
2308
|
-
function createRouteFromServerManifest(match, payload) {
|
|
2309
|
-
let hasInitialData = payload && match.id in payload.loaderData;
|
|
2310
|
-
let initialData = payload?.loaderData[match.id];
|
|
2311
|
-
let hasInitialError = payload?.errors && match.id in payload.errors;
|
|
2312
|
-
let initialError = payload?.errors?.[match.id];
|
|
2313
|
-
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
|
|
2314
|
-
// the server loader flow regardless of whether the client loader calls
|
|
2315
|
-
// `serverLoader` or not, otherwise we'll have nothing to render.
|
|
2316
|
-
match.hasComponent && !match.element;
|
|
2317
|
-
invariant(window.__reactRouterRouteModules);
|
|
2318
|
-
populateRSCRouteModules(window.__reactRouterRouteModules, match);
|
|
2319
|
-
let dataRoute = {
|
|
2320
|
-
id: match.id,
|
|
2321
|
-
element: match.element,
|
|
2322
|
-
errorElement: match.errorElement,
|
|
2323
|
-
handle: match.handle,
|
|
2324
|
-
hasErrorBoundary: match.hasErrorBoundary,
|
|
2325
|
-
hydrateFallbackElement: match.hydrateFallbackElement,
|
|
2326
|
-
index: match.index,
|
|
2327
|
-
loader: match.clientLoader ? async (args, singleFetch) => {
|
|
2328
|
-
try {
|
|
2329
|
-
let result = await match.clientLoader({
|
|
2330
|
-
...args,
|
|
2331
|
-
serverLoader: () => {
|
|
2332
|
-
preventInvalidServerHandlerCall(
|
|
2333
|
-
"loader",
|
|
2334
|
-
match.id,
|
|
2335
|
-
match.hasLoader
|
|
2336
|
-
);
|
|
2337
|
-
if (isHydrationRequest) {
|
|
2338
|
-
if (hasInitialData) {
|
|
2339
|
-
return initialData;
|
|
2340
|
-
}
|
|
2341
|
-
if (hasInitialError) {
|
|
2342
|
-
throw initialError;
|
|
2343
|
-
}
|
|
2344
|
-
}
|
|
2345
|
-
return callSingleFetch(singleFetch);
|
|
2346
|
-
}
|
|
2347
|
-
});
|
|
2348
|
-
return result;
|
|
2349
|
-
} finally {
|
|
2350
|
-
isHydrationRequest = false;
|
|
2351
|
-
}
|
|
2352
|
-
} : (
|
|
2353
|
-
// We always make the call in this RSC world since even if we don't
|
|
2354
|
-
// have a `loader` we may need to get the `element` implementation
|
|
2355
|
-
(_, singleFetch) => callSingleFetch(singleFetch)
|
|
2356
|
-
),
|
|
2357
|
-
action: match.clientAction ? (args, singleFetch) => match.clientAction({
|
|
2358
|
-
...args,
|
|
2359
|
-
serverAction: async () => {
|
|
2360
|
-
preventInvalidServerHandlerCall(
|
|
2361
|
-
"action",
|
|
2362
|
-
match.id,
|
|
2363
|
-
match.hasLoader
|
|
2364
|
-
);
|
|
2365
|
-
return await callSingleFetch(singleFetch);
|
|
2366
|
-
}
|
|
2367
|
-
}) : match.hasAction ? (_, singleFetch) => callSingleFetch(singleFetch) : () => {
|
|
2368
|
-
throw noActionDefinedError("action", match.id);
|
|
2369
|
-
},
|
|
2370
|
-
path: match.path,
|
|
2371
|
-
shouldRevalidate: match.shouldRevalidate,
|
|
2372
|
-
// We always have a "loader" in this RSC world since even if we don't
|
|
2373
|
-
// have a `loader` we may need to get the `element` implementation
|
|
2374
|
-
hasLoader: true,
|
|
2375
|
-
hasClientLoader: match.clientLoader != null,
|
|
2376
|
-
hasAction: match.hasAction,
|
|
2377
|
-
hasClientAction: match.clientAction != null,
|
|
2378
|
-
hasShouldRevalidate: match.shouldRevalidate != null
|
|
2379
|
-
};
|
|
2380
|
-
if (typeof dataRoute.loader === "function") {
|
|
2381
|
-
dataRoute.loader.hydrate = shouldHydrateRouteLoader(
|
|
2382
|
-
match.id,
|
|
2383
|
-
match.clientLoader,
|
|
2384
|
-
match.hasLoader,
|
|
2385
|
-
false
|
|
2386
|
-
);
|
|
2387
|
-
}
|
|
2388
|
-
return dataRoute;
|
|
2389
|
-
}
|
|
2390
|
-
function callSingleFetch(singleFetch) {
|
|
2391
|
-
invariant(typeof singleFetch === "function", "Invalid singleFetch parameter");
|
|
2392
|
-
return singleFetch();
|
|
2393
|
-
}
|
|
2394
|
-
function preventInvalidServerHandlerCall(type, routeId, hasHandler) {
|
|
2395
|
-
if (!hasHandler) {
|
|
2396
|
-
let fn = type === "action" ? "serverAction()" : "serverLoader()";
|
|
2397
|
-
let msg = `You are trying to call ${fn} on a route that does not have a server ${type} (routeId: "${routeId}")`;
|
|
2398
|
-
console.error(msg);
|
|
2399
|
-
throw new ErrorResponseImpl(400, "Bad Request", new Error(msg), true);
|
|
2400
|
-
}
|
|
2401
|
-
}
|
|
2402
|
-
var nextPaths = /* @__PURE__ */ new Set();
|
|
2403
|
-
var discoveredPathsMaxSize = 1e3;
|
|
2404
|
-
var discoveredPaths = /* @__PURE__ */ new Set();
|
|
2405
|
-
var URL_LIMIT = 7680;
|
|
2406
|
-
function getManifestUrl(paths) {
|
|
2407
|
-
if (paths.length === 0) {
|
|
2408
|
-
return null;
|
|
2409
|
-
}
|
|
2410
|
-
if (paths.length === 1) {
|
|
2411
|
-
return new URL(`${paths[0]}.manifest`, window.location.origin);
|
|
2412
|
-
}
|
|
2413
|
-
const globalVar = window;
|
|
2414
|
-
let basename = (globalVar.__reactRouterDataRouter.basename ?? "").replace(
|
|
2415
|
-
/^\/|\/$/g,
|
|
2416
|
-
""
|
|
2417
|
-
);
|
|
2418
|
-
let url = new URL(`${basename}/.manifest`, window.location.origin);
|
|
2419
|
-
url.searchParams.set("paths", paths.sort().join(","));
|
|
2420
|
-
return url;
|
|
2421
|
-
}
|
|
2422
|
-
async function fetchAndApplyManifestPatches(paths, createFromReadableStream, fetchImplementation, signal) {
|
|
2423
|
-
let url = getManifestUrl(paths);
|
|
2424
|
-
if (url == null) {
|
|
2425
|
-
return;
|
|
2426
|
-
}
|
|
2427
|
-
if (url.toString().length > URL_LIMIT) {
|
|
2428
|
-
nextPaths.clear();
|
|
2429
|
-
return;
|
|
2430
|
-
}
|
|
2431
|
-
let response = await fetchImplementation(new Request(url, { signal }));
|
|
2432
|
-
if (!response.body || response.status < 200 || response.status >= 300) {
|
|
2433
|
-
throw new Error("Unable to fetch new route matches from the server");
|
|
2434
|
-
}
|
|
2435
|
-
let payload = await createFromReadableStream(response.body, {
|
|
2436
|
-
temporaryReferences: void 0
|
|
2437
|
-
});
|
|
2438
|
-
if (payload.type !== "manifest") {
|
|
2439
|
-
throw new Error("Failed to patch routes");
|
|
2440
|
-
}
|
|
2441
|
-
paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
|
|
2442
|
-
payload.patches.forEach((p) => {
|
|
2443
|
-
window.__reactRouterDataRouter.patchRoutes(
|
|
2444
|
-
p.parentId ?? null,
|
|
2445
|
-
[createRouteFromServerManifest(p)]
|
|
2446
|
-
);
|
|
2447
|
-
});
|
|
2448
|
-
}
|
|
2449
|
-
function addToFifoQueue(path, queue) {
|
|
2450
|
-
if (queue.size >= discoveredPathsMaxSize) {
|
|
2451
|
-
let first = queue.values().next().value;
|
|
2452
|
-
queue.delete(first);
|
|
2453
|
-
}
|
|
2454
|
-
queue.add(path);
|
|
2455
|
-
}
|
|
2456
|
-
function debounce(callback, wait) {
|
|
2457
|
-
let timeoutId;
|
|
2458
|
-
return (...args) => {
|
|
2459
|
-
window.clearTimeout(timeoutId);
|
|
2460
|
-
timeoutId = window.setTimeout(() => callback(...args), wait);
|
|
2461
|
-
};
|
|
2462
|
-
}
|
|
2463
|
-
function isExternalLocation(location2) {
|
|
2464
|
-
const newLocation = new URL(location2, window.location.href);
|
|
2465
|
-
return newLocation.origin !== window.location.origin;
|
|
2466
|
-
}
|
|
2467
|
-
|
|
2468
|
-
// lib/rsc/server.ssr.tsx
|
|
2469
|
-
import * as React5 from "react";
|
|
2470
|
-
|
|
2471
|
-
// lib/rsc/html-stream/server.ts
|
|
2472
|
-
var encoder2 = new TextEncoder();
|
|
2473
|
-
var trailer = "</body></html>";
|
|
2474
|
-
function injectRSCPayload(rscStream) {
|
|
2475
|
-
let decoder = new TextDecoder();
|
|
2476
|
-
let resolveFlightDataPromise;
|
|
2477
|
-
let flightDataPromise = new Promise(
|
|
2478
|
-
(resolve) => resolveFlightDataPromise = resolve
|
|
2479
|
-
);
|
|
2480
|
-
let startedRSC = false;
|
|
2481
|
-
let buffered = [];
|
|
2482
|
-
let timeout = null;
|
|
2483
|
-
function flushBufferedChunks(controller) {
|
|
2484
|
-
for (let chunk of buffered) {
|
|
2485
|
-
let buf = decoder.decode(chunk, { stream: true });
|
|
2486
|
-
if (buf.endsWith(trailer)) {
|
|
2487
|
-
buf = buf.slice(0, -trailer.length);
|
|
2488
|
-
}
|
|
2489
|
-
controller.enqueue(encoder2.encode(buf));
|
|
2490
|
-
}
|
|
2491
|
-
buffered.length = 0;
|
|
2492
|
-
timeout = null;
|
|
2493
|
-
}
|
|
2494
|
-
return new TransformStream({
|
|
2495
|
-
transform(chunk, controller) {
|
|
2496
|
-
buffered.push(chunk);
|
|
2497
|
-
if (timeout) {
|
|
2498
|
-
return;
|
|
2499
|
-
}
|
|
2500
|
-
timeout = setTimeout(async () => {
|
|
2501
|
-
flushBufferedChunks(controller);
|
|
2502
|
-
if (!startedRSC) {
|
|
2503
|
-
startedRSC = true;
|
|
2504
|
-
writeRSCStream(rscStream, controller).catch((err) => controller.error(err)).then(resolveFlightDataPromise);
|
|
2505
|
-
}
|
|
2506
|
-
}, 0);
|
|
2507
|
-
},
|
|
2508
|
-
async flush(controller) {
|
|
2509
|
-
await flightDataPromise;
|
|
2510
|
-
if (timeout) {
|
|
2511
|
-
clearTimeout(timeout);
|
|
2512
|
-
flushBufferedChunks(controller);
|
|
2513
|
-
}
|
|
2514
|
-
controller.enqueue(encoder2.encode("</body></html>"));
|
|
2515
|
-
}
|
|
2516
|
-
});
|
|
2517
|
-
}
|
|
2518
|
-
async function writeRSCStream(rscStream, controller) {
|
|
2519
|
-
let decoder = new TextDecoder("utf-8", { fatal: true });
|
|
2520
|
-
const reader = rscStream.getReader();
|
|
2521
|
-
try {
|
|
2522
|
-
let read;
|
|
2523
|
-
while ((read = await reader.read()) && !read.done) {
|
|
2524
|
-
const chunk = read.value;
|
|
2525
|
-
try {
|
|
2526
|
-
writeChunk(
|
|
2527
|
-
JSON.stringify(decoder.decode(chunk, { stream: true })),
|
|
2528
|
-
controller
|
|
2529
|
-
);
|
|
2530
|
-
} catch (err) {
|
|
2531
|
-
let base64 = JSON.stringify(btoa(String.fromCodePoint(...chunk)));
|
|
2532
|
-
writeChunk(
|
|
2533
|
-
`Uint8Array.from(atob(${base64}), m => m.codePointAt(0))`,
|
|
2534
|
-
controller
|
|
2535
|
-
);
|
|
2536
|
-
}
|
|
2537
|
-
}
|
|
2538
|
-
} finally {
|
|
2539
|
-
reader.releaseLock();
|
|
2540
|
-
}
|
|
2541
|
-
let remaining = decoder.decode();
|
|
2542
|
-
if (remaining.length) {
|
|
2543
|
-
writeChunk(JSON.stringify(remaining), controller);
|
|
2544
|
-
}
|
|
2545
|
-
}
|
|
2546
|
-
function writeChunk(chunk, controller) {
|
|
2547
|
-
controller.enqueue(
|
|
2548
|
-
encoder2.encode(
|
|
2549
|
-
`<script>${escapeScript(
|
|
2550
|
-
`(self.__FLIGHT_DATA||=[]).push(${chunk})`
|
|
2551
|
-
)}</script>`
|
|
2552
|
-
)
|
|
2553
|
-
);
|
|
2554
|
-
}
|
|
2555
|
-
function escapeScript(script) {
|
|
2556
|
-
return script.replace(/<!--/g, "<\\!--").replace(/<\/(script)/gi, "</\\$1");
|
|
2557
|
-
}
|
|
2558
|
-
|
|
2559
1886
|
// lib/rsc/server.ssr.tsx
|
|
2560
1887
|
var REACT_USE = "use";
|
|
2561
|
-
var useImpl =
|
|
1888
|
+
var useImpl = React4[REACT_USE];
|
|
2562
1889
|
function useSafe(promise) {
|
|
2563
1890
|
if (useImpl) {
|
|
2564
1891
|
return useImpl(promise);
|
|
@@ -2829,7 +2156,7 @@ function RSCStaticRouter({ getPayload }) {
|
|
|
2829
2156
|
routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" },
|
|
2830
2157
|
routeModules: createRSCRouteModules(payload)
|
|
2831
2158
|
};
|
|
2832
|
-
return /* @__PURE__ */
|
|
2159
|
+
return /* @__PURE__ */ React4.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React4.createElement(RSCRouterGlobalErrorBoundary, { location: payload.location }, /* @__PURE__ */ React4.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React4.createElement(
|
|
2833
2160
|
StaticRouterProvider,
|
|
2834
2161
|
{
|
|
2835
2162
|
context,
|
|
@@ -2846,41 +2173,6 @@ function isManifestRequest(url) {
|
|
|
2846
2173
|
return url.pathname.endsWith(".manifest");
|
|
2847
2174
|
}
|
|
2848
2175
|
|
|
2849
|
-
// lib/rsc/html-stream/browser.ts
|
|
2850
|
-
function getRSCStream() {
|
|
2851
|
-
let encoder3 = new TextEncoder();
|
|
2852
|
-
let streamController = null;
|
|
2853
|
-
let rscStream = new ReadableStream({
|
|
2854
|
-
start(controller) {
|
|
2855
|
-
if (typeof window === "undefined") {
|
|
2856
|
-
return;
|
|
2857
|
-
}
|
|
2858
|
-
let handleChunk = (chunk) => {
|
|
2859
|
-
if (typeof chunk === "string") {
|
|
2860
|
-
controller.enqueue(encoder3.encode(chunk));
|
|
2861
|
-
} else {
|
|
2862
|
-
controller.enqueue(chunk);
|
|
2863
|
-
}
|
|
2864
|
-
};
|
|
2865
|
-
window.__FLIGHT_DATA || (window.__FLIGHT_DATA = []);
|
|
2866
|
-
window.__FLIGHT_DATA.forEach(handleChunk);
|
|
2867
|
-
window.__FLIGHT_DATA.push = (chunk) => {
|
|
2868
|
-
handleChunk(chunk);
|
|
2869
|
-
return 0;
|
|
2870
|
-
};
|
|
2871
|
-
streamController = controller;
|
|
2872
|
-
}
|
|
2873
|
-
});
|
|
2874
|
-
if (typeof document !== "undefined" && document.readyState === "loading") {
|
|
2875
|
-
document.addEventListener("DOMContentLoaded", () => {
|
|
2876
|
-
streamController?.close();
|
|
2877
|
-
});
|
|
2878
|
-
} else {
|
|
2879
|
-
streamController?.close();
|
|
2880
|
-
}
|
|
2881
|
-
return rscStream;
|
|
2882
|
-
}
|
|
2883
|
-
|
|
2884
2176
|
// lib/dom/ssr/errors.ts
|
|
2885
2177
|
function deserializeErrors(errors) {
|
|
2886
2178
|
if (!errors) return null;
|
|
@@ -2918,6 +2210,39 @@ function deserializeErrors(errors) {
|
|
|
2918
2210
|
return serialized;
|
|
2919
2211
|
}
|
|
2920
2212
|
|
|
2213
|
+
// lib/dom/ssr/hydration.tsx
|
|
2214
|
+
function getHydrationData({
|
|
2215
|
+
state,
|
|
2216
|
+
routes,
|
|
2217
|
+
getRouteInfo,
|
|
2218
|
+
location,
|
|
2219
|
+
basename,
|
|
2220
|
+
isSpaMode
|
|
2221
|
+
}) {
|
|
2222
|
+
let hydrationData = {
|
|
2223
|
+
...state,
|
|
2224
|
+
loaderData: { ...state.loaderData }
|
|
2225
|
+
};
|
|
2226
|
+
let initialMatches = matchRoutes(routes, location, basename);
|
|
2227
|
+
if (initialMatches) {
|
|
2228
|
+
for (let match of initialMatches) {
|
|
2229
|
+
let routeId = match.route.id;
|
|
2230
|
+
let routeInfo = getRouteInfo(routeId);
|
|
2231
|
+
if (shouldHydrateRouteLoader(
|
|
2232
|
+
routeId,
|
|
2233
|
+
routeInfo.clientLoader,
|
|
2234
|
+
routeInfo.hasLoader,
|
|
2235
|
+
isSpaMode
|
|
2236
|
+
) && (routeInfo.hasHydrateFallback || !routeInfo.hasLoader)) {
|
|
2237
|
+
delete hydrationData.loaderData[routeId];
|
|
2238
|
+
} else if (!routeInfo.hasLoader) {
|
|
2239
|
+
hydrationData.loaderData[routeId] = null;
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
return hydrationData;
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2921
2246
|
export {
|
|
2922
2247
|
ServerRouter,
|
|
2923
2248
|
createRoutesStub,
|
|
@@ -2932,12 +2257,11 @@ export {
|
|
|
2932
2257
|
createCookieSessionStorage,
|
|
2933
2258
|
createMemorySessionStorage,
|
|
2934
2259
|
href,
|
|
2935
|
-
|
|
2260
|
+
RSCRouterGlobalErrorBoundary,
|
|
2936
2261
|
RSCDefaultRootErrorBoundary,
|
|
2937
|
-
|
|
2938
|
-
RSCHydratedRouter,
|
|
2262
|
+
populateRSCRouteModules,
|
|
2939
2263
|
routeRSCServerRequest,
|
|
2940
2264
|
RSCStaticRouter,
|
|
2941
|
-
|
|
2942
|
-
|
|
2265
|
+
deserializeErrors,
|
|
2266
|
+
getHydrationData
|
|
2943
2267
|
};
|