react-router 0.0.0-experimental-e145538f2 → 0.0.0-experimental-10a6fd0e1

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v0.0.0-experimental-e145538f2
2
+ * React Router v0.0.0-experimental-10a6fd0e1
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -6670,7 +6670,6 @@ function StreamTransfer(_ref) {
6670
6670
  identifier,
6671
6671
  reader,
6672
6672
  textDecoder,
6673
- isAction,
6674
6673
  nonce
6675
6674
  } = _ref;
6676
6675
  // If the user didn't render the <Scripts> component then we don't have to
@@ -6681,16 +6680,9 @@ function StreamTransfer(_ref) {
6681
6680
  if (!context.renderMeta.streamCache) {
6682
6681
  context.renderMeta.streamCache = {};
6683
6682
  }
6684
- let streamCache = isAction ? context.renderMeta.streamCacheAction : context.renderMeta.streamCache;
6685
- if (!streamCache) {
6686
- if (isAction) {
6687
- context.renderMeta.streamCacheAction = {};
6688
- streamCache = context.renderMeta.streamCacheAction;
6689
- } else {
6690
- context.renderMeta.streamCache = {};
6691
- streamCache = context.renderMeta.streamCache;
6692
- }
6693
- }
6683
+ let {
6684
+ streamCache
6685
+ } = context.renderMeta;
6694
6686
  let promise = streamCache[identifier];
6695
6687
  if (!promise) {
6696
6688
  promise = streamCache[identifier] = reader.read().then(result => {
@@ -6717,14 +6709,14 @@ function StreamTransfer(_ref) {
6717
6709
  let scriptTag = value ? ( /*#__PURE__*/React.createElement("script", {
6718
6710
  nonce: nonce,
6719
6711
  dangerouslySetInnerHTML: {
6720
- __html: "window.__remixContext.streamController" + (isAction ? "Action" : "") + ".enqueue(" + escapeHtml(JSON.stringify(value)) + ");"
6712
+ __html: "window.__remixContext.streamController.enqueue(" + escapeHtml(JSON.stringify(value)) + ");"
6721
6713
  }
6722
6714
  })) : null;
6723
6715
  if (done) {
6724
6716
  return /*#__PURE__*/React.createElement(React.Fragment, null, scriptTag, /*#__PURE__*/React.createElement("script", {
6725
6717
  nonce: nonce,
6726
6718
  dangerouslySetInnerHTML: {
6727
- __html: "window.__remixContext.streamController" + (isAction ? "Action" : "") + ".close();"
6719
+ __html: "window.__remixContext.streamController.close();"
6728
6720
  }
6729
6721
  }));
6730
6722
  } else {
@@ -6733,7 +6725,6 @@ function StreamTransfer(_ref) {
6733
6725
  identifier: identifier + 1,
6734
6726
  reader: reader,
6735
6727
  textDecoder: textDecoder,
6736
- isAction: isAction,
6737
6728
  nonce: nonce
6738
6729
  })));
6739
6730
  }
@@ -6873,18 +6864,8 @@ function singleFetchUrl(reqUrl) {
6873
6864
  return url;
6874
6865
  }
6875
6866
  async function fetchAndDecode(url, init) {
6876
- var _res$headers$get;
6877
6867
  let res = await fetch(url, init);
6878
6868
  !res.body ? process.env.NODE_ENV !== "production" ? invariant(false, "No response body to decode") : invariant(false) : void 0;
6879
- if ((_res$headers$get = res.headers.get("Content-Type")) != null && _res$headers$get.includes("text/x-component")) {
6880
- !res.body ? process.env.NODE_ENV !== "production" ? invariant(false, "No response body to decode") : invariant(false) : void 0;
6881
- // @ts-expect-error - TODO: Figure out where this comes from
6882
- let decoded = await window.createFromReadableStream(res.body);
6883
- return {
6884
- status: res.status,
6885
- data: decoded
6886
- };
6887
- }
6888
6869
  try {
6889
6870
  let decoded = await decodeViaTurboStream(res.body, window);
6890
6871
  return {
@@ -7396,8 +7377,7 @@ function Scripts(props) {
7396
7377
  manifest,
7397
7378
  serverHandoffString,
7398
7379
  isSpaMode,
7399
- renderMeta,
7400
- future
7380
+ renderMeta
7401
7381
  } = useRemixContext();
7402
7382
  let {
7403
7383
  router,
@@ -7420,9 +7400,6 @@ function Scripts(props) {
7420
7400
  let initialScripts = React.useMemo(() => {
7421
7401
  var _manifest$hmr;
7422
7402
  let streamScript = "window.__remixContext.stream = new ReadableStream({" + "start(controller){" + "window.__remixContext.streamController = controller;" + "}" + "}).pipeThrough(new TextEncoderStream());";
7423
- if (future.unstable_serverComponents && staticContext != null && staticContext.actionData) {
7424
- streamScript += "window.__remixContext.streamAction = new ReadableStream({" + "start(controller){" + "window.__remixContext.streamControllerAction = controller;" + "}" + "}).pipeThrough(new TextEncoderStream());";
7425
- }
7426
7403
  let contextScript = staticContext ? "window.__remixContext = " + serverHandoffString + ";" + streamScript : " ";
7427
7404
  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) + ");";
7428
7405
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("script", _extends({}, props, {
@@ -9518,7 +9495,7 @@ function createServerRoutes(manifest, routeModules, future, isSpaMode, parentId,
9518
9495
  // has a loader/clientLoader, but it won't ever be called during the static
9519
9496
  // render, so just give it a no-op function so we can render down to the
9520
9497
  // proper fallback
9521
- loader: route.hasLoader || route.hasClientLoader ? true : undefined
9498
+ loader: route.hasLoader || route.hasClientLoader ? () => null : undefined
9522
9499
  // We don't need action/shouldRevalidate on these routes since they're
9523
9500
  // for a static render
9524
9501
  });
@@ -9787,85 +9764,7 @@ function initSsrInfo() {
9787
9764
  };
9788
9765
  }
9789
9766
  }
9790
- let hmrInfo = null;
9791
- if (import.meta &&
9792
- // @ts-expect-error
9793
- import.meta.hot && typeof window !== "undefined" && window.__remixManifest) {
9794
- let resolve;
9795
- let routerReadyPromise = new Promise(r => {
9796
- resolve = r;
9797
- }).catch(() => {
9798
- // This is a noop catch handler to avoid unhandled promise rejection warnings
9799
- // in the console. The promise is never rejected.
9800
- return undefined;
9801
- });
9802
- hmrInfo = {
9803
- abortController: undefined,
9804
- routerReadyResolve: resolve,
9805
- // There's a race condition with HMR where the remix:manifest is signaled before
9806
- // the router is assigned in the RemixBrowser component. This promise gates the
9807
- // HMR handler until the router is ready
9808
- routerReadyPromise
9809
- };
9810
- // @ts-expect-error
9811
- import.meta.hot.accept("remix:manifest", async _ref => {
9812
- var _hmrInfo$abortControl;
9813
- let {
9814
- assetsManifest,
9815
- needsRevalidation
9816
- } = _ref;
9817
- let router = await hmrInfo.routerReadyPromise;
9818
- // This should never happen, but just in case...
9819
- if (!router || !ssrInfo || !hmrInfo) {
9820
- console.error("Failed to accept HMR update because the router/ssrInfo was not ready.");
9821
- return;
9822
- }
9823
- let routeIds = [...new Set(router.state.matches.map(m => m.route.id).concat(Object.keys(ssrInfo.routeModules)))];
9824
- (_hmrInfo$abortControl = hmrInfo.abortController) == null ? void 0 : _hmrInfo$abortControl.abort();
9825
- hmrInfo.abortController = new AbortController();
9826
- let signal = hmrInfo.abortController.signal;
9827
- // Load new route modules that we've seen.
9828
- let newRouteModules = Object.assign({}, ssrInfo.routeModules, Object.fromEntries((await Promise.all(routeIds.map(async id => {
9829
- var _assetsManifest$hmr, _ssrInfo$routeModules, _ssrInfo$routeModules2, _ssrInfo$routeModules3;
9830
- if (!assetsManifest.routes[id]) {
9831
- return null;
9832
- }
9833
- let imported = await import(assetsManifest.routes[id].module + ("?t=" + ((_assetsManifest$hmr = assetsManifest.hmr) == null ? void 0 : _assetsManifest$hmr.timestamp)));
9834
- !ssrInfo ? process.env.NODE_ENV !== "production" ? invariant(false, "ssrInfo unavailable for HMR update") : invariant(false) : void 0;
9835
- return [id, _extends({}, imported, {
9836
- // react-refresh takes care of updating these in-place,
9837
- // if we don't preserve existing values we'll loose state.
9838
- default: imported.default ? ((_ssrInfo$routeModules = ssrInfo.routeModules[id]) == null ? void 0 : _ssrInfo$routeModules.default) || imported.default : imported.default,
9839
- ErrorBoundary: imported.ErrorBoundary ? ((_ssrInfo$routeModules2 = ssrInfo.routeModules[id]) == null ? void 0 : _ssrInfo$routeModules2.ErrorBoundary) || imported.ErrorBoundary : imported.ErrorBoundary,
9840
- HydrateFallback: imported.HydrateFallback ? ((_ssrInfo$routeModules3 = ssrInfo.routeModules[id]) == null ? void 0 : _ssrInfo$routeModules3.HydrateFallback) || imported.HydrateFallback : imported.HydrateFallback
9841
- })];
9842
- }))).filter(Boolean)));
9843
- Object.assign(ssrInfo.routeModules, newRouteModules);
9844
- // Create new routes
9845
- let routes = createClientRoutesWithHMRRevalidationOptOut(needsRevalidation, assetsManifest.routes, ssrInfo.routeModules, ssrInfo.context.state, ssrInfo.context.future, ssrInfo.context.isSpaMode);
9846
- // This is temporary API and will be more granular before release
9847
- router._internalSetRoutes(routes);
9848
- // Wait for router to be idle before updating the manifest and route modules
9849
- // and triggering a react-refresh
9850
- let unsub = router.subscribe(state => {
9851
- if (state.revalidation === "idle") {
9852
- unsub();
9853
- // Abort if a new update comes in while we're waiting for the
9854
- // router to be idle.
9855
- if (signal.aborted) return;
9856
- // Ensure RouterProvider setState has flushed before re-rendering
9857
- setTimeout(() => {
9858
- Object.assign(ssrInfo.manifest, assetsManifest);
9859
- window.$RefreshRuntime$.performReactRefresh();
9860
- }, 1);
9861
- }
9862
- });
9863
- window.__remixRevalidation = (window.__remixRevalidation || 0) + 1;
9864
- router.revalidate();
9865
- });
9866
- }
9867
9767
  function createHydratedRouter() {
9868
- var _hmrInfo;
9869
9768
  initSsrInfo();
9870
9769
  if (!ssrInfo) {
9871
9770
  throw new Error("You must be using the SSR features of React Router in order to skip " + "passing a `router` prop to `<RouterProvider>`");
@@ -9880,50 +9779,14 @@ function createHydratedRouter() {
9880
9779
  // then only get past here and create the `router` one time
9881
9780
  if (!ssrInfo.stateDecodingPromise) {
9882
9781
  let stream = ssrInfo.context.stream;
9883
- let streamAction = ssrInfo.context.streamAction;
9884
9782
  !stream ? process.env.NODE_ENV !== "production" ? invariant(false, "No stream found for single fetch decoding") : invariant(false) : void 0;
9885
9783
  ssrInfo.context.stream = undefined;
9886
- if (ssrInfo.context.future.unstable_serverComponents) {
9887
- ssrInfo.stateDecodingPromise = Promise.all([
9888
- // @ts-expect-error - TODO: Get this from somewhere else
9889
- window.createFromReadableStream(stream), streamAction ?
9890
- // @ts-expect-error - TODO: Get this from somewhere else
9891
- window.createFromReadableStream(streamAction) : undefined]).then(_ref2 => {
9892
- let [loaderPayload, actionPayload] = _ref2;
9893
- let state = {};
9894
- for (let routeId of Object.keys(ssrInfo.routeModules)) {
9895
- if ("error" in loaderPayload[routeId]) {
9896
- state.errors = state.errors || {};
9897
- state.errors[routeId] = loaderPayload[routeId].error;
9898
- } else if ("data" in loaderPayload[routeId]) {
9899
- state.loaderData = state.loaderData || {};
9900
- state.loaderData[routeId] = loaderPayload[routeId].data;
9901
- }
9902
- }
9903
- if (actionPayload) {
9904
- // @ts-expect-error - TODO: Fix types and don't get it off the window directly
9905
- const actionId = window.__remixContext.serverHandoffActionId;
9906
- if ("error" in actionPayload) {
9907
- state.errors = state.errors || {};
9908
- state.errors[actionId] = actionPayload.error;
9909
- } else if ("data" in actionPayload) {
9910
- state.actionData = state.actionData || {};
9911
- state.actionData[actionId] = actionPayload.data;
9912
- }
9913
- }
9914
- ssrInfo.context.state = state;
9915
- localSsrInfo.stateDecodingPromise.value = true;
9916
- }).catch(e => {
9917
- localSsrInfo.stateDecodingPromise.error = e;
9918
- });
9919
- } else {
9920
- ssrInfo.stateDecodingPromise = decodeViaTurboStream(stream, window).then(value => {
9921
- ssrInfo.context.state = value.value;
9922
- localSsrInfo.stateDecodingPromise.value = true;
9923
- }).catch(e => {
9924
- localSsrInfo.stateDecodingPromise.error = e;
9925
- });
9926
- }
9784
+ ssrInfo.stateDecodingPromise = decodeViaTurboStream(stream, window).then(value => {
9785
+ ssrInfo.context.state = value.value;
9786
+ localSsrInfo.stateDecodingPromise.value = true;
9787
+ }).catch(e => {
9788
+ localSsrInfo.stateDecodingPromise.error = e;
9789
+ });
9927
9790
  }
9928
9791
  if (ssrInfo.stateDecodingPromise.error) {
9929
9792
  throw ssrInfo.stateDecodingPromise.error;
@@ -10000,8 +9863,6 @@ function createHydratedRouter() {
10000
9863
  // @ts-ignore
10001
9864
  router.createRoutesForHMR = createClientRoutesWithHMRRevalidationOptOut;
10002
9865
  window.__remixRouter = router;
10003
- // Notify that the router is ready for HMR
10004
- (_hmrInfo = hmrInfo) == null ? void 0 : _hmrInfo.routerReadyResolve(router);
10005
9866
  return router;
10006
9867
  }
10007
9868
  /**
@@ -10134,19 +9995,11 @@ function RemixServer(_ref) {
10134
9995
  router: router,
10135
9996
  context: context.staticHandlerContext,
10136
9997
  hydrate: false
10137
- }))), context.serverHandoffStreamAction ? ( /*#__PURE__*/React.createElement(React.Suspense, null, /*#__PURE__*/React.createElement(StreamTransfer, {
10138
- context: context,
10139
- identifier: 0,
10140
- reader: context.serverHandoffStreamAction.getReader(),
10141
- textDecoder: new TextDecoder(),
10142
- isAction: true,
10143
- nonce: nonce
10144
- }))) : null, context.serverHandoffStream ? ( /*#__PURE__*/React.createElement(React.Suspense, null, /*#__PURE__*/React.createElement(StreamTransfer, {
9998
+ }))), context.serverHandoffStream ? ( /*#__PURE__*/React.createElement(React.Suspense, null, /*#__PURE__*/React.createElement(StreamTransfer, {
10145
9999
  context: context,
10146
10000
  identifier: 0,
10147
10001
  reader: context.serverHandoffStream.getReader(),
10148
10002
  textDecoder: new TextDecoder(),
10149
- isAction: false,
10150
10003
  nonce: nonce
10151
10004
  }))) : null);
10152
10005
  }
@@ -10171,8 +10024,7 @@ function createRemixStub(routes, context) {
10171
10024
  remixContextRef.current = {
10172
10025
  future: {
10173
10026
  v3_fetcherPersist: (future == null ? void 0 : future.v3_fetcherPersist) === true,
10174
- v3_relativeSplatPath: (future == null ? void 0 : future.v3_relativeSplatPath) === true,
10175
- unstable_serverComponents: (future == null ? void 0 : future.unstable_serverComponents) === true
10027
+ v3_relativeSplatPath: (future == null ? void 0 : future.v3_relativeSplatPath) === true
10176
10028
  },
10177
10029
  manifest: {
10178
10030
  routes: {},