@modern-js/runtime 2.60.1-alpha.0 → 2.60.1-alpha.2

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.
@@ -125,10 +125,10 @@ const runtimePlugin = (params) => ({
125
125
  * Compatible with the reference path of the old version of the plugin.
126
126
  */
127
127
  [`@${metaName}/runtime/plugins`]: pluginsExportsUtils.getPath(),
128
- "@meta/runtime/browser": "@modern-js/runtime/browser",
129
- "@meta/runtime/react": "@modern-js/runtime/react",
130
- "@meta/runtime/context": "@modern-js/runtime/context",
131
- "@meta/runtime": "@modern-js/runtime"
128
+ "@meta/runtime/browser": require.resolve("@modern-js/runtime/browser"),
129
+ "@meta/runtime/react": require.resolve("@modern-js/runtime/react"),
130
+ "@meta/runtime/context": require.resolve("@modern-js/runtime/context"),
131
+ "@meta/runtime": require.resolve("@modern-js/runtime")
132
132
  },
133
133
  globalVars: {
134
134
  "process.env.IS_REACT18": process.env.IS_REACT18
@@ -32,14 +32,13 @@ __export(nossr_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(nossr_exports);
34
34
  var import_react = __toESM(require("react"));
35
- let csr = false;
35
+ var import_react2 = require("react");
36
36
  const NoSSR = (props) => {
37
- const [isMounted, setMounted] = (0, import_react.useState)(csr);
38
- (0, import_react.useEffect)(() => {
39
- csr = true;
37
+ const [isMounted, setMounted] = (0, import_react2.useState)(false);
38
+ (0, import_react2.useEffect)(() => {
40
39
  setMounted(true);
41
- });
42
- const { children, fallback = null } = props;
40
+ }, []);
41
+ const { children, fallback = null } = props || {};
43
42
  return import_react.default.createElement(import_react.default.Fragment, null, isMounted ? children : fallback);
44
43
  };
45
44
  // Annotate the CommonJS export names for ESM import in node:
@@ -35,6 +35,7 @@ module.exports = __toCommonJS(code_exports);
35
35
  var import_path = __toESM(require("path"));
36
36
  var import_utils = require("@modern-js/utils");
37
37
  var import_lodash = require("@modern-js/utils/lodash");
38
+ var import_route = require("@modern-js/utils/universal/route");
38
39
  var import_constants = require("../../../cli/constants");
39
40
  var import_constants2 = require("../constants");
40
41
  var import_getClientRoutes = require("./getClientRoutes");
@@ -84,7 +85,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
84
85
  const config2 = api.useResolvedConfigContext();
85
86
  const ssrByRouteIds = config2.server.ssrByRouteIds || [];
86
87
  const clonedRoutes = (0, import_lodash.cloneDeep)(initialRoutes);
87
- const markedRoutes = ssrByRouteIds.length > 0 ? markRoutes(clonedRoutes, ssrByRouteIds) : initialRoutes;
88
+ const markedRoutes = ssrByRouteIds.length > 0 ? (0, import_route.markRoutes)(clonedRoutes, ssrByRouteIds) : initialRoutes;
88
89
  const { routes } = await hookRunners.modifyFileSystemRoutes({
89
90
  entrypoint,
90
91
  routes: markedRoutes
@@ -117,8 +118,8 @@ const generateCode = async (appContext, config, entrypoints, api) => {
117
118
  if (entrypoint.nestedRoutesEntry && (0, import_utils.isUseSSRBundle)(config2)) {
118
119
  var _config_output1;
119
120
  const routesServerFile = (0, import_utils2.getServerLoadersFile)(internalDirectory, entryName);
120
- const filtedRoutesForServer = (0, import_utils.filterRoutesForServer)(routes);
121
- const routesForServerLoaderMatches = (0, import_utils.filterRoutesLoader)(routes);
121
+ const filtedRoutesForServer = (0, import_route.filterRoutesForServer)(routes);
122
+ const routesForServerLoaderMatches = (0, import_route.filterRoutesLoader)(routes);
122
123
  const code2 = templates.routesForServer({
123
124
  routesForServerLoaderMatches
124
125
  });
@@ -145,25 +146,6 @@ const generateCode = async (appContext, config, entrypoints, api) => {
145
146
  }
146
147
  }
147
148
  };
148
- function markRoutes(routes, routeIds) {
149
- return routes.map((route) => {
150
- if (route.type !== "nested") {
151
- return route;
152
- }
153
- if (route.children && route.children.length > 0) {
154
- route.children = markRoutes(route.children, routeIds);
155
- }
156
- if (route.children && route.children.length > 0) {
157
- route.inValidSSRRoute = route.children.every((child) => {
158
- var _child_inValidSSRRoute;
159
- return (_child_inValidSSRRoute = child.inValidSSRRoute) !== null && _child_inValidSSRRoute !== void 0 ? _child_inValidSSRRoute : false;
160
- });
161
- } else if (route.id) {
162
- route.inValidSSRRoute = !routeIds.includes(route.id);
163
- }
164
- return route;
165
- });
166
- }
167
149
  function generatorRegisterCode(internalDirectory, entryName, code) {
168
150
  import_utils.fs.outputFileSync(import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME}`), code, "utf8");
169
151
  }
@@ -37,6 +37,7 @@ __export(cli_exports, {
37
37
  module.exports = __toCommonJS(cli_exports);
38
38
  var import_node_path = __toESM(require("node:path"));
39
39
  var import_utils = require("@modern-js/utils");
40
+ var import_route = require("@modern-js/utils/universal/route");
40
41
  var import_entry = require("./entry");
41
42
  var import_handler = require("./handler");
42
43
  var import_entry2 = require("./entry");
@@ -115,7 +116,7 @@ const routerPlugin = () => ({
115
116
  },
116
117
  async modifyFileSystemRoutes({ entrypoint, routes }) {
117
118
  nestedRoutes[entrypoint.entryName] = routes;
118
- nestedRoutesForServer[entrypoint.entryName] = (0, import_utils.filterRoutesForServer)(routes);
119
+ nestedRoutesForServer[entrypoint.entryName] = (0, import_route.filterRoutesForServer)(routes);
119
120
  return {
120
121
  entrypoint,
121
122
  routes
@@ -84,8 +84,8 @@ const routerPlugin = (userConfig = {}) => {
84
84
  const useCreateRouter = (props) => {
85
85
  var _window__SERVER_DATA;
86
86
  const runtimeContext = (0, import_react.useContext)(import_core.RuntimeReactContext);
87
- const baseUrl = (runtimeContext._internalRouterBaseName || ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname)).replace(/^\/*/, "/");
88
- const _basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, basename) : baseUrl;
87
+ const baseUrl = (((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname)).replace(/^\/*/, "/");
88
+ const _basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || basename) : baseUrl;
89
89
  let hydrationData = window._ROUTER_DATA;
90
90
  const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
91
91
  return (0, import_react.useMemo)(() => {
@@ -109,7 +109,7 @@ var runtimePlugin = function(params) {
109
109
  }, /**
110
110
  * Compatible with the reference path of the old version of the plugin.
111
111
  */
112
- _define_property(_obj, "@".concat(metaName, "/runtime/plugins"), pluginsExportsUtils.getPath()), _define_property(_obj, "@meta/runtime/browser", "@modern-js/runtime/browser"), _define_property(_obj, "@meta/runtime/react", "@modern-js/runtime/react"), _define_property(_obj, "@meta/runtime/context", "@modern-js/runtime/context"), _define_property(_obj, "@meta/runtime", "@modern-js/runtime"), _obj),
112
+ _define_property(_obj, "@".concat(metaName, "/runtime/plugins"), pluginsExportsUtils.getPath()), _define_property(_obj, "@meta/runtime/browser", require.resolve("@modern-js/runtime/browser")), _define_property(_obj, "@meta/runtime/react", require.resolve("@modern-js/runtime/react")), _define_property(_obj, "@meta/runtime/context", require.resolve("@modern-js/runtime/context")), _define_property(_obj, "@meta/runtime", require.resolve("@modern-js/runtime")), _obj),
113
113
  globalVars: {
114
114
  "process.env.IS_REACT18": process.env.IS_REACT18
115
115
  }
@@ -1,13 +1,12 @@
1
1
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
2
- import React, { useEffect, useState } from "react";
3
- var csr = false;
2
+ import React from "react";
3
+ import { useEffect, useState } from "react";
4
4
  var NoSSR = function(props) {
5
- var _useState = _sliced_to_array(useState(csr), 2), isMounted = _useState[0], setMounted = _useState[1];
5
+ var _useState = _sliced_to_array(useState(false), 2), isMounted = _useState[0], setMounted = _useState[1];
6
6
  useEffect(function() {
7
- csr = true;
8
7
  setMounted(true);
9
- });
10
- var children = props.children, _props_fallback = props.fallback, fallback = _props_fallback === void 0 ? null : _props_fallback;
8
+ }, []);
9
+ var _ref = props || {}, children = _ref.children, _ref_fallback = _ref.fallback, fallback = _ref_fallback === void 0 ? null : _ref_fallback;
11
10
  return React.createElement(React.Fragment, null, isMounted ? children : fallback);
12
11
  };
13
12
  export {
@@ -2,8 +2,9 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _type_of } from "@swc/helpers/_/_type_of";
3
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
4
  import path from "path";
5
- import { fs, filterRoutesForServer, filterRoutesLoader, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
5
+ import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
6
6
  import { cloneDeep } from "@modern-js/utils/lodash";
7
+ import { filterRoutesForServer, filterRoutesLoader, markRoutes } from "@modern-js/utils/universal/route";
7
8
  import { ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME } from "../../../cli/constants";
8
9
  import { FILE_SYSTEM_ROUTES_FILE_NAME } from "../constants";
9
10
  import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
@@ -240,25 +241,6 @@ var generateCode = function() {
240
241
  return _ref.apply(this, arguments);
241
242
  };
242
243
  }();
243
- function markRoutes(routes, routeIds) {
244
- return routes.map(function(route) {
245
- if (route.type !== "nested") {
246
- return route;
247
- }
248
- if (route.children && route.children.length > 0) {
249
- route.children = markRoutes(route.children, routeIds);
250
- }
251
- if (route.children && route.children.length > 0) {
252
- route.inValidSSRRoute = route.children.every(function(child) {
253
- var _child_inValidSSRRoute;
254
- return (_child_inValidSSRRoute = child.inValidSSRRoute) !== null && _child_inValidSSRRoute !== void 0 ? _child_inValidSSRRoute : false;
255
- });
256
- } else if (route.id) {
257
- route.inValidSSRRoute = !routeIds.includes(route.id);
258
- }
259
- return route;
260
- });
261
- }
262
244
  function generatorRegisterCode(internalDirectory, entryName, code) {
263
245
  fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME)), code, "utf8");
264
246
  }
@@ -3,7 +3,8 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
3
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import path from "node:path";
6
- import { fs, NESTED_ROUTE_SPEC_FILE, createRuntimeExportsUtils, filterRoutesForServer, getEntryOptions, isRouterV5 as isV5 } from "@modern-js/utils";
6
+ import { fs, NESTED_ROUTE_SPEC_FILE, createRuntimeExportsUtils, getEntryOptions, isRouterV5 as isV5 } from "@modern-js/utils";
7
+ import { filterRoutesForServer } from "@modern-js/utils/universal/route";
7
8
  import { isRouteEntry } from "./entry";
8
9
  import { handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints } from "./handler";
9
10
  import { isRouteEntry as isRouteEntry2 } from "./entry";
@@ -65,8 +65,8 @@ var routerPlugin = function() {
65
65
  var useCreateRouter = function(props) {
66
66
  var _window__SERVER_DATA;
67
67
  var runtimeContext = useContext(RuntimeReactContext);
68
- var baseUrl = (runtimeContext._internalRouterBaseName || ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname)).replace(/^\/*/, "/");
69
- var _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
68
+ var baseUrl = (((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname)).replace(/^\/*/, "/");
69
+ var _basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename) : baseUrl;
70
70
  var hydrationData = window._ROUTER_DATA;
71
71
  var getBlockNavState = runtimeContext.unstable_getBlockNavState;
72
72
  return useMemo(function() {
@@ -86,10 +86,10 @@ const runtimePlugin = (params) => ({
86
86
  * Compatible with the reference path of the old version of the plugin.
87
87
  */
88
88
  [`@${metaName}/runtime/plugins`]: pluginsExportsUtils.getPath(),
89
- "@meta/runtime/browser": "@modern-js/runtime/browser",
90
- "@meta/runtime/react": "@modern-js/runtime/react",
91
- "@meta/runtime/context": "@modern-js/runtime/context",
92
- "@meta/runtime": "@modern-js/runtime"
89
+ "@meta/runtime/browser": require.resolve("@modern-js/runtime/browser"),
90
+ "@meta/runtime/react": require.resolve("@modern-js/runtime/react"),
91
+ "@meta/runtime/context": require.resolve("@modern-js/runtime/context"),
92
+ "@meta/runtime": require.resolve("@modern-js/runtime")
93
93
  },
94
94
  globalVars: {
95
95
  "process.env.IS_REACT18": process.env.IS_REACT18
@@ -1,12 +1,11 @@
1
- import React, { useEffect, useState } from "react";
2
- let csr = false;
1
+ import React from "react";
2
+ import { useEffect, useState } from "react";
3
3
  const NoSSR = (props) => {
4
- const [isMounted, setMounted] = useState(csr);
4
+ const [isMounted, setMounted] = useState(false);
5
5
  useEffect(() => {
6
- csr = true;
7
6
  setMounted(true);
8
- });
9
- const { children, fallback = null } = props;
7
+ }, []);
8
+ const { children, fallback = null } = props || {};
10
9
  return React.createElement(React.Fragment, null, isMounted ? children : fallback);
11
10
  };
12
11
  export {
@@ -1,6 +1,7 @@
1
1
  import path from "path";
2
- import { fs, filterRoutesForServer, filterRoutesLoader, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
2
+ import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
3
3
  import { cloneDeep } from "@modern-js/utils/lodash";
4
+ import { filterRoutesForServer, filterRoutesLoader, markRoutes } from "@modern-js/utils/universal/route";
4
5
  import { ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME } from "../../../cli/constants";
5
6
  import { FILE_SYSTEM_ROUTES_FILE_NAME } from "../constants";
6
7
  import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
@@ -111,25 +112,6 @@ const generateCode = async (appContext, config, entrypoints, api) => {
111
112
  }
112
113
  }
113
114
  };
114
- function markRoutes(routes, routeIds) {
115
- return routes.map((route) => {
116
- if (route.type !== "nested") {
117
- return route;
118
- }
119
- if (route.children && route.children.length > 0) {
120
- route.children = markRoutes(route.children, routeIds);
121
- }
122
- if (route.children && route.children.length > 0) {
123
- route.inValidSSRRoute = route.children.every((child) => {
124
- var _child_inValidSSRRoute;
125
- return (_child_inValidSSRRoute = child.inValidSSRRoute) !== null && _child_inValidSSRRoute !== void 0 ? _child_inValidSSRRoute : false;
126
- });
127
- } else if (route.id) {
128
- route.inValidSSRRoute = !routeIds.includes(route.id);
129
- }
130
- return route;
131
- });
132
- }
133
115
  function generatorRegisterCode(internalDirectory, entryName, code) {
134
116
  fs.outputFileSync(path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME}`), code, "utf8");
135
117
  }
@@ -1,5 +1,6 @@
1
1
  import path from "node:path";
2
- import { fs, NESTED_ROUTE_SPEC_FILE, createRuntimeExportsUtils, filterRoutesForServer, getEntryOptions, isRouterV5 as isV5 } from "@modern-js/utils";
2
+ import { fs, NESTED_ROUTE_SPEC_FILE, createRuntimeExportsUtils, getEntryOptions, isRouterV5 as isV5 } from "@modern-js/utils";
3
+ import { filterRoutesForServer } from "@modern-js/utils/universal/route";
3
4
  import { isRouteEntry } from "./entry";
4
5
  import { handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints } from "./handler";
5
6
  import { isRouteEntry as isRouteEntry2 } from "./entry";
@@ -58,8 +58,8 @@ const routerPlugin = (userConfig = {}) => {
58
58
  const useCreateRouter = (props) => {
59
59
  var _window__SERVER_DATA;
60
60
  const runtimeContext = useContext(RuntimeReactContext);
61
- const baseUrl = (runtimeContext._internalRouterBaseName || ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname)).replace(/^\/*/, "/");
62
- const _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
61
+ const baseUrl = (((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname)).replace(/^\/*/, "/");
62
+ const _basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename) : baseUrl;
63
63
  let hydrationData = window._ROUTER_DATA;
64
64
  const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
65
65
  return useMemo(() => {
@@ -1,6 +1,5 @@
1
- import React, { type ReactElement } from 'react';
2
- export declare const NoSSR: (props: React.PropsWithChildren<{
1
+ import React from 'react';
2
+ import { type ReactElement } from 'react';
3
+ export declare const NoSSR: (props?: React.PropsWithChildren<{
3
4
  fallback?: ReactElement | string;
4
- }>) => React.FunctionComponentElement<{
5
- children?: React.ReactNode;
6
- }>;
5
+ }>) => ReactElement | null;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.60.1-alpha.0",
18
+ "version": "2.60.1-alpha.2",
19
19
  "engines": {
20
20
  "node": ">=14.17.6"
21
21
  },
@@ -200,10 +200,10 @@
200
200
  "react-side-effect": "^2.1.1",
201
201
  "styled-components": "^5.3.1",
202
202
  "@modern-js/plugin": "2.60.0",
203
- "@modern-js/types": "2.60.0",
204
203
  "@modern-js/runtime-utils": "2.60.0",
205
- "@modern-js/utils": "2.60.0",
206
- "@modern-js/plugin-data-loader": "2.60.0"
204
+ "@modern-js/types": "2.60.0",
205
+ "@modern-js/plugin-data-loader": "2.60.0",
206
+ "@modern-js/utils": "2.60.0"
207
207
  },
208
208
  "peerDependencies": {
209
209
  "react": ">=17",
@@ -226,10 +226,10 @@
226
226
  "ts-jest": "^29.1.0",
227
227
  "typescript": "^5",
228
228
  "webpack": "^5.94.0",
229
- "@scripts/build": "2.60.0",
230
229
  "@modern-js/app-tools": "2.60.0",
230
+ "@scripts/jest-config": "2.60.0",
231
231
  "@modern-js/core": "2.60.0",
232
- "@scripts/jest-config": "2.60.0"
232
+ "@scripts/build": "2.60.0"
233
233
  },
234
234
  "sideEffects": false,
235
235
  "publishConfig": {