@modern-js/runtime 2.63.6 → 2.63.7

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.
@@ -24,13 +24,12 @@ __export(hydrate_exports, {
24
24
  module.exports = __toCommonJS(hydrate_exports);
25
25
  var import_jsx_runtime = require("react/jsx-runtime");
26
26
  var import_component = require("@loadable/component");
27
- var import_url = require("@modern-js/runtime-utils/url");
28
27
  var import_constants = require("../constants");
29
28
  var import_wrapper = require("../react/wrapper");
30
29
  var import_withCallback = require("./withCallback");
31
30
  const isReact18 = () => process.env.IS_REACT18 === "true";
32
31
  function hydrateRoot(App, context, ModernRender, ModernHydrate) {
33
- var _ssrContext_request, _window__SSR_DATA, _window, _window__SSR_DATA1, _window1;
32
+ var _window__SSR_DATA, _window, _window__SSR_DATA1, _window1;
34
33
  const hydrateContext = {
35
34
  ...context,
36
35
  get routes() {
@@ -38,14 +37,6 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
38
37
  },
39
38
  _hydration: true
40
39
  };
41
- const { ssrContext } = hydrateContext;
42
- const currentPathname = (0, import_url.normalizePathname)(window.location.pathname);
43
- const initialPathname = (ssrContext === null || ssrContext === void 0 ? void 0 : (_ssrContext_request = ssrContext.request) === null || _ssrContext_request === void 0 ? void 0 : _ssrContext_request.pathname) && (0, import_url.normalizePathname)(ssrContext.request.pathname);
44
- if (initialPathname && initialPathname !== currentPathname && context.router) {
45
- const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
46
- console.error(errorMsg);
47
- window.location.reload();
48
- }
49
40
  const callback = () => {
50
41
  delete hydrateContext._hydration;
51
42
  };
@@ -49,9 +49,9 @@ const createReadableStreamFromElement = async (request, rootElement, options) =>
49
49
  const onReady = isbot || forceStream2String ? "onAllReady" : "onShellReady";
50
50
  const sheet = new import_styled_components.ServerStyleSheet();
51
51
  const chunkVec = [];
52
- const root = forceStream2String ? sheet.collectStyles(rootElement) : rootElement;
52
+ const root = sheet.collectStyles(rootElement);
53
53
  return new Promise((resolve) => {
54
- const { pipe } = renderToPipeableStream(root, {
54
+ const { pipe: reactStreamingPipe } = renderToPipeableStream(root, {
55
55
  nonce: config.nonce,
56
56
  [onReady]() {
57
57
  var _options_onReady;
@@ -92,7 +92,10 @@ const createReadableStreamFromElement = async (request, rootElement, options) =>
92
92
  });
93
93
  const stream = (0, import_node.createReadableStreamFromReadable)(body);
94
94
  resolve(stream);
95
- pipe(body);
95
+ const passThrough = new import_stream.PassThrough();
96
+ const styledStream = sheet.interleaveWithNodeStream(passThrough);
97
+ reactStreamingPipe(passThrough);
98
+ styledStream.pipe(body);
96
99
  });
97
100
  },
98
101
  onShellError(error) {
@@ -27,6 +27,7 @@ module.exports = __toCommonJS(plugin_exports);
27
27
  var import_jsx_runtime = require("react/jsx-runtime");
28
28
  var import_merge = require("@modern-js/runtime-utils/merge");
29
29
  var import_router = require("@modern-js/runtime-utils/router");
30
+ var import_url = require("@modern-js/runtime-utils/url");
30
31
  var import_react = require("react");
31
32
  var import_core = require("../../core");
32
33
  var import_context = require("../../core/context");
@@ -55,6 +56,17 @@ const routerPlugin = (userConfig = {}) => {
55
56
  let routes = [];
56
57
  return {
57
58
  beforeRender(context) {
59
+ if (window._SSR_DATA && userConfig.unstable_reloadOnURLMismatch) {
60
+ var _ssrContext_request;
61
+ const { ssrContext } = context;
62
+ const currentPathname = (0, import_url.normalizePathname)(window.location.pathname);
63
+ const initialPathname = (ssrContext === null || ssrContext === void 0 ? void 0 : (_ssrContext_request = ssrContext.request) === null || _ssrContext_request === void 0 ? void 0 : _ssrContext_request.pathname) && (0, import_url.normalizePathname)(ssrContext.request.pathname);
64
+ if (initialPathname && initialPathname !== currentPathname) {
65
+ const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
66
+ console.error(errorMsg);
67
+ window.location.reload();
68
+ }
69
+ }
58
70
  context.router = {
59
71
  useMatches: import_router.useMatches,
60
72
  useLocation: import_router.useLocation,
@@ -109,10 +109,12 @@ const routerPlugin = (userConfig = {}) => {
109
109
  if (routerContext instanceof Response) {
110
110
  return interrupt(routerContext);
111
111
  }
112
- if (routerContext.statusCode >= 500 && routerContext.statusCode < 600 && // TODO: if loaderFailureMode is not 'errroBoundary', error log will not be printed.
113
- loaderFailureMode === "clientRender") {
112
+ const errors = Object.values(routerContext.errors || {});
113
+ if (
114
+ // TODO: if loaderFailureMode is not 'errroBoundary', error log will not be printed.
115
+ errors.length > 0 && loaderFailureMode === "clientRender"
116
+ ) {
114
117
  routerContext.statusCode = 200;
115
- const errors = Object.values(routerContext.errors);
116
118
  throw errors[0];
117
119
  }
118
120
  const router = (0, import_router.createStaticRouter)(routes, routerContext);
@@ -2,7 +2,6 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
2
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  import { loadableReady } from "@loadable/component";
5
- import { normalizePathname } from "@modern-js/runtime-utils/url";
6
5
  import { RenderLevel } from "../constants";
7
6
  import { wrapRuntimeContextProvider } from "../react/wrapper";
8
7
  import { WithCallback } from "./withCallback";
@@ -10,21 +9,13 @@ var isReact18 = function() {
10
9
  return process.env.IS_REACT18 === "true";
11
10
  };
12
11
  function hydrateRoot(App, context, ModernRender, ModernHydrate) {
13
- var _ssrContext_request, _window__SSR_DATA, _window, _window__SSR_DATA1, _window1;
12
+ var _window__SSR_DATA, _window, _window__SSR_DATA1, _window1;
14
13
  var hydrateContext = _object_spread_props(_object_spread({}, context), {
15
14
  get routes() {
16
15
  return context.routes;
17
16
  },
18
17
  _hydration: true
19
18
  });
20
- var ssrContext = hydrateContext.ssrContext;
21
- var currentPathname = normalizePathname(window.location.pathname);
22
- var initialPathname = (ssrContext === null || ssrContext === void 0 ? void 0 : (_ssrContext_request = ssrContext.request) === null || _ssrContext_request === void 0 ? void 0 : _ssrContext_request.pathname) && normalizePathname(ssrContext.request.pathname);
23
- if (initialPathname && initialPathname !== currentPathname && context.router) {
24
- var errorMsg = "The initial URL ".concat(initialPathname, " and the URL ").concat(currentPathname, " to be hydrated do not match, reload.");
25
- console.error(errorMsg);
26
- window.location.reload();
27
- }
28
19
  var callback = function() {
29
20
  delete hydrateContext._hydration;
30
21
  };
@@ -2,7 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
3
3
  import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
- import { Transform } from "stream";
5
+ import { PassThrough, Transform } from "stream";
6
6
  import { createReadableStreamFromReadable } from "@modern-js/runtime-utils/node";
7
7
  import checkIsBot from "isbot";
8
8
  import { ServerStyleSheet } from "styled-components";
@@ -30,12 +30,12 @@ var createReadableStreamFromElement = function() {
30
30
  onReady = isbot || forceStream2String ? "onAllReady" : "onShellReady";
31
31
  sheet = new ServerStyleSheet();
32
32
  chunkVec = [];
33
- root = forceStream2String ? sheet.collectStyles(rootElement) : rootElement;
33
+ root = sheet.collectStyles(rootElement);
34
34
  return [
35
35
  2,
36
36
  new Promise(function(resolve) {
37
37
  var _obj;
38
- var pipe = renderToPipeableStream(root, (_obj = {
38
+ var _renderToPipeableStream = renderToPipeableStream(root, (_obj = {
39
39
  nonce: config.nonce
40
40
  }, _define_property(_obj, onReady, function() {
41
41
  var _options_onReady;
@@ -77,7 +77,10 @@ var createReadableStreamFromElement = function() {
77
77
  });
78
78
  var stream = createReadableStreamFromReadable(body);
79
79
  resolve(stream);
80
- pipe(body);
80
+ var passThrough = new PassThrough();
81
+ var styledStream = sheet.interleaveWithNodeStream(passThrough);
82
+ reactStreamingPipe(passThrough);
83
+ styledStream.pipe(body);
81
84
  });
82
85
  }), _define_property(_obj, "onShellError", function onShellError(error) {
83
86
  renderLevel = RenderLevel.CLIENT_RENDER;
@@ -100,7 +103,7 @@ var createReadableStreamFromElement = function() {
100
103
  var _options_onError;
101
104
  renderLevel = RenderLevel.CLIENT_RENDER;
102
105
  options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, error);
103
- }), _obj)).pipe;
106
+ }), _obj)), reactStreamingPipe = _renderToPipeableStream.pipe;
104
107
  })
105
108
  ];
106
109
  }
@@ -4,6 +4,7 @@ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
4
4
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
5
5
  import { merge } from "@modern-js/runtime-utils/merge";
6
6
  import { RouterProvider, createBrowserRouter, createHashRouter, createRoutesFromElements, useHref, useLocation, useMatches } from "@modern-js/runtime-utils/router";
7
+ import { normalizePathname } from "@modern-js/runtime-utils/url";
7
8
  import { useContext, useMemo } from "react";
8
9
  import { RuntimeReactContext } from "../../core";
9
10
  import { getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
@@ -33,6 +34,17 @@ var routerPlugin = function() {
33
34
  var routes = [];
34
35
  return {
35
36
  beforeRender: function beforeRender(context) {
37
+ if (window._SSR_DATA && userConfig.unstable_reloadOnURLMismatch) {
38
+ var _ssrContext_request;
39
+ var ssrContext = context.ssrContext;
40
+ var currentPathname = normalizePathname(window.location.pathname);
41
+ var initialPathname = (ssrContext === null || ssrContext === void 0 ? void 0 : (_ssrContext_request = ssrContext.request) === null || _ssrContext_request === void 0 ? void 0 : _ssrContext_request.pathname) && normalizePathname(ssrContext.request.pathname);
42
+ if (initialPathname && initialPathname !== currentPathname) {
43
+ var errorMsg = "The initial URL ".concat(initialPathname, " and the URL ").concat(currentPathname, " to be hydrated do not match, reload.");
44
+ console.error(errorMsg);
45
+ window.location.reload();
46
+ }
47
+ }
36
48
  context.router = {
37
49
  useMatches,
38
50
  useLocation,
@@ -98,10 +98,12 @@ var routerPlugin = function() {
98
98
  interrupt(routerContext)
99
99
  ];
100
100
  }
101
- if (routerContext.statusCode >= 500 && routerContext.statusCode < 600 && // TODO: if loaderFailureMode is not 'errroBoundary', error log will not be printed.
102
- loaderFailureMode === "clientRender") {
101
+ errors = Object.values(routerContext.errors || {});
102
+ if (
103
+ // TODO: if loaderFailureMode is not 'errroBoundary', error log will not be printed.
104
+ errors.length > 0 && loaderFailureMode === "clientRender"
105
+ ) {
103
106
  routerContext.statusCode = 200;
104
- errors = Object.values(routerContext.errors);
105
107
  throw errors[0];
106
108
  }
107
109
  router = createStaticRouter(routes, routerContext);
@@ -1,12 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { loadableReady } from "@loadable/component";
3
- import { normalizePathname } from "@modern-js/runtime-utils/url";
4
3
  import { RenderLevel } from "../constants";
5
4
  import { wrapRuntimeContextProvider } from "../react/wrapper";
6
5
  import { WithCallback } from "./withCallback";
7
6
  const isReact18 = () => process.env.IS_REACT18 === "true";
8
7
  function hydrateRoot(App, context, ModernRender, ModernHydrate) {
9
- var _ssrContext_request, _window__SSR_DATA, _window, _window__SSR_DATA1, _window1;
8
+ var _window__SSR_DATA, _window, _window__SSR_DATA1, _window1;
10
9
  const hydrateContext = {
11
10
  ...context,
12
11
  get routes() {
@@ -14,14 +13,6 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
14
13
  },
15
14
  _hydration: true
16
15
  };
17
- const { ssrContext } = hydrateContext;
18
- const currentPathname = normalizePathname(window.location.pathname);
19
- const initialPathname = (ssrContext === null || ssrContext === void 0 ? void 0 : (_ssrContext_request = ssrContext.request) === null || _ssrContext_request === void 0 ? void 0 : _ssrContext_request.pathname) && normalizePathname(ssrContext.request.pathname);
20
- if (initialPathname && initialPathname !== currentPathname && context.router) {
21
- const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
22
- console.error(errorMsg);
23
- window.location.reload();
24
- }
25
16
  const callback = () => {
26
17
  delete hydrateContext._hydration;
27
18
  };
@@ -1,4 +1,4 @@
1
- import { Transform } from "stream";
1
+ import { PassThrough, Transform } from "stream";
2
2
  import { createReadableStreamFromReadable } from "@modern-js/runtime-utils/node";
3
3
  import checkIsBot from "isbot";
4
4
  import { ServerStyleSheet } from "styled-components";
@@ -16,9 +16,9 @@ const createReadableStreamFromElement = async (request, rootElement, options) =>
16
16
  const onReady = isbot || forceStream2String ? "onAllReady" : "onShellReady";
17
17
  const sheet = new ServerStyleSheet();
18
18
  const chunkVec = [];
19
- const root = forceStream2String ? sheet.collectStyles(rootElement) : rootElement;
19
+ const root = sheet.collectStyles(rootElement);
20
20
  return new Promise((resolve) => {
21
- const { pipe } = renderToPipeableStream(root, {
21
+ const { pipe: reactStreamingPipe } = renderToPipeableStream(root, {
22
22
  nonce: config.nonce,
23
23
  [onReady]() {
24
24
  var _options_onReady;
@@ -59,7 +59,10 @@ const createReadableStreamFromElement = async (request, rootElement, options) =>
59
59
  });
60
60
  const stream = createReadableStreamFromReadable(body);
61
61
  resolve(stream);
62
- pipe(body);
62
+ const passThrough = new PassThrough();
63
+ const styledStream = sheet.interleaveWithNodeStream(passThrough);
64
+ reactStreamingPipe(passThrough);
65
+ styledStream.pipe(body);
63
66
  });
64
67
  },
65
68
  onShellError(error) {
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { merge } from "@modern-js/runtime-utils/merge";
3
3
  import { RouterProvider, createBrowserRouter, createHashRouter, createRoutesFromElements, useHref, useLocation, useMatches } from "@modern-js/runtime-utils/router";
4
+ import { normalizePathname } from "@modern-js/runtime-utils/url";
4
5
  import { useContext, useMemo } from "react";
5
6
  import { RuntimeReactContext } from "../../core";
6
7
  import { getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
@@ -29,6 +30,17 @@ const routerPlugin = (userConfig = {}) => {
29
30
  let routes = [];
30
31
  return {
31
32
  beforeRender(context) {
33
+ if (window._SSR_DATA && userConfig.unstable_reloadOnURLMismatch) {
34
+ var _ssrContext_request;
35
+ const { ssrContext } = context;
36
+ const currentPathname = normalizePathname(window.location.pathname);
37
+ const initialPathname = (ssrContext === null || ssrContext === void 0 ? void 0 : (_ssrContext_request = ssrContext.request) === null || _ssrContext_request === void 0 ? void 0 : _ssrContext_request.pathname) && normalizePathname(ssrContext.request.pathname);
38
+ if (initialPathname && initialPathname !== currentPathname) {
39
+ const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
40
+ console.error(errorMsg);
41
+ window.location.reload();
42
+ }
43
+ }
32
44
  context.router = {
33
45
  useMatches,
34
46
  useLocation,
@@ -75,10 +75,12 @@ const routerPlugin = (userConfig = {}) => {
75
75
  if (routerContext instanceof Response) {
76
76
  return interrupt(routerContext);
77
77
  }
78
- if (routerContext.statusCode >= 500 && routerContext.statusCode < 600 && // TODO: if loaderFailureMode is not 'errroBoundary', error log will not be printed.
79
- loaderFailureMode === "clientRender") {
78
+ const errors = Object.values(routerContext.errors || {});
79
+ if (
80
+ // TODO: if loaderFailureMode is not 'errroBoundary', error log will not be printed.
81
+ errors.length > 0 && loaderFailureMode === "clientRender"
82
+ ) {
80
83
  routerContext.statusCode = 200;
81
- const errors = Object.values(routerContext.errors);
82
84
  throw errors[0];
83
85
  }
84
86
  const router = createStaticRouter(routes, routerContext);
@@ -32,6 +32,10 @@ export type RouterConfig = {
32
32
  future?: Partial<{
33
33
  v7_startTransition: boolean;
34
34
  }>;
35
+ /**
36
+ * An unstable feature, which will reload the page when the current browser URL and the SSR Context URL do not match.
37
+ */
38
+ unstable_reloadOnURLMismatch?: boolean;
35
39
  };
36
40
  export type Routes = RouterConfig['routesConfig']['routes'];
37
41
  export interface RouteManifest {
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.63.6",
18
+ "version": "2.63.7",
19
19
  "engines": {
20
20
  "node": ">=14.17.6"
21
21
  },
@@ -200,12 +200,12 @@
200
200
  "react-is": "^18",
201
201
  "react-side-effect": "^2.1.1",
202
202
  "styled-components": "^5.3.1",
203
- "@modern-js/plugin": "2.63.6",
204
- "@modern-js/plugin-v2": "2.63.6",
205
- "@modern-js/plugin-data-loader": "2.63.6",
206
- "@modern-js/runtime-utils": "2.63.6",
207
- "@modern-js/types": "2.63.6",
208
- "@modern-js/utils": "2.63.6"
203
+ "@modern-js/plugin": "2.63.7",
204
+ "@modern-js/plugin-v2": "2.63.7",
205
+ "@modern-js/plugin-data-loader": "2.63.7",
206
+ "@modern-js/runtime-utils": "2.63.7",
207
+ "@modern-js/types": "2.63.7",
208
+ "@modern-js/utils": "2.63.7"
209
209
  },
210
210
  "peerDependencies": {
211
211
  "react": ">=17",
@@ -229,9 +229,9 @@
229
229
  "ts-node": "^10.9.1",
230
230
  "typescript": "^5",
231
231
  "webpack": "^5.97.1",
232
- "@scripts/build": "2.63.6",
233
- "@modern-js/app-tools": "2.63.6",
234
- "@scripts/jest-config": "2.63.6"
232
+ "@modern-js/app-tools": "2.63.7",
233
+ "@scripts/build": "2.63.7",
234
+ "@scripts/jest-config": "2.63.7"
235
235
  },
236
236
  "sideEffects": false,
237
237
  "publishConfig": {