@modern-js/runtime 3.9.3 → 3.10.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.
@@ -85,6 +85,11 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
85
85
  module: isServerEnvironment && outputModule
86
86
  },
87
87
  tools: {
88
+ rspack: isServerEnvironment && (0, utils_namespaceObject.isUseSSRBundle)(userConfig) ? {
89
+ output: {
90
+ strictModuleErrorHandling: true
91
+ }
92
+ } : void 0,
88
93
  bundlerChain: useLoadablePlugin ? (chain)=>{
89
94
  chain.plugin('loadable').use(external_loadable_bundler_plugin_js_default(), [
90
95
  {
@@ -42,6 +42,7 @@ __webpack_require__.d(__webpack_exports__, {
42
42
  const external_path_namespaceObject = require("path");
43
43
  var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
44
44
  const utils_namespaceObject = require("@modern-js/utils");
45
+ const DEFAULT_CHUNK_LOADING_GLOBAL = '__LOADABLE_LOADED_CHUNKS__';
45
46
  const normalizeChunkId = (id)=>'string' == typeof id && /^\d+$/.test(id) ? Number(id) : id;
46
47
  const normalizeChunkGroup = (group)=>({
47
48
  ...group,
@@ -50,7 +51,16 @@ const normalizeChunkGroup = (group)=>({
50
51
  class LoadablePlugin {
51
52
  apply(compiler) {
52
53
  this.compiler = compiler;
53
- compiler.options.output.chunkLoadingGlobal = this.opts.chunkLoadingGlobal;
54
+ if (this.opts.chunkLoadingGlobal) compiler.options.output.chunkLoadingGlobal = this.opts.chunkLoadingGlobal;
55
+ compiler.hooks.initialize.tap({
56
+ name: LoadablePlugin.name,
57
+ stage: 1 / 0
58
+ }, ()=>{
59
+ const chunkLoadingGlobal = compiler.options.output.chunkLoadingGlobal || DEFAULT_CHUNK_LOADING_GLOBAL;
60
+ new compiler.webpack.DefinePlugin({
61
+ 'process.env.MODERN_CHUNK_LOADING_GLOBAL': JSON.stringify(chunkLoadingGlobal)
62
+ }).apply(compiler);
63
+ });
54
64
  if (this.opts.outputAsset || this.opts.writeToDisk) compiler.hooks.make.tap(LoadablePlugin.name, (compilation)=>{
55
65
  compilation.hooks.processAssets.tap({
56
66
  name: LoadablePlugin.name,
@@ -110,10 +120,9 @@ class LoadablePlugin {
110
120
  const outputFile = external_path_default().resolve(outputFolder || '', this.opts.filename);
111
121
  utils_namespaceObject.fs.outputFileSync(outputFile, manifest);
112
122
  }
113
- constructor({ filename = 'loadable-stats.json', path, writeToDisk, outputAsset = true, chunkLoadingGlobal = '__LOADABLE_LOADED_CHUNKS__' } = {
123
+ constructor({ filename = 'loadable-stats.json', path, writeToDisk, outputAsset = true, chunkLoadingGlobal } = {
114
124
  filename: 'loadable-stats.json',
115
- outputAsset: true,
116
- chunkLoadingGlobal: '__LOADABLE_LOADED_CHUNKS__'
125
+ outputAsset: true
117
126
  }){
118
127
  this.opts = {
119
128
  filename,
@@ -80,6 +80,8 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
80
80
  ModernHydrate((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SSRApp, {}), hydrateContext)).then((root)=>{
81
81
  resolve(root);
82
82
  });
83
+ }, {
84
+ chunkLoadingGlobal: process.env.MODERN_CHUNK_LOADING_GLOBAL
83
85
  });
84
86
  });
85
87
  console.warn(`unknow render level: ${renderLevel}, execute render()`);
@@ -157,7 +157,7 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
157
157
  };
158
158
  const createLazyImport = ({ componentPath, routeId, webpackChunkName, eager })=>{
159
159
  const importOptions = webpackChunkName ? `/* webpackChunkName: "${routeId}" */ ` : eager ? '/* webpackMode: "eager" */ ' : '';
160
- return `() => import(${importOptions}'${componentPath}').then(routeModule => handleRouteModule(routeModule, "${routeId}")).catch(handleRouteModuleError)`;
160
+ return `() => import(${importOptions}'${componentPath}').then(routeModule => handleRouteModule(routeModule, "${routeId}"))`;
161
161
  };
162
162
  const traverseRouteTree = async (route, isRscClientBundle)=>{
163
163
  let children;
@@ -326,7 +326,7 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
326
326
  await utils_namespaceObject.fs.ensureFile(loadersMapFile);
327
327
  await utils_namespaceObject.fs.writeJSON(loadersMapFile, loadersMap);
328
328
  const importRuntimeRouterCode = `
329
- import { createShouldRevalidate, handleRouteModule, handleRouteModuleError} from '@${metaName}/runtime/routerHelper';
329
+ import { createShouldRevalidate, handleRouteModule } from '@${metaName}/runtime/routerHelper';
330
330
  `;
331
331
  const routeModulesCode = `
332
332
  if(typeof document !== 'undefined'){
@@ -41,6 +41,11 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
41
41
  module: isServerEnvironment && outputModule
42
42
  },
43
43
  tools: {
44
+ rspack: isServerEnvironment && isUseSSRBundle(userConfig) ? {
45
+ output: {
46
+ strictModuleErrorHandling: true
47
+ }
48
+ } : void 0,
44
49
  bundlerChain: useLoadablePlugin ? (chain)=>{
45
50
  chain.plugin('loadable').use(loadable_bundler_plugin, [
46
51
  {
@@ -1,5 +1,6 @@
1
1
  import path_0 from "path";
2
2
  import { fs } from "@modern-js/utils";
3
+ const DEFAULT_CHUNK_LOADING_GLOBAL = '__LOADABLE_LOADED_CHUNKS__';
3
4
  const normalizeChunkId = (id)=>'string' == typeof id && /^\d+$/.test(id) ? Number(id) : id;
4
5
  const normalizeChunkGroup = (group)=>({
5
6
  ...group,
@@ -8,7 +9,16 @@ const normalizeChunkGroup = (group)=>({
8
9
  class LoadablePlugin {
9
10
  apply(compiler) {
10
11
  this.compiler = compiler;
11
- compiler.options.output.chunkLoadingGlobal = this.opts.chunkLoadingGlobal;
12
+ if (this.opts.chunkLoadingGlobal) compiler.options.output.chunkLoadingGlobal = this.opts.chunkLoadingGlobal;
13
+ compiler.hooks.initialize.tap({
14
+ name: LoadablePlugin.name,
15
+ stage: 1 / 0
16
+ }, ()=>{
17
+ const chunkLoadingGlobal = compiler.options.output.chunkLoadingGlobal || DEFAULT_CHUNK_LOADING_GLOBAL;
18
+ new compiler.webpack.DefinePlugin({
19
+ 'process.env.MODERN_CHUNK_LOADING_GLOBAL': JSON.stringify(chunkLoadingGlobal)
20
+ }).apply(compiler);
21
+ });
12
22
  if (this.opts.outputAsset || this.opts.writeToDisk) compiler.hooks.make.tap(LoadablePlugin.name, (compilation)=>{
13
23
  compilation.hooks.processAssets.tap({
14
24
  name: LoadablePlugin.name,
@@ -68,10 +78,9 @@ class LoadablePlugin {
68
78
  const outputFile = path_0.resolve(outputFolder || '', this.opts.filename);
69
79
  fs.outputFileSync(outputFile, manifest);
70
80
  }
71
- constructor({ filename = 'loadable-stats.json', path, writeToDisk, outputAsset = true, chunkLoadingGlobal = '__LOADABLE_LOADED_CHUNKS__' } = {
81
+ constructor({ filename = 'loadable-stats.json', path, writeToDisk, outputAsset = true, chunkLoadingGlobal } = {
72
82
  filename: 'loadable-stats.json',
73
- outputAsset: true,
74
- chunkLoadingGlobal: '__LOADABLE_LOADED_CHUNKS__'
83
+ outputAsset: true
75
84
  }){
76
85
  this.opts = {
77
86
  filename,
@@ -47,6 +47,8 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
47
47
  ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
48
48
  resolve(root);
49
49
  });
50
+ }, {
51
+ chunkLoadingGlobal: process.env.MODERN_CHUNK_LOADING_GLOBAL
50
52
  });
51
53
  });
52
54
  console.warn(`unknow render level: ${renderLevel}, execute render()`);
@@ -112,7 +112,7 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
112
112
  };
113
113
  const createLazyImport = ({ componentPath, routeId, webpackChunkName, eager })=>{
114
114
  const importOptions = webpackChunkName ? `/* webpackChunkName: "${routeId}" */ ` : eager ? '/* webpackMode: "eager" */ ' : '';
115
- return `() => import(${importOptions}'${componentPath}').then(routeModule => handleRouteModule(routeModule, "${routeId}")).catch(handleRouteModuleError)`;
115
+ return `() => import(${importOptions}'${componentPath}').then(routeModule => handleRouteModule(routeModule, "${routeId}"))`;
116
116
  };
117
117
  const traverseRouteTree = async (route, isRscClientBundle)=>{
118
118
  let children;
@@ -281,7 +281,7 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
281
281
  await fs.ensureFile(loadersMapFile);
282
282
  await fs.writeJSON(loadersMapFile, loadersMap);
283
283
  const importRuntimeRouterCode = `
284
- import { createShouldRevalidate, handleRouteModule, handleRouteModuleError} from '@${metaName}/runtime/routerHelper';
284
+ import { createShouldRevalidate, handleRouteModule } from '@${metaName}/runtime/routerHelper';
285
285
  `;
286
286
  const routeModulesCode = `
287
287
  if(typeof document !== 'undefined'){
@@ -43,6 +43,11 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
43
43
  module: isServerEnvironment && outputModule
44
44
  },
45
45
  tools: {
46
+ rspack: isServerEnvironment && isUseSSRBundle(userConfig) ? {
47
+ output: {
48
+ strictModuleErrorHandling: true
49
+ }
50
+ } : void 0,
46
51
  bundlerChain: useLoadablePlugin ? (chain)=>{
47
52
  chain.plugin('loadable').use(loadable_bundler_plugin, [
48
53
  {
@@ -1,6 +1,7 @@
1
1
  import "node:module";
2
2
  import path_0 from "path";
3
3
  import { fs } from "@modern-js/utils";
4
+ const DEFAULT_CHUNK_LOADING_GLOBAL = '__LOADABLE_LOADED_CHUNKS__';
4
5
  const normalizeChunkId = (id)=>'string' == typeof id && /^\d+$/.test(id) ? Number(id) : id;
5
6
  const normalizeChunkGroup = (group)=>({
6
7
  ...group,
@@ -9,7 +10,16 @@ const normalizeChunkGroup = (group)=>({
9
10
  class LoadablePlugin {
10
11
  apply(compiler) {
11
12
  this.compiler = compiler;
12
- compiler.options.output.chunkLoadingGlobal = this.opts.chunkLoadingGlobal;
13
+ if (this.opts.chunkLoadingGlobal) compiler.options.output.chunkLoadingGlobal = this.opts.chunkLoadingGlobal;
14
+ compiler.hooks.initialize.tap({
15
+ name: LoadablePlugin.name,
16
+ stage: 1 / 0
17
+ }, ()=>{
18
+ const chunkLoadingGlobal = compiler.options.output.chunkLoadingGlobal || DEFAULT_CHUNK_LOADING_GLOBAL;
19
+ new compiler.webpack.DefinePlugin({
20
+ 'process.env.MODERN_CHUNK_LOADING_GLOBAL': JSON.stringify(chunkLoadingGlobal)
21
+ }).apply(compiler);
22
+ });
13
23
  if (this.opts.outputAsset || this.opts.writeToDisk) compiler.hooks.make.tap(LoadablePlugin.name, (compilation)=>{
14
24
  compilation.hooks.processAssets.tap({
15
25
  name: LoadablePlugin.name,
@@ -69,10 +79,9 @@ class LoadablePlugin {
69
79
  const outputFile = path_0.resolve(outputFolder || '', this.opts.filename);
70
80
  fs.outputFileSync(outputFile, manifest);
71
81
  }
72
- constructor({ filename = 'loadable-stats.json', path, writeToDisk, outputAsset = true, chunkLoadingGlobal = '__LOADABLE_LOADED_CHUNKS__' } = {
82
+ constructor({ filename = 'loadable-stats.json', path, writeToDisk, outputAsset = true, chunkLoadingGlobal } = {
73
83
  filename: 'loadable-stats.json',
74
- outputAsset: true,
75
- chunkLoadingGlobal: '__LOADABLE_LOADED_CHUNKS__'
84
+ outputAsset: true
76
85
  }){
77
86
  this.opts = {
78
87
  filename,
@@ -48,6 +48,8 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
48
48
  ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
49
49
  resolve(root);
50
50
  });
51
+ }, {
52
+ chunkLoadingGlobal: process.env.MODERN_CHUNK_LOADING_GLOBAL
51
53
  });
52
54
  });
53
55
  console.warn(`unknow render level: ${renderLevel}, execute render()`);
@@ -114,7 +114,7 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
114
114
  };
115
115
  const createLazyImport = ({ componentPath, routeId, webpackChunkName, eager })=>{
116
116
  const importOptions = webpackChunkName ? `/* webpackChunkName: "${routeId}" */ ` : eager ? '/* webpackMode: "eager" */ ' : '';
117
- return `() => import(${importOptions}'${componentPath}').then(routeModule => handleRouteModule(routeModule, "${routeId}")).catch(handleRouteModuleError)`;
117
+ return `() => import(${importOptions}'${componentPath}').then(routeModule => handleRouteModule(routeModule, "${routeId}"))`;
118
118
  };
119
119
  const traverseRouteTree = async (route, isRscClientBundle)=>{
120
120
  let children;
@@ -283,7 +283,7 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
283
283
  await fs.ensureFile(loadersMapFile);
284
284
  await fs.writeJSON(loadersMapFile, loadersMap);
285
285
  const importRuntimeRouterCode = `
286
- import { createShouldRevalidate, handleRouteModule, handleRouteModuleError} from '@${metaName}/runtime/routerHelper';
286
+ import { createShouldRevalidate, handleRouteModule } from '@${metaName}/runtime/routerHelper';
287
287
  `;
288
288
  const routeModulesCode = `
289
289
  if(typeof document !== 'undefined'){
@@ -36,7 +36,7 @@ interface GlobalContext {
36
36
  serverPayload?: ServerPayload;
37
37
  enableRsc?: boolean;
38
38
  }
39
- export { getServerPayload, setServerPayload, } from './serverPayload/index.js';
39
+ export { getServerPayload, setServerPayload } from './serverPayload/index.js';
40
40
  export declare function getGlobalIsRscClient(): boolean | undefined;
41
41
  export declare function getGlobalEnableRsc(): boolean | undefined;
42
42
  export declare function setGlobalContext(context: Omit<GlobalContext, 'internalRuntimeContext'>): void;
@@ -1,5 +1,5 @@
1
1
  export type { RuntimePlugin } from './plugin/index.js';
2
2
  export { defineRuntimeConfig } from './config.js';
3
3
  export type { TRuntimeContext } from './context/runtime.js';
4
- export { RuntimeContext, useRuntimeContext, } from './context/runtime.js';
4
+ export { RuntimeContext, useRuntimeContext } from './context/runtime.js';
5
5
  export type { SSRData, SSRContainer } from './types.js';
@@ -6,5 +6,5 @@ export type { TRuntimeContext } from './core/context/runtime.js';
6
6
  export { getMonitors } from './core/context/monitors/index.js';
7
7
  export { getRequest } from './core/context/request/index.js';
8
8
  export { setHeaders, setStatus, redirect } from './core/context/response/index.js';
9
- export { RuntimeContext, defineRuntimeConfig, useRuntimeContext, } from './core/index.js';
9
+ export { RuntimeContext, defineRuntimeConfig, useRuntimeContext } from './core/index.js';
10
10
  export type { RouterConfig };
@@ -2,4 +2,9 @@ import type Module from 'module';
2
2
  import type { ShouldRevalidateFunction } from '@modern-js/runtime-utils/router';
3
3
  export declare const createShouldRevalidate: (routeId: string) => ShouldRevalidateFunction;
4
4
  export declare const handleRouteModule: (routeModule: Module, routeId: string) => Module;
5
+ /**
6
+ * @deprecated Generated routes no longer use this. Swallowing the import error
7
+ * here replaced a `ChunkLoadError` with an unrelated `TypeError` by the time it
8
+ * reached the route error boundary. Kept only for code that imports it directly.
9
+ */
5
10
  export declare const handleRouteModuleError: (error: Error) => null;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.9.3",
18
+ "version": "3.10.0",
19
19
  "engines": {
20
20
  "node": ">=20"
21
21
  },
@@ -203,7 +203,7 @@
203
203
  "dependencies": {
204
204
  "@loadable/component": "5.16.7",
205
205
  "@loadable/server": "5.16.7",
206
- "@swc/core": "1.15.41",
206
+ "@swc/core": "1.16.18",
207
207
  "@swc/helpers": "^0.5.17",
208
208
  "@swc/plugin-loadable-components": "^12.0.0",
209
209
  "@types/loadable__component": "^5.13.10",
@@ -215,12 +215,12 @@
215
215
  "isbot": "3.8.0",
216
216
  "react-helmet": "^6.1.0",
217
217
  "react-is": "^18.3.1",
218
- "@modern-js/plugin": "3.9.3",
219
- "@modern-js/plugin-data-loader": "3.9.3",
220
- "@modern-js/render": "3.9.3",
221
- "@modern-js/runtime-utils": "3.9.3",
222
- "@modern-js/types": "3.9.3",
223
- "@modern-js/utils": "3.9.3"
218
+ "@modern-js/plugin": "3.10.0",
219
+ "@modern-js/plugin-data-loader": "3.10.0",
220
+ "@modern-js/render": "3.10.0",
221
+ "@modern-js/runtime-utils": "3.10.0",
222
+ "@modern-js/types": "3.10.0",
223
+ "@modern-js/utils": "3.10.0"
224
224
  },
225
225
  "peerDependencies": {
226
226
  "react": ">=18.3.1",
@@ -228,19 +228,18 @@
228
228
  },
229
229
  "devDependencies": {
230
230
  "@remix-run/web-fetch": "^4.1.3",
231
- "@rsbuild/core": "2.2.9",
232
- "@rslib/core": "1.0.1",
231
+ "@rsbuild/core": "2.2.13",
233
232
  "@testing-library/dom": "^10.4.2",
234
233
  "@testing-library/react": "^16.3.3",
235
234
  "@types/cookie": "0.6.0",
236
235
  "@types/invariant": "^2.2.37",
237
236
  "@types/loadable__server": "5.12.11",
238
237
  "@types/node": "^20",
239
- "react": "^19.2.8",
240
- "react-dom": "^19.2.8",
238
+ "react": "^19.3.0",
239
+ "react-dom": "^19.3.0",
241
240
  "ts-node": "^10.9.2",
242
241
  "typescript": "^5",
243
- "@modern-js/app-tools": "3.9.3",
242
+ "@modern-js/app-tools": "3.10.0",
244
243
  "@modern-js/rslib": "2.68.10",
245
244
  "@scripts/rstest-config": "2.66.0"
246
245
  },
@@ -250,8 +249,8 @@
250
249
  "access": "public"
251
250
  },
252
251
  "scripts": {
253
- "dev": "rslib build --watch",
254
- "build": "rslib build && pnpm run gen-static",
252
+ "dev": "rs lib --watch",
253
+ "build": "rs lib && pnpm run gen-static",
255
254
  "gen-static": "ts-node ./scripts/gen-static.ts",
256
255
  "test": "rstest"
257
256
  }
@@ -1,7 +1,7 @@
1
1
  import { rslibConfig } from '@modern-js/rslib';
2
- import { defineConfig } from '@rslib/core';
2
+ import { define } from 'rstack';
3
3
 
4
- export default defineConfig({
4
+ define.lib({
5
5
  ...rslibConfig,
6
6
  source: {
7
7
  define: {
package/rstest.config.mts CHANGED
@@ -57,7 +57,10 @@ export default {
57
57
  ({
58
58
  code,
59
59
  resourcePath,
60
- }: { code: string; resourcePath: string }) => {
60
+ }: {
61
+ code: string;
62
+ resourcePath: string;
63
+ }) => {
61
64
  return code.replace(
62
65
  '__webpack_chunk_load__',
63
66
  '__webpack_chunk_load_test__',