react-router 0.0.0-experimental-cb25a21e1 → 0.0.0-experimental-e16afd9b7
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/index.js +86 -19
- package/dist/index.js.map +1 -1
- package/dist/lib/dom/global.d.ts +2 -0
- package/dist/lib/dom/ssr/single-fetch.d.ts +2 -1
- package/dist/main.js +1 -1
- package/dist/react-router.development.js +84 -19
- package/dist/react-router.development.js.map +1 -1
- package/dist/react-router.production.min.js +2 -2
- package/dist/react-router.production.min.js.map +1 -1
- package/dist/rsc.js +1641 -0
- package/dist/umd/react-router.development.js +86 -19
- package/dist/umd/react-router.development.js.map +1 -1
- package/dist/umd/react-router.production.min.js +2 -2
- package/dist/umd/react-router.production.min.js.map +1 -1
- package/package.json +10 -1
package/dist/lib/dom/global.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export type WindowRemixContext = {
|
|
|
11
11
|
isSpaMode: boolean;
|
|
12
12
|
stream: ReadableStream<Uint8Array> | undefined;
|
|
13
13
|
streamController: ReadableStreamDefaultController<Uint8Array>;
|
|
14
|
+
streamAction?: ReadableStream<Uint8Array> | undefined;
|
|
15
|
+
streamControllerAction?: ReadableStreamDefaultController<Uint8Array>;
|
|
14
16
|
a?: number;
|
|
15
17
|
dev?: {
|
|
16
18
|
port?: number;
|
|
@@ -24,8 +24,9 @@ interface StreamTransferProps {
|
|
|
24
24
|
identifier: number;
|
|
25
25
|
reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
26
26
|
textDecoder: TextDecoder;
|
|
27
|
+
isAction: boolean;
|
|
27
28
|
}
|
|
28
|
-
export declare function StreamTransfer({ context, identifier, reader, textDecoder, }: StreamTransferProps): React.JSX.Element | null;
|
|
29
|
+
export declare function StreamTransfer({ context, identifier, reader, textDecoder, isAction, }: StreamTransferProps): React.JSX.Element | null;
|
|
29
30
|
export declare function getSingleFetchDataStrategy(manifest: AssetsManifest, routeModules: RouteModules): DataStrategyFunction;
|
|
30
31
|
export declare function addRevalidationParam(manifest: AssetsManifest, routeModules: RouteModules, matchedRoutes: DataRouteObject[], loadRoutes: DataRouteObject[], url: URL): URL;
|
|
31
32
|
export declare function singleFetchUrl(reqUrl: URL | string): URL;
|
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v0.0.0-experimental-
|
|
2
|
+
* React Router v0.0.0-experimental-e16afd9b7
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -7020,7 +7020,8 @@ function StreamTransfer({
|
|
|
7020
7020
|
context,
|
|
7021
7021
|
identifier,
|
|
7022
7022
|
reader,
|
|
7023
|
-
textDecoder
|
|
7023
|
+
textDecoder,
|
|
7024
|
+
isAction
|
|
7024
7025
|
}) {
|
|
7025
7026
|
// If the user didn't render the <Scripts> component then we don't have to
|
|
7026
7027
|
// bother streaming anything in
|
|
@@ -7030,9 +7031,16 @@ function StreamTransfer({
|
|
|
7030
7031
|
if (!context.renderMeta.streamCache) {
|
|
7031
7032
|
context.renderMeta.streamCache = {};
|
|
7032
7033
|
}
|
|
7033
|
-
let
|
|
7034
|
-
|
|
7035
|
-
|
|
7034
|
+
let streamCache = isAction ? context.renderMeta.streamCacheAction : context.renderMeta.streamCache;
|
|
7035
|
+
if (!streamCache) {
|
|
7036
|
+
if (isAction) {
|
|
7037
|
+
context.renderMeta.streamCacheAction = {};
|
|
7038
|
+
streamCache = context.renderMeta.streamCacheAction;
|
|
7039
|
+
} else {
|
|
7040
|
+
context.renderMeta.streamCache = {};
|
|
7041
|
+
streamCache = context.renderMeta.streamCache;
|
|
7042
|
+
}
|
|
7043
|
+
}
|
|
7036
7044
|
let promise = streamCache[identifier];
|
|
7037
7045
|
if (!promise) {
|
|
7038
7046
|
promise = streamCache[identifier] = reader.read().then(result => {
|
|
@@ -7058,13 +7066,13 @@ function StreamTransfer({
|
|
|
7058
7066
|
} = promise.result;
|
|
7059
7067
|
let scriptTag = value ? /*#__PURE__*/React.createElement("script", {
|
|
7060
7068
|
dangerouslySetInnerHTML: {
|
|
7061
|
-
__html: `window.__remixContext.streamController.enqueue(${escapeHtml(JSON.stringify(value))});`
|
|
7069
|
+
__html: `window.__remixContext.streamController${isAction ? "Action" : ""}.enqueue(${escapeHtml(JSON.stringify(value))});`
|
|
7062
7070
|
}
|
|
7063
7071
|
}) : null;
|
|
7064
7072
|
if (done) {
|
|
7065
7073
|
return /*#__PURE__*/React.createElement(React.Fragment, null, scriptTag, /*#__PURE__*/React.createElement("script", {
|
|
7066
7074
|
dangerouslySetInnerHTML: {
|
|
7067
|
-
__html: `window.__remixContext.streamController.close();`
|
|
7075
|
+
__html: `window.__remixContext.streamController${isAction ? "Action" : ""}.close();`
|
|
7068
7076
|
}
|
|
7069
7077
|
}));
|
|
7070
7078
|
} else {
|
|
@@ -7072,7 +7080,8 @@ function StreamTransfer({
|
|
|
7072
7080
|
context: context,
|
|
7073
7081
|
identifier: identifier + 1,
|
|
7074
7082
|
reader: reader,
|
|
7075
|
-
textDecoder: textDecoder
|
|
7083
|
+
textDecoder: textDecoder,
|
|
7084
|
+
isAction: isAction
|
|
7076
7085
|
})));
|
|
7077
7086
|
}
|
|
7078
7087
|
}
|
|
@@ -7207,6 +7216,15 @@ function singleFetchUrl(reqUrl) {
|
|
|
7207
7216
|
async function fetchAndDecode(url, init) {
|
|
7208
7217
|
let res = await fetch(url, init);
|
|
7209
7218
|
!res.body ? invariant(false, "No response body to decode") : void 0;
|
|
7219
|
+
if (res.headers.get("Content-Type")?.includes("text/x-component")) {
|
|
7220
|
+
!res.body ? invariant(false, "No response body to decode") : void 0;
|
|
7221
|
+
// @ts-expect-error - TODO: Figure out where this comes from
|
|
7222
|
+
let decoded = await window.createFromReadableStream(res.body);
|
|
7223
|
+
return {
|
|
7224
|
+
status: res.status,
|
|
7225
|
+
data: decoded
|
|
7226
|
+
};
|
|
7227
|
+
}
|
|
7210
7228
|
try {
|
|
7211
7229
|
let decoded = await decodeViaTurboStream(res.body, window);
|
|
7212
7230
|
return {
|
|
@@ -7716,7 +7734,8 @@ function Scripts(props) {
|
|
|
7716
7734
|
manifest,
|
|
7717
7735
|
serverHandoffString,
|
|
7718
7736
|
isSpaMode,
|
|
7719
|
-
renderMeta
|
|
7737
|
+
renderMeta,
|
|
7738
|
+
future
|
|
7720
7739
|
} = useRemixContext();
|
|
7721
7740
|
let {
|
|
7722
7741
|
router,
|
|
@@ -7739,6 +7758,9 @@ function Scripts(props) {
|
|
|
7739
7758
|
}, []);
|
|
7740
7759
|
let initialScripts = React.useMemo(() => {
|
|
7741
7760
|
let streamScript = "window.__remixContext.stream = new ReadableStream({" + "start(controller){" + "window.__remixContext.streamController = controller;" + "}" + "}).pipeThrough(new TextEncoderStream());";
|
|
7761
|
+
if (future.unstable_serverComponents && staticContext?.actionData) {
|
|
7762
|
+
streamScript += "window.__remixContext.streamAction = new ReadableStream({" + "start(controller){" + "window.__remixContext.streamControllerAction = controller;" + "}" + "}).pipeThrough(new TextEncoderStream());";
|
|
7763
|
+
}
|
|
7742
7764
|
let contextScript = staticContext ? `window.__remixContext = ${serverHandoffString};${streamScript}` : " ";
|
|
7743
7765
|
let routeModulesScript = !isStatic ? " " : `${manifest.hmr?.runtime ? `import ${JSON.stringify(manifest.hmr.runtime)};` : ""}import ${JSON.stringify(manifest.url)};
|
|
7744
7766
|
${matches.map((match, index) => `import * as route${index} from ${JSON.stringify(manifest.routes[match.route.id].module)};`).join("\n")}
|
|
@@ -9789,7 +9811,7 @@ function createServerRoutes(manifest, routeModules, future, isSpaMode, parentId
|
|
|
9789
9811
|
// has a loader/clientLoader, but it won't ever be called during the static
|
|
9790
9812
|
// render, so just give it a no-op function so we can render down to the
|
|
9791
9813
|
// proper fallback
|
|
9792
|
-
loader: route.hasLoader || route.hasClientLoader ?
|
|
9814
|
+
loader: route.hasLoader || route.hasClientLoader ? true : undefined
|
|
9793
9815
|
// We don't need action/shouldRevalidate on these routes since they're
|
|
9794
9816
|
// for a static render
|
|
9795
9817
|
};
|
|
@@ -10161,14 +10183,49 @@ function createHydratedRouter() {
|
|
|
10161
10183
|
// then only get past here and create the `router` one time
|
|
10162
10184
|
if (!ssrInfo.stateDecodingPromise) {
|
|
10163
10185
|
let stream = ssrInfo.context.stream;
|
|
10186
|
+
let streamAction = ssrInfo.context.streamAction;
|
|
10164
10187
|
!stream ? invariant(false, "No stream found for single fetch decoding") : void 0;
|
|
10165
10188
|
ssrInfo.context.stream = undefined;
|
|
10166
|
-
ssrInfo.
|
|
10167
|
-
ssrInfo.
|
|
10168
|
-
|
|
10169
|
-
|
|
10170
|
-
|
|
10171
|
-
|
|
10189
|
+
if (ssrInfo.context.future.unstable_serverComponents) {
|
|
10190
|
+
ssrInfo.stateDecodingPromise = Promise.all([
|
|
10191
|
+
// @ts-expect-error - TODO: Get this from somewhere else
|
|
10192
|
+
window.createFromReadableStream(stream), streamAction ?
|
|
10193
|
+
// @ts-expect-error - TODO: Get this from somewhere else
|
|
10194
|
+
window.createFromReadableStream(streamAction) : undefined]).then(([loaderPayload, actionPayload]) => {
|
|
10195
|
+
let state = {};
|
|
10196
|
+
for (let routeId of Object.keys(ssrInfo.routeModules)) {
|
|
10197
|
+
if ("error" in loaderPayload[routeId]) {
|
|
10198
|
+
state.errors = state.errors || {};
|
|
10199
|
+
state.errors[routeId] = loaderPayload[routeId].error;
|
|
10200
|
+
} else if ("data" in loaderPayload[routeId]) {
|
|
10201
|
+
state.loaderData = state.loaderData || {};
|
|
10202
|
+
state.loaderData[routeId] = loaderPayload[routeId].data;
|
|
10203
|
+
}
|
|
10204
|
+
}
|
|
10205
|
+
if (actionPayload) {
|
|
10206
|
+
// @ts-expect-error - TODO: Fix types and don't get it off the window directly
|
|
10207
|
+
const actionId = window.__remixContext.serverHandoffActionId;
|
|
10208
|
+
if ("error" in actionPayload) {
|
|
10209
|
+
state.errors = state.errors || {};
|
|
10210
|
+
state.errors[actionId] = actionPayload.error;
|
|
10211
|
+
} else if ("data" in actionPayload) {
|
|
10212
|
+
state.actionData = state.actionData || {};
|
|
10213
|
+
state.actionData[actionId] = actionPayload.data;
|
|
10214
|
+
}
|
|
10215
|
+
}
|
|
10216
|
+
ssrInfo.context.state = state;
|
|
10217
|
+
localSsrInfo.stateDecodingPromise.value = true;
|
|
10218
|
+
}).catch(e => {
|
|
10219
|
+
localSsrInfo.stateDecodingPromise.error = e;
|
|
10220
|
+
});
|
|
10221
|
+
} else {
|
|
10222
|
+
ssrInfo.stateDecodingPromise = decodeViaTurboStream(stream, window).then(value => {
|
|
10223
|
+
ssrInfo.context.state = value.value;
|
|
10224
|
+
localSsrInfo.stateDecodingPromise.value = true;
|
|
10225
|
+
}).catch(e => {
|
|
10226
|
+
localSsrInfo.stateDecodingPromise.error = e;
|
|
10227
|
+
});
|
|
10228
|
+
}
|
|
10172
10229
|
}
|
|
10173
10230
|
if (ssrInfo.stateDecodingPromise.error) {
|
|
10174
10231
|
throw ssrInfo.stateDecodingPromise.error;
|
|
@@ -10383,11 +10440,18 @@ function RemixServer({
|
|
|
10383
10440
|
router: router,
|
|
10384
10441
|
context: context.staticHandlerContext,
|
|
10385
10442
|
hydrate: false
|
|
10386
|
-
}))), context.
|
|
10443
|
+
}))), context.serverHandoffStreamAction ? /*#__PURE__*/React.createElement(React.Suspense, null, /*#__PURE__*/React.createElement(StreamTransfer, {
|
|
10444
|
+
context: context,
|
|
10445
|
+
identifier: 0,
|
|
10446
|
+
reader: context.serverHandoffStreamAction.getReader(),
|
|
10447
|
+
textDecoder: new TextDecoder(),
|
|
10448
|
+
isAction: true
|
|
10449
|
+
})) : null, context.serverHandoffStream ? /*#__PURE__*/React.createElement(React.Suspense, null, /*#__PURE__*/React.createElement(StreamTransfer, {
|
|
10387
10450
|
context: context,
|
|
10388
10451
|
identifier: 0,
|
|
10389
10452
|
reader: context.serverHandoffStream.getReader(),
|
|
10390
|
-
textDecoder: new TextDecoder()
|
|
10453
|
+
textDecoder: new TextDecoder(),
|
|
10454
|
+
isAction: false
|
|
10391
10455
|
})) : null);
|
|
10392
10456
|
}
|
|
10393
10457
|
|
|
@@ -10404,7 +10468,8 @@ function createRemixStub(routes, context = {}) {
|
|
|
10404
10468
|
remixContextRef.current = {
|
|
10405
10469
|
future: {
|
|
10406
10470
|
v3_fetcherPersist: future?.v3_fetcherPersist === true,
|
|
10407
|
-
v3_relativeSplatPath: future?.v3_relativeSplatPath === true
|
|
10471
|
+
v3_relativeSplatPath: future?.v3_relativeSplatPath === true,
|
|
10472
|
+
unstable_serverComponents: future?.unstable_serverComponents === true
|
|
10408
10473
|
},
|
|
10409
10474
|
manifest: {
|
|
10410
10475
|
routes: {},
|