@modern-js/runtime 2.25.2 → 2.27.0

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 CHANGED
@@ -1,5 +1,46 @@
1
1
  # @modern-js/runtime
2
2
 
3
+ ## 2.27.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 21be212: fix: add support for nodenext moduleResolution
8
+ fix: TS 类型支持 moduleResolution 为 nodenext
9
+ - 8322a51: chore: migrate packages from tsc to module-lib build
10
+
11
+ chore: 将使用 tsc 的包迁移到 module-lib 构建
12
+
13
+ - fb51b98: fix: fix remixRouter not existed in conventional routes
14
+ fix: 修复 remixRouter 在约定式路由下不存在问题
15
+ - b591092: fix: fix `modifyRoutes` in SSR
16
+ fix: 修复 SSR 时, `modifyRoutes` 执行时机
17
+ - Updated dependencies [91d14b8]
18
+ - Updated dependencies [6d7104d]
19
+ - @modern-js/utils@2.27.0
20
+ - @modern-js/plugin@2.27.0
21
+ - @modern-js/types@2.27.0
22
+
23
+ ## 2.26.0
24
+
25
+ ### Minor Changes
26
+
27
+ - 22acfda: feat: support unstable_getBlockNavState
28
+ feat: 支持 unstable_getBlockNavState
29
+
30
+ ### Patch Changes
31
+
32
+ - 64a51c4: fix(plugin-runtime): we should not repeatly registe the script, if template has it.
33
+ fix(plugin-runtime): 如果模版中已经有了,我们不应该重复添加 script 链接
34
+ - 1586774: feat: add support for origin properties in document
35
+ feat: 为 document 增加原始属性透传
36
+ - 73c592d: fix: should define remixRouter property when the property does not exist
37
+ fix: 应该仅当属性不存在时,定义 remixRouter
38
+ - 5c2dbb3: refactor: use import syntax for reduck plugin types
39
+ refactor: 使用 import 语法加载 reduck 插件的类型文件
40
+ - @modern-js/plugin@2.26.0
41
+ - @modern-js/types@2.26.0
42
+ - @modern-js/utils@2.26.0
43
+
3
44
  ## 2.25.2
4
45
 
5
46
  ### Patch Changes
@@ -16,8 +16,9 @@ const _DocumentStructureContext = require("./DocumentStructureContext");
16
16
  const _Root = require("./Root");
17
17
  function Body(props) {
18
18
  const { hasSetRoot } = (0, _react.useContext)(_DocumentStructureContext.DocumentStructureContext);
19
- const { children } = props;
19
+ const { children, ...rest } = props;
20
20
  return /* @__PURE__ */ (0, _jsxruntime.jsxs)("body", {
21
+ ...rest,
21
22
  children: [
22
23
  hasSetRoot ? null : /* @__PURE__ */ (0, _jsxruntime.jsx)(_Root.DefaultRoot, {}),
23
24
  children,
@@ -26,8 +26,9 @@ const _Links = require("./Links");
26
26
  const _constants = require("./constants");
27
27
  function Head(props) {
28
28
  const { hasSetScripts, hasSetLinks } = (0, _react.useContext)(_DocumentStructureContext.DocumentStructureContext);
29
- const { children } = props;
29
+ const { children, ...rest } = props;
30
30
  return /* @__PURE__ */ (0, _jsxruntime.jsxs)("head", {
31
+ ...rest,
31
32
  children: [
32
33
  `${_constants.DOCUMENT_META_PLACEHOLDER}`,
33
34
  !hasSetLinks && /* @__PURE__ */ (0, _jsxruntime.jsx)(_Links.Links, {}),
@@ -20,18 +20,24 @@ _export(exports, {
20
20
  const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
21
21
  const _jsxruntime = require("react/jsx-runtime");
22
22
  const _react = /* @__PURE__ */ _interop_require_wildcard._(require("react"));
23
+ const _lodash = require("@modern-js/utils/lodash");
23
24
  const _DocumentContext = require("./DocumentContext");
24
25
  const _constants = require("./constants");
25
26
  function Root(props) {
26
- const { rootId, children } = props;
27
+ const { rootId, children, ...rest } = props;
28
+ const legalProperties = (0, _lodash.omit)(rest, "id");
27
29
  const { templateParams: { mountId = "root" } } = (0, _react.useContext)(_DocumentContext.DocumentContext);
28
- return /* @__PURE__ */ (0, _jsxruntime.jsxs)("div", {
29
- id: `${rootId || mountId}`,
30
- children: [
31
- `${_constants.DOCUMENT_SSR_PLACEHOLDER}`,
32
- children
33
- ]
34
- });
30
+ return (
31
+ // in case for properities order not keep
32
+ /* @__PURE__ */ (0, _jsxruntime.jsxs)("div", {
33
+ id: `${rootId || mountId}`,
34
+ ...legalProperties,
35
+ children: [
36
+ `${_constants.DOCUMENT_SSR_PLACEHOLDER}`,
37
+ children
38
+ ]
39
+ })
40
+ );
35
41
  }
36
42
  function DefaultRoot(props) {
37
43
  const { templateParams: { mountId = "root" } } = (0, _react.useContext)(_DocumentContext.DocumentContext);
@@ -105,7 +105,25 @@ const routerPlugin = ({ serverBase = [], supportHtml5History = true, basename =
105
105
  hydrationData
106
106
  });
107
107
  const runtimeContext = (0, _react.useContext)(_core.RuntimeReactContext);
108
- runtimeContext.remixRouter = router;
108
+ if (!runtimeContext.remixRouter) {
109
+ Object.defineProperty(runtimeContext, "remixRouter", {
110
+ get() {
111
+ return router;
112
+ }
113
+ });
114
+ }
115
+ const originSubscribe = router.subscribe;
116
+ router.subscribe = (listener) => {
117
+ const wrapedListener = (...args) => {
118
+ const getBlockNavState = runtimeContext.unstable_getBlockNavState;
119
+ const blockRoute = getBlockNavState ? getBlockNavState() : false;
120
+ if (blockRoute) {
121
+ return;
122
+ }
123
+ return listener(...args);
124
+ };
125
+ return originSubscribe(wrapedListener);
126
+ };
109
127
  return /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
110
128
  ...props,
111
129
  children: /* @__PURE__ */ (0, _jsxruntime.jsx)(_router.RouterProvider, {
@@ -76,13 +76,15 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
76
76
  const { request, mode: ssrMode, nonce } = context.ssrContext;
77
77
  const baseUrl = request.baseUrl;
78
78
  const _basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, basename) : baseUrl;
79
- const routes = createRoutes ? createRoutes() : (0, _router1.createRoutesFromElements)((0, _utils.renderRoutes)({
79
+ let routes = createRoutes ? createRoutes() : (0, _router1.createRoutesFromElements)((0, _utils.renderRoutes)({
80
80
  routesConfig,
81
81
  ssrMode,
82
82
  props: {
83
83
  nonce
84
84
  }
85
85
  }));
86
+ const runner = api.useHookRunners();
87
+ routes = runner.modifyRoutes(routes);
86
88
  const { query } = (0, _remixrouter.createStaticHandler)(routes, {
87
89
  basename: _basename
88
90
  });
@@ -96,8 +98,6 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
96
98
  context.routerContext = routerContext;
97
99
  context.routes = routes;
98
100
  context.routeManifest = context.ssrContext.routeManifest;
99
- const runner = api.useHookRunners();
100
- runner.modifyRoutes(routes);
101
101
  return next({
102
102
  context
103
103
  });
@@ -133,6 +133,12 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
133
133
  },
134
134
  pickContext: ({ context, pickedContext }, next) => {
135
135
  const { remixRouter } = context;
136
+ if (!remixRouter) {
137
+ return next({
138
+ context,
139
+ pickedContext
140
+ });
141
+ }
136
142
  const router = {
137
143
  navigate: remixRouter.navigate,
138
144
  get location() {
@@ -112,7 +112,8 @@ class Entry {
112
112
  result: this.result,
113
113
  entryName: this.entryName,
114
114
  config: this.pluginConfig,
115
- nonce: this.nonce
115
+ nonce: this.nonce,
116
+ template: this.template
116
117
  };
117
118
  html = (0, _reduce.reduce)(App, renderContext, [
118
119
  _styledComponent.toHtml,
@@ -151,6 +152,7 @@ class Entry {
151
152
  _define_property._(this, "result", void 0);
152
153
  _define_property._(this, "metrics", void 0);
153
154
  _define_property._(this, "logger", void 0);
155
+ _define_property._(this, "template", void 0);
154
156
  _define_property._(this, "App", void 0);
155
157
  _define_property._(this, "fragments", void 0);
156
158
  _define_property._(this, "pluginConfig", void 0);
@@ -159,6 +161,7 @@ class Entry {
159
161
  const { ctx, config } = options;
160
162
  const { entryName, template, request: { host }, nonce } = ctx;
161
163
  this.fragments = (0, _template.toFragments)(template, entryName);
164
+ this.template = template;
162
165
  this.entryName = entryName;
163
166
  this.host = host;
164
167
  this.App = options.App;
@@ -47,9 +47,12 @@ const toHtml = (jsx, renderer, next) => {
47
47
  default:
48
48
  }
49
49
  if (fileType === "js") {
50
- attributes.nonce = nonce;
51
- const attrsStr = (0, _utils.attributesToString)(attributes);
52
- chunksMap[fileType] += `<script${attrsStr} src="${v.url}"></script>`;
50
+ const jsChunkReg = new RegExp(`<script .*src="${v.url}".*>`);
51
+ if (!jsChunkReg.test(renderer.template)) {
52
+ attributes.nonce = nonce;
53
+ const attrsStr = (0, _utils.attributesToString)(attributes);
54
+ chunksMap[fileType] += `<script${attrsStr} src="${v.url}"></script>`;
55
+ }
53
56
  } else if (fileType === "css") {
54
57
  const attrsStr = (0, _utils.attributesToString)(attributes);
55
58
  chunksMap[fileType] += `<link${attrsStr} href="${v.url}" rel="stylesheet" />`;
@@ -1,3 +1,6 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
+ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
1
4
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
5
  import { useContext } from "react";
3
6
  import { DOCUMENT_CHUNKSMAP_PLACEHOLDER, DOCUMENT_SSRDATASCRIPT_PLACEHOLDER } from "./constants";
@@ -5,13 +8,15 @@ import { DocumentStructureContext } from "./DocumentStructureContext";
5
8
  import { DefaultRoot } from "./Root";
6
9
  export function Body(props) {
7
10
  var hasSetRoot = useContext(DocumentStructureContext).hasSetRoot;
8
- var children = props.children;
9
- return /* @__PURE__ */ _jsxs("body", {
11
+ var children = props.children, rest = _object_without_properties(props, [
12
+ "children"
13
+ ]);
14
+ return /* @__PURE__ */ _jsxs("body", _object_spread_props(_object_spread({}, rest), {
10
15
  children: [
11
16
  hasSetRoot ? null : /* @__PURE__ */ _jsx(DefaultRoot, {}),
12
17
  children,
13
18
  "".concat(DOCUMENT_CHUNKSMAP_PLACEHOLDER),
14
19
  "".concat(DOCUMENT_SSRDATASCRIPT_PLACEHOLDER)
15
20
  ]
16
- });
21
+ }));
17
22
  }
@@ -1,3 +1,6 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
+ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
1
4
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
5
  import { useContext } from "react";
3
6
  import { DocumentStructureContext } from "./DocumentStructureContext";
@@ -6,15 +9,17 @@ import { Links } from "./Links";
6
9
  import { DOCUMENT_META_PLACEHOLDER } from "./constants";
7
10
  export function Head(props) {
8
11
  var _useContext = useContext(DocumentStructureContext), hasSetScripts = _useContext.hasSetScripts, hasSetLinks = _useContext.hasSetLinks;
9
- var children = props.children;
10
- return /* @__PURE__ */ _jsxs("head", {
12
+ var children = props.children, rest = _object_without_properties(props, [
13
+ "children"
14
+ ]);
15
+ return /* @__PURE__ */ _jsxs("head", _object_spread_props(_object_spread({}, rest), {
11
16
  children: [
12
17
  "".concat(DOCUMENT_META_PLACEHOLDER),
13
18
  !hasSetLinks && /* @__PURE__ */ _jsx(Links, {}),
14
19
  !hasSetScripts && /* @__PURE__ */ _jsx(Scripts, {}),
15
20
  children
16
21
  ]
17
- });
22
+ }));
18
23
  }
19
24
  export function DefaultHead() {
20
25
  return /* @__PURE__ */ _jsx("head", {
@@ -1,17 +1,29 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
+ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
1
4
  import { jsxs as _jsxs } from "react/jsx-runtime";
2
5
  import { useContext } from "react";
6
+ import { omit } from "@modern-js/utils/lodash";
3
7
  import { DocumentContext } from "./DocumentContext";
4
8
  import { DOCUMENT_SSR_PLACEHOLDER } from "./constants";
5
9
  export function Root(props) {
6
- var rootId = props.rootId, children = props.children;
10
+ var rootId = props.rootId, children = props.children, rest = _object_without_properties(props, [
11
+ "rootId",
12
+ "children"
13
+ ]);
14
+ var legalProperties = omit(rest, "id");
7
15
  var _useContext = useContext(DocumentContext), _useContext_templateParams = _useContext.templateParams, _useContext_templateParams_mountId = _useContext_templateParams.mountId, mountId = _useContext_templateParams_mountId === void 0 ? "root" : _useContext_templateParams_mountId;
8
- return /* @__PURE__ */ _jsxs("div", {
9
- id: "".concat(rootId || mountId),
10
- children: [
11
- "".concat(DOCUMENT_SSR_PLACEHOLDER),
12
- children
13
- ]
14
- });
16
+ return (
17
+ // in case for properities order not keep
18
+ /* @__PURE__ */ _jsxs("div", _object_spread_props(_object_spread({
19
+ id: "".concat(rootId || mountId)
20
+ }, legalProperties), {
21
+ children: [
22
+ "".concat(DOCUMENT_SSR_PLACEHOLDER),
23
+ children
24
+ ]
25
+ }))
26
+ );
15
27
  }
16
28
  export function DefaultRoot(props) {
17
29
  var _useContext = useContext(DocumentContext), _useContext_templateParams = _useContext.templateParams, _useContext_templateParams_mountId = _useContext_templateParams.mountId, mountId = _useContext_templateParams_mountId === void 0 ? "root" : _useContext_templateParams_mountId;
@@ -1,5 +1,6 @@
1
1
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
2
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
4
  import { jsx as _jsx } from "react/jsx-runtime";
4
5
  import { useContext } from "react";
5
6
  import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements, useMatches, useLocation } from "@modern-js/utils/runtime/router";
@@ -86,7 +87,28 @@ export var routerPlugin = function(param) {
86
87
  hydrationData: hydrationData
87
88
  });
88
89
  var runtimeContext = useContext(RuntimeReactContext);
89
- runtimeContext.remixRouter = router;
90
+ if (!runtimeContext.remixRouter) {
91
+ Object.defineProperty(runtimeContext, "remixRouter", {
92
+ get: function get() {
93
+ return router;
94
+ }
95
+ });
96
+ }
97
+ var originSubscribe = router.subscribe;
98
+ router.subscribe = function(listener) {
99
+ var wrapedListener = function() {
100
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
101
+ args[_key] = arguments[_key];
102
+ }
103
+ var getBlockNavState = runtimeContext.unstable_getBlockNavState;
104
+ var blockRoute = getBlockNavState ? getBlockNavState() : false;
105
+ if (blockRoute) {
106
+ return;
107
+ }
108
+ return listener.apply(void 0, _to_consumable_array(args));
109
+ };
110
+ return originSubscribe(wrapedListener);
111
+ };
90
112
  return /* @__PURE__ */ _jsx(App, _object_spread_props(_object_spread({}, props), {
91
113
  children: /* @__PURE__ */ _jsx(RouterProvider, {
92
114
  router: router
@@ -87,7 +87,7 @@ export var routerPlugin = function(param) {
87
87
  init: function init(param2, next) {
88
88
  var context = param2.context;
89
89
  return _async_to_generator(function() {
90
- var _context_ssrContext, request, ssrMode, nonce, baseUrl, _basename, routes, query, remixRequest, routerContext, router, runner;
90
+ var _context_ssrContext, request, ssrMode, nonce, baseUrl, _basename, routes, runner, query, remixRequest, routerContext, router;
91
91
  return _ts_generator(this, function(_state) {
92
92
  switch (_state.label) {
93
93
  case 0:
@@ -109,6 +109,8 @@ export var routerPlugin = function(param) {
109
109
  nonce: nonce
110
110
  }
111
111
  }));
112
+ runner = api.useHookRunners();
113
+ routes = runner.modifyRoutes(routes);
112
114
  query = createStaticHandler(routes, {
113
115
  basename: _basename
114
116
  }).query;
@@ -130,8 +132,6 @@ export var routerPlugin = function(param) {
130
132
  context.routerContext = routerContext;
131
133
  context.routes = routes;
132
134
  context.routeManifest = context.ssrContext.routeManifest;
133
- runner = api.useHookRunners();
134
- runner.modifyRoutes(routes);
135
135
  return [
136
136
  2,
137
137
  next({
@@ -174,6 +174,12 @@ export var routerPlugin = function(param) {
174
174
  pickContext: function(param2, next) {
175
175
  var context = param2.context, pickedContext = param2.pickedContext;
176
176
  var remixRouter = context.remixRouter;
177
+ if (!remixRouter) {
178
+ return next({
179
+ context: context,
180
+ pickedContext: pickedContext
181
+ });
182
+ }
177
183
  var router = {
178
184
  navigate: remixRouter.navigate,
179
185
  get location() {
@@ -45,6 +45,7 @@ var Entry = /* @__PURE__ */ function() {
45
45
  _define_property(this, "result", void 0);
46
46
  _define_property(this, "metrics", void 0);
47
47
  _define_property(this, "logger", void 0);
48
+ _define_property(this, "template", void 0);
48
49
  _define_property(this, "App", void 0);
49
50
  _define_property(this, "fragments", void 0);
50
51
  _define_property(this, "pluginConfig", void 0);
@@ -53,6 +54,7 @@ var Entry = /* @__PURE__ */ function() {
53
54
  var ctx = options.ctx, config = options.config;
54
55
  var entryName = ctx.entryName, template = ctx.template, host = ctx.request.host, nonce = ctx.nonce;
55
56
  this.fragments = toFragments(template, entryName);
57
+ this.template = template;
56
58
  this.entryName = entryName;
57
59
  this.host = host;
58
60
  this.App = options.App;
@@ -218,7 +220,8 @@ var Entry = /* @__PURE__ */ function() {
218
220
  result: this.result,
219
221
  entryName: this.entryName,
220
222
  config: this.pluginConfig,
221
- nonce: this.nonce
223
+ nonce: this.nonce,
224
+ template: this.template
222
225
  };
223
226
  html = reduce(App, renderContext, [
224
227
  styledComponentRenderer.toHtml,
@@ -40,9 +40,12 @@ export var toHtml = function(jsx, renderer, next) {
40
40
  default:
41
41
  }
42
42
  if (fileType === "js") {
43
- attributes.nonce = nonce;
44
- var attrsStr = attributesToString(attributes);
45
- chunksMap[fileType] += "<script".concat(attrsStr, ' src="').concat(v.url, '"></script>');
43
+ var jsChunkReg = new RegExp('<script .*src="'.concat(v.url, '".*>'));
44
+ if (!jsChunkReg.test(renderer.template)) {
45
+ attributes.nonce = nonce;
46
+ var attrsStr = attributesToString(attributes);
47
+ chunksMap[fileType] += "<script".concat(attrsStr, ' src="').concat(v.url, '"></script>');
48
+ }
46
49
  } else if (fileType === "css") {
47
50
  var attrsStr1 = attributesToString(attributes);
48
51
  chunksMap[fileType] += "<link".concat(attrsStr1, ' href="').concat(v.url, '" rel="stylesheet" />');
@@ -5,8 +5,9 @@ import { DocumentStructureContext } from "./DocumentStructureContext";
5
5
  import { DefaultRoot } from "./Root";
6
6
  export function Body(props) {
7
7
  const { hasSetRoot } = useContext(DocumentStructureContext);
8
- const { children } = props;
8
+ const { children, ...rest } = props;
9
9
  return /* @__PURE__ */ _jsxs("body", {
10
+ ...rest,
10
11
  children: [
11
12
  hasSetRoot ? null : /* @__PURE__ */ _jsx(DefaultRoot, {}),
12
13
  children,
@@ -6,8 +6,9 @@ import { Links } from "./Links";
6
6
  import { DOCUMENT_META_PLACEHOLDER } from "./constants";
7
7
  export function Head(props) {
8
8
  const { hasSetScripts, hasSetLinks } = useContext(DocumentStructureContext);
9
- const { children } = props;
9
+ const { children, ...rest } = props;
10
10
  return /* @__PURE__ */ _jsxs("head", {
11
+ ...rest,
11
12
  children: [
12
13
  `${DOCUMENT_META_PLACEHOLDER}`,
13
14
  !hasSetLinks && /* @__PURE__ */ _jsx(Links, {}),
@@ -1,17 +1,23 @@
1
1
  import { jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useContext } from "react";
3
+ import { omit } from "@modern-js/utils/lodash";
3
4
  import { DocumentContext } from "./DocumentContext";
4
5
  import { DOCUMENT_SSR_PLACEHOLDER } from "./constants";
5
6
  export function Root(props) {
6
- const { rootId, children } = props;
7
+ const { rootId, children, ...rest } = props;
8
+ const legalProperties = omit(rest, "id");
7
9
  const { templateParams: { mountId = "root" } } = useContext(DocumentContext);
8
- return /* @__PURE__ */ _jsxs("div", {
9
- id: `${rootId || mountId}`,
10
- children: [
11
- `${DOCUMENT_SSR_PLACEHOLDER}`,
12
- children
13
- ]
14
- });
10
+ return (
11
+ // in case for properities order not keep
12
+ /* @__PURE__ */ _jsxs("div", {
13
+ id: `${rootId || mountId}`,
14
+ ...legalProperties,
15
+ children: [
16
+ `${DOCUMENT_SSR_PLACEHOLDER}`,
17
+ children
18
+ ]
19
+ })
20
+ );
15
21
  }
16
22
  export function DefaultRoot(props) {
17
23
  const { templateParams: { mountId = "root" } } = useContext(DocumentContext);
@@ -78,7 +78,25 @@ export const routerPlugin = ({ serverBase = [], supportHtml5History = true, base
78
78
  hydrationData
79
79
  });
80
80
  const runtimeContext = useContext(RuntimeReactContext);
81
- runtimeContext.remixRouter = router;
81
+ if (!runtimeContext.remixRouter) {
82
+ Object.defineProperty(runtimeContext, "remixRouter", {
83
+ get() {
84
+ return router;
85
+ }
86
+ });
87
+ }
88
+ const originSubscribe = router.subscribe;
89
+ router.subscribe = (listener) => {
90
+ const wrapedListener = (...args) => {
91
+ const getBlockNavState = runtimeContext.unstable_getBlockNavState;
92
+ const blockRoute = getBlockNavState ? getBlockNavState() : false;
93
+ if (blockRoute) {
94
+ return;
95
+ }
96
+ return listener(...args);
97
+ };
98
+ return originSubscribe(wrapedListener);
99
+ };
82
100
  return /* @__PURE__ */ _jsx(App, {
83
101
  ...props,
84
102
  children: /* @__PURE__ */ _jsx(RouterProvider, {
@@ -52,13 +52,15 @@ export const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
52
52
  const { request, mode: ssrMode, nonce } = context.ssrContext;
53
53
  const baseUrl = request.baseUrl;
54
54
  const _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
55
- const routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
55
+ let routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
56
56
  routesConfig,
57
57
  ssrMode,
58
58
  props: {
59
59
  nonce
60
60
  }
61
61
  }));
62
+ const runner = api.useHookRunners();
63
+ routes = runner.modifyRoutes(routes);
62
64
  const { query } = createStaticHandler(routes, {
63
65
  basename: _basename
64
66
  });
@@ -72,8 +74,6 @@ export const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
72
74
  context.routerContext = routerContext;
73
75
  context.routes = routes;
74
76
  context.routeManifest = context.ssrContext.routeManifest;
75
- const runner = api.useHookRunners();
76
- runner.modifyRoutes(routes);
77
77
  return next({
78
78
  context
79
79
  });
@@ -109,6 +109,12 @@ export const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
109
109
  },
110
110
  pickContext: ({ context, pickedContext }, next) => {
111
111
  const { remixRouter } = context;
112
+ if (!remixRouter) {
113
+ return next({
114
+ context,
115
+ pickedContext
116
+ });
117
+ }
112
118
  const router = {
113
119
  navigate: remixRouter.navigate,
114
120
  get location() {
@@ -100,7 +100,8 @@ class Entry {
100
100
  result: this.result,
101
101
  entryName: this.entryName,
102
102
  config: this.pluginConfig,
103
- nonce: this.nonce
103
+ nonce: this.nonce,
104
+ template: this.template
104
105
  };
105
106
  html = reduce(App, renderContext, [
106
107
  styledComponentRenderer.toHtml,
@@ -139,6 +140,7 @@ class Entry {
139
140
  _define_property(this, "result", void 0);
140
141
  _define_property(this, "metrics", void 0);
141
142
  _define_property(this, "logger", void 0);
143
+ _define_property(this, "template", void 0);
142
144
  _define_property(this, "App", void 0);
143
145
  _define_property(this, "fragments", void 0);
144
146
  _define_property(this, "pluginConfig", void 0);
@@ -147,6 +149,7 @@ class Entry {
147
149
  const { ctx, config } = options;
148
150
  const { entryName, template, request: { host }, nonce } = ctx;
149
151
  this.fragments = toFragments(template, entryName);
152
+ this.template = template;
150
153
  this.entryName = entryName;
151
154
  this.host = host;
152
155
  this.App = options.App;
@@ -37,9 +37,12 @@ export const toHtml = (jsx, renderer, next) => {
37
37
  default:
38
38
  }
39
39
  if (fileType === "js") {
40
- attributes.nonce = nonce;
41
- const attrsStr = attributesToString(attributes);
42
- chunksMap[fileType] += `<script${attrsStr} src="${v.url}"></script>`;
40
+ const jsChunkReg = new RegExp(`<script .*src="${v.url}".*>`);
41
+ if (!jsChunkReg.test(renderer.template)) {
42
+ attributes.nonce = nonce;
43
+ const attrsStr = attributesToString(attributes);
44
+ chunksMap[fileType] += `<script${attrsStr} src="${v.url}"></script>`;
45
+ }
43
46
  } else if (fileType === "css") {
44
47
  const attrsStr = attributesToString(attributes);
45
48
  chunksMap[fileType] += `<link${attrsStr} href="${v.url}" rel="stylesheet" />`;
@@ -13,6 +13,14 @@ export interface BaseRuntimeContext {
13
13
  store?: Store;
14
14
  routeManifest: RouteManifest;
15
15
  routerContext?: StaticHandlerContext;
16
+ /**
17
+ * private method
18
+ */
19
+ remixRouter?: Router;
20
+ /**
21
+ * private
22
+ */
23
+ unstable_getBlockNavState?: () => boolean;
16
24
  }
17
25
  export interface RuntimeContext extends BaseRuntimeContext {
18
26
  [key: string]: any;
@@ -10,6 +10,7 @@ export default class Entry {
10
10
  result: RenderResult;
11
11
  metrics: SSRServerContext['metrics'];
12
12
  logger: SSRServerContext['logger'];
13
+ private readonly template;
13
14
  private readonly App;
14
15
  private readonly fragments;
15
16
  private readonly pluginConfig;
@@ -19,6 +19,7 @@ export interface RenderEntry {
19
19
  result: RenderResult;
20
20
  stats: Record<string, any>;
21
21
  config: SSRPluginConfig;
22
+ template: string;
22
23
  nonce?: string;
23
24
  }
24
25
  export type RenderHandler = (jsx: React.ReactElement, renderer: RenderEntry, next: (jsx: React.ReactElement) => string) => string;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.25.2",
18
+ "version": "2.27.0",
19
19
  "engines": {
20
20
  "node": ">=14.17.6"
21
21
  },
@@ -29,6 +29,10 @@
29
29
  "types": "./dist/types/index.d.ts",
30
30
  "default": "./dist/esm/index.js"
31
31
  },
32
+ "./types": "./types/index.d.ts",
33
+ "./types/index": "./types/index.d.ts",
34
+ "./types/router": "./types/router.d.ts",
35
+ "./types/model": "./types/model.d.ts",
32
36
  "./loadable": {
33
37
  "jsnext:source": "./src/exports/loadable.ts",
34
38
  "types": "./dist/types/exports/loadable.d.ts",
@@ -145,9 +149,9 @@
145
149
  "@babel/core": "^7.21.8",
146
150
  "@babel/types": "^7.21.5",
147
151
  "cookie": "0.5.0",
148
- "@loadable/babel-plugin": "^5.13.2",
149
- "@loadable/component": "^5.15.0",
150
- "@loadable/server": "^5.15.1",
152
+ "@loadable/babel-plugin": "5.15.3",
153
+ "@loadable/component": "5.15.3",
154
+ "@loadable/server": "5.15.3",
151
155
  "@loadable/webpack-plugin": "5.15.2",
152
156
  "@modern-js-reduck/plugin-auto-actions": "^1.1.10",
153
157
  "@modern-js-reduck/plugin-devtools": "^1.1.10",
@@ -169,9 +173,9 @@
169
173
  "redux-logger": "^3.0.6",
170
174
  "styled-components": "^5.3.1",
171
175
  "@swc/helpers": "0.5.1",
172
- "@modern-js/plugin": "2.25.2",
173
- "@modern-js/types": "2.25.2",
174
- "@modern-js/utils": "2.25.2"
176
+ "@modern-js/plugin": "2.27.0",
177
+ "@modern-js/types": "2.27.0",
178
+ "@modern-js/utils": "2.27.0"
175
179
  },
176
180
  "peerDependencies": {
177
181
  "react": ">=17",
@@ -192,14 +196,13 @@
192
196
  "ts-jest": "^29.1.0",
193
197
  "typescript": "^5",
194
198
  "webpack": "^5.88.1",
195
- "@modern-js/app-tools": "2.25.2",
196
- "@modern-js/core": "2.25.2",
197
- "@modern-js/server-core": "2.25.2",
198
- "@scripts/build": "2.25.2",
199
- "@scripts/jest-config": "2.25.2"
199
+ "@modern-js/app-tools": "2.27.0",
200
+ "@modern-js/core": "2.27.0",
201
+ "@modern-js/server-core": "2.27.0",
202
+ "@scripts/jest-config": "2.27.0",
203
+ "@scripts/build": "2.27.0"
200
204
  },
201
205
  "sideEffects": false,
202
- "modernConfig": {},
203
206
  "publishConfig": {
204
207
  "registry": "https://registry.npmjs.org/",
205
208
  "access": "public",
package/types/model.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- /// <reference types="@modern-js-reduck/plugin-auto-actions" />
2
- /// <reference types="@modern-js-reduck/plugin-devtools" />
3
- /// <reference types="@modern-js-reduck/plugin-effects" />
4
- /// <reference types="@modern-js-reduck/plugin-immutable" />
1
+ import '@modern-js-reduck/plugin-auto-actions';
2
+ import '@modern-js-reduck/plugin-devtools';
3
+ import '@modern-js-reduck/plugin-effects';
4
+ import '@modern-js-reduck/plugin-immutable';
5
5
 
6
6
  export { default } from '../dist/types/state';
7
7
  export * from '../dist/types/state';