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/index.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
|
*
|
|
@@ -6428,7 +6428,8 @@ function StreamTransfer(_ref) {
|
|
|
6428
6428
|
context,
|
|
6429
6429
|
identifier,
|
|
6430
6430
|
reader,
|
|
6431
|
-
textDecoder
|
|
6431
|
+
textDecoder,
|
|
6432
|
+
isAction
|
|
6432
6433
|
} = _ref;
|
|
6433
6434
|
// If the user didn't render the <Scripts> component then we don't have to
|
|
6434
6435
|
// bother streaming anything in
|
|
@@ -6438,9 +6439,16 @@ function StreamTransfer(_ref) {
|
|
|
6438
6439
|
if (!context.renderMeta.streamCache) {
|
|
6439
6440
|
context.renderMeta.streamCache = {};
|
|
6440
6441
|
}
|
|
6441
|
-
let
|
|
6442
|
-
|
|
6443
|
-
|
|
6442
|
+
let streamCache = isAction ? context.renderMeta.streamCacheAction : context.renderMeta.streamCache;
|
|
6443
|
+
if (!streamCache) {
|
|
6444
|
+
if (isAction) {
|
|
6445
|
+
context.renderMeta.streamCacheAction = {};
|
|
6446
|
+
streamCache = context.renderMeta.streamCacheAction;
|
|
6447
|
+
} else {
|
|
6448
|
+
context.renderMeta.streamCache = {};
|
|
6449
|
+
streamCache = context.renderMeta.streamCache;
|
|
6450
|
+
}
|
|
6451
|
+
}
|
|
6444
6452
|
let promise = streamCache[identifier];
|
|
6445
6453
|
if (!promise) {
|
|
6446
6454
|
promise = streamCache[identifier] = reader.read().then(result => {
|
|
@@ -6466,13 +6474,13 @@ function StreamTransfer(_ref) {
|
|
|
6466
6474
|
} = promise.result;
|
|
6467
6475
|
let scriptTag = value ? ( /*#__PURE__*/React.createElement("script", {
|
|
6468
6476
|
dangerouslySetInnerHTML: {
|
|
6469
|
-
__html: "window.__remixContext.streamController.enqueue(" + escapeHtml(JSON.stringify(value)) + ");"
|
|
6477
|
+
__html: "window.__remixContext.streamController" + (isAction ? "Action" : "") + ".enqueue(" + escapeHtml(JSON.stringify(value)) + ");"
|
|
6470
6478
|
}
|
|
6471
6479
|
})) : null;
|
|
6472
6480
|
if (done) {
|
|
6473
6481
|
return /*#__PURE__*/React.createElement(React.Fragment, null, scriptTag, /*#__PURE__*/React.createElement("script", {
|
|
6474
6482
|
dangerouslySetInnerHTML: {
|
|
6475
|
-
__html: "window.__remixContext.streamController.close();"
|
|
6483
|
+
__html: "window.__remixContext.streamController" + (isAction ? "Action" : "") + ".close();"
|
|
6476
6484
|
}
|
|
6477
6485
|
}));
|
|
6478
6486
|
} else {
|
|
@@ -6480,7 +6488,8 @@ function StreamTransfer(_ref) {
|
|
|
6480
6488
|
context: context,
|
|
6481
6489
|
identifier: identifier + 1,
|
|
6482
6490
|
reader: reader,
|
|
6483
|
-
textDecoder: textDecoder
|
|
6491
|
+
textDecoder: textDecoder,
|
|
6492
|
+
isAction: isAction
|
|
6484
6493
|
})));
|
|
6485
6494
|
}
|
|
6486
6495
|
}
|
|
@@ -6619,8 +6628,18 @@ function singleFetchUrl(reqUrl) {
|
|
|
6619
6628
|
return url;
|
|
6620
6629
|
}
|
|
6621
6630
|
async function fetchAndDecode(url, init) {
|
|
6631
|
+
var _res$headers$get;
|
|
6622
6632
|
let res = await fetch(url, init);
|
|
6623
6633
|
!res.body ? process.env.NODE_ENV !== "production" ? invariant(false, "No response body to decode") : invariant(false) : void 0;
|
|
6634
|
+
if ((_res$headers$get = res.headers.get("Content-Type")) != null && _res$headers$get.includes("text/x-component")) {
|
|
6635
|
+
!res.body ? process.env.NODE_ENV !== "production" ? invariant(false, "No response body to decode") : invariant(false) : void 0;
|
|
6636
|
+
// @ts-expect-error - TODO: Figure out where this comes from
|
|
6637
|
+
let decoded = await window.createFromReadableStream(res.body);
|
|
6638
|
+
return {
|
|
6639
|
+
status: res.status,
|
|
6640
|
+
data: decoded
|
|
6641
|
+
};
|
|
6642
|
+
}
|
|
6624
6643
|
try {
|
|
6625
6644
|
let decoded = await decodeViaTurboStream(res.body, window);
|
|
6626
6645
|
return {
|
|
@@ -7120,7 +7139,8 @@ function Scripts(props) {
|
|
|
7120
7139
|
manifest,
|
|
7121
7140
|
serverHandoffString,
|
|
7122
7141
|
isSpaMode,
|
|
7123
|
-
renderMeta
|
|
7142
|
+
renderMeta,
|
|
7143
|
+
future
|
|
7124
7144
|
} = useRemixContext();
|
|
7125
7145
|
let {
|
|
7126
7146
|
router,
|
|
@@ -7143,6 +7163,9 @@ function Scripts(props) {
|
|
|
7143
7163
|
let initialScripts = React.useMemo(() => {
|
|
7144
7164
|
var _manifest$hmr;
|
|
7145
7165
|
let streamScript = "window.__remixContext.stream = new ReadableStream({" + "start(controller){" + "window.__remixContext.streamController = controller;" + "}" + "}).pipeThrough(new TextEncoderStream());";
|
|
7166
|
+
if (future.unstable_serverComponents && staticContext != null && staticContext.actionData) {
|
|
7167
|
+
streamScript += "window.__remixContext.streamAction = new ReadableStream({" + "start(controller){" + "window.__remixContext.streamControllerAction = controller;" + "}" + "}).pipeThrough(new TextEncoderStream());";
|
|
7168
|
+
}
|
|
7146
7169
|
let contextScript = staticContext ? "window.__remixContext = " + serverHandoffString + ";" + streamScript : " ";
|
|
7147
7170
|
let routeModulesScript = !isStatic ? " " : ((_manifest$hmr = manifest.hmr) != null && _manifest$hmr.runtime ? "import " + JSON.stringify(manifest.hmr.runtime) + ";" : "") + "import " + JSON.stringify(manifest.url) + ";\n" + matches.map((match, index) => "import * as route" + index + " from " + JSON.stringify(manifest.routes[match.route.id].module) + ";").join("\n") + "\nwindow.__remixRouteModules = {" + matches.map((match, index) => JSON.stringify(match.route.id) + ":route" + index).join(",") + "};\n\nimport(" + JSON.stringify(manifest.entry.module) + ");";
|
|
7148
7171
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("script", _extends({}, props, {
|
|
@@ -9082,7 +9105,7 @@ function createServerRoutes(manifest, routeModules, future, isSpaMode, parentId,
|
|
|
9082
9105
|
// has a loader/clientLoader, but it won't ever be called during the static
|
|
9083
9106
|
// render, so just give it a no-op function so we can render down to the
|
|
9084
9107
|
// proper fallback
|
|
9085
|
-
loader: route.hasLoader || route.hasClientLoader ?
|
|
9108
|
+
loader: route.hasLoader || route.hasClientLoader ? true : undefined
|
|
9086
9109
|
// We don't need action/shouldRevalidate on these routes since they're
|
|
9087
9110
|
// for a static render
|
|
9088
9111
|
});
|
|
@@ -9444,14 +9467,50 @@ function createHydratedRouter() {
|
|
|
9444
9467
|
// then only get past here and create the `router` one time
|
|
9445
9468
|
if (!ssrInfo.stateDecodingPromise) {
|
|
9446
9469
|
let stream = ssrInfo.context.stream;
|
|
9470
|
+
let streamAction = ssrInfo.context.streamAction;
|
|
9447
9471
|
!stream ? process.env.NODE_ENV !== "production" ? invariant(false, "No stream found for single fetch decoding") : invariant(false) : void 0;
|
|
9448
9472
|
ssrInfo.context.stream = undefined;
|
|
9449
|
-
ssrInfo.
|
|
9450
|
-
ssrInfo.
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9454
|
-
|
|
9473
|
+
if (ssrInfo.context.future.unstable_serverComponents) {
|
|
9474
|
+
ssrInfo.stateDecodingPromise = Promise.all([
|
|
9475
|
+
// @ts-expect-error - TODO: Get this from somewhere else
|
|
9476
|
+
window.createFromReadableStream(stream), streamAction ?
|
|
9477
|
+
// @ts-expect-error - TODO: Get this from somewhere else
|
|
9478
|
+
window.createFromReadableStream(streamAction) : undefined]).then(_ref2 => {
|
|
9479
|
+
let [loaderPayload, actionPayload] = _ref2;
|
|
9480
|
+
let state = {};
|
|
9481
|
+
for (let routeId of Object.keys(ssrInfo.routeModules)) {
|
|
9482
|
+
if ("error" in loaderPayload[routeId]) {
|
|
9483
|
+
state.errors = state.errors || {};
|
|
9484
|
+
state.errors[routeId] = loaderPayload[routeId].error;
|
|
9485
|
+
} else if ("data" in loaderPayload[routeId]) {
|
|
9486
|
+
state.loaderData = state.loaderData || {};
|
|
9487
|
+
state.loaderData[routeId] = loaderPayload[routeId].data;
|
|
9488
|
+
}
|
|
9489
|
+
}
|
|
9490
|
+
if (actionPayload) {
|
|
9491
|
+
// @ts-expect-error - TODO: Fix types and don't get it off the window directly
|
|
9492
|
+
const actionId = window.__remixContext.serverHandoffActionId;
|
|
9493
|
+
if ("error" in actionPayload) {
|
|
9494
|
+
state.errors = state.errors || {};
|
|
9495
|
+
state.errors[actionId] = actionPayload.error;
|
|
9496
|
+
} else if ("data" in actionPayload) {
|
|
9497
|
+
state.actionData = state.actionData || {};
|
|
9498
|
+
state.actionData[actionId] = actionPayload.data;
|
|
9499
|
+
}
|
|
9500
|
+
}
|
|
9501
|
+
ssrInfo.context.state = state;
|
|
9502
|
+
localSsrInfo.stateDecodingPromise.value = true;
|
|
9503
|
+
}).catch(e => {
|
|
9504
|
+
localSsrInfo.stateDecodingPromise.error = e;
|
|
9505
|
+
});
|
|
9506
|
+
} else {
|
|
9507
|
+
ssrInfo.stateDecodingPromise = decodeViaTurboStream(stream, window).then(value => {
|
|
9508
|
+
ssrInfo.context.state = value.value;
|
|
9509
|
+
localSsrInfo.stateDecodingPromise.value = true;
|
|
9510
|
+
}).catch(e => {
|
|
9511
|
+
localSsrInfo.stateDecodingPromise.error = e;
|
|
9512
|
+
});
|
|
9513
|
+
}
|
|
9455
9514
|
}
|
|
9456
9515
|
if (ssrInfo.stateDecodingPromise.error) {
|
|
9457
9516
|
throw ssrInfo.stateDecodingPromise.error;
|
|
@@ -9656,11 +9715,18 @@ function RemixServer(_ref) {
|
|
|
9656
9715
|
router: router,
|
|
9657
9716
|
context: context.staticHandlerContext,
|
|
9658
9717
|
hydrate: false
|
|
9659
|
-
}))), context.
|
|
9718
|
+
}))), context.serverHandoffStreamAction ? ( /*#__PURE__*/React.createElement(React.Suspense, null, /*#__PURE__*/React.createElement(StreamTransfer, {
|
|
9719
|
+
context: context,
|
|
9720
|
+
identifier: 0,
|
|
9721
|
+
reader: context.serverHandoffStreamAction.getReader(),
|
|
9722
|
+
textDecoder: new TextDecoder(),
|
|
9723
|
+
isAction: true
|
|
9724
|
+
}))) : null, context.serverHandoffStream ? ( /*#__PURE__*/React.createElement(React.Suspense, null, /*#__PURE__*/React.createElement(StreamTransfer, {
|
|
9660
9725
|
context: context,
|
|
9661
9726
|
identifier: 0,
|
|
9662
9727
|
reader: context.serverHandoffStream.getReader(),
|
|
9663
|
-
textDecoder: new TextDecoder()
|
|
9728
|
+
textDecoder: new TextDecoder(),
|
|
9729
|
+
isAction: false
|
|
9664
9730
|
}))) : null);
|
|
9665
9731
|
}
|
|
9666
9732
|
|
|
@@ -9681,7 +9747,8 @@ function createRemixStub(routes, context) {
|
|
|
9681
9747
|
remixContextRef.current = {
|
|
9682
9748
|
future: {
|
|
9683
9749
|
v3_fetcherPersist: (future == null ? void 0 : future.v3_fetcherPersist) === true,
|
|
9684
|
-
v3_relativeSplatPath: (future == null ? void 0 : future.v3_relativeSplatPath) === true
|
|
9750
|
+
v3_relativeSplatPath: (future == null ? void 0 : future.v3_relativeSplatPath) === true,
|
|
9751
|
+
unstable_serverComponents: (future == null ? void 0 : future.unstable_serverComponents) === true
|
|
9685
9752
|
},
|
|
9686
9753
|
manifest: {
|
|
9687
9754
|
routes: {},
|