@modern-js/server-core 2.69.5 → 2.69.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.
@@ -130,15 +130,13 @@ async function getRscSSRManifest(pwd) {
130
130
  const rscSSRManifest = await (0, import_utils.compatibleRequire)(import_path.default.join(pwd, "react-ssr-manifest.json")).catch((_) => void 0);
131
131
  return rscSSRManifest;
132
132
  }
133
- const injectRscManifestPlugin = () => ({
133
+ const injectRscManifestPlugin = (enableRsc) => ({
134
134
  name: "@modern-js/plugin-inject-rsc-manifest",
135
135
  setup(api) {
136
136
  return {
137
137
  async prepare() {
138
- var _config_server;
139
138
  const { middlewares, distDirectory: pwd } = api.useAppContext();
140
- const config = api.useConfigContext();
141
- if (!((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.rsc)) {
139
+ if (!enableRsc) {
142
140
  return;
143
141
  }
144
142
  middlewares.push({
@@ -28,6 +28,10 @@ var import_utils = require("../../utils");
28
28
  var import_customServer = require("../customServer");
29
29
  var import_monitors = require("../monitors");
30
30
  __reExport(render_exports, require("./inject"), module.exports);
31
+ const DYNAMIC_ROUTE_REG = /\/:./;
32
+ function escapeRegexSpecialChars(path) {
33
+ return path.replace(/[()[\]{}*+?.^$|\\]/g, "\\$&");
34
+ }
31
35
  const renderPlugin = () => ({
32
36
  name: "@modern-js/plugin-render",
33
37
  setup(api) {
@@ -48,7 +52,9 @@ const renderPlugin = () => ({
48
52
  for (const route of pageRoutes) {
49
53
  var _config_server;
50
54
  const { urlPath: originUrlPath, entryName = import_constants.MAIN_ENTRY_NAME } = route;
51
- const urlPath = originUrlPath.endsWith("/") ? `${originUrlPath}*` : `${originUrlPath}/*`;
55
+ const isDynamic = DYNAMIC_ROUTE_REG.test(originUrlPath);
56
+ const escapedPath = isDynamic ? originUrlPath : escapeRegexSpecialChars(originUrlPath);
57
+ const urlPath = escapedPath.endsWith("/") ? `${escapedPath}*` : `${escapedPath}/*`;
52
58
  if (((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.disableHook) !== true) {
53
59
  const customServerHookMiddleware = customServer.getHookMiddleware(entryName, routes);
54
60
  middlewares.push({
@@ -269,7 +269,7 @@ function injectFallbackReasonToHtml({ html, reason, framework }) {
269
269
  }
270
270
  async function csrRender(request, options) {
271
271
  const { html, rscClientManifest } = options;
272
- if (!rscClientManifest || process.env.MODERN_DISABLE_INJECT_RSC_DATA) {
272
+ if (!rscClientManifest || process.env.MODERN_DISABLE_INJECT_RSC_DATA || !options.routeInfo.isRSC) {
273
273
  return new Response(html, {
274
274
  status: 200,
275
275
  headers: new Headers({
@@ -51,7 +51,8 @@ const injectRoutePlugin = () => ({
51
51
  name: "inject-route-info",
52
52
  path: urlPath,
53
53
  handler: injectRoute({
54
- entryName
54
+ entryName,
55
+ urlPath: originUrlPath
55
56
  })
56
57
  });
57
58
  }
@@ -405,18 +405,17 @@ function _getRscSSRManifest() {
405
405
  });
406
406
  return _getRscSSRManifest.apply(this, arguments);
407
407
  }
408
- var injectRscManifestPlugin = function() {
408
+ var injectRscManifestPlugin = function(enableRsc) {
409
409
  return {
410
410
  name: "@modern-js/plugin-inject-rsc-manifest",
411
411
  setup: function setup(api) {
412
412
  return {
413
413
  prepare: function prepare() {
414
414
  return _async_to_generator(function() {
415
- var _config_server, _api_useAppContext, middlewares, pwd, config;
415
+ var _api_useAppContext, middlewares, pwd;
416
416
  return _ts_generator(this, function(_state) {
417
417
  _api_useAppContext = api.useAppContext(), middlewares = _api_useAppContext.middlewares, pwd = _api_useAppContext.distDirectory;
418
- config = api.useConfigContext();
419
- if (!((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.rsc)) {
418
+ if (!enableRsc) {
420
419
  return [
421
420
  2
422
421
  ];
@@ -7,6 +7,10 @@ import { sortRoutes } from "../../utils";
7
7
  import { CustomServer } from "../customServer";
8
8
  import { requestLatencyMiddleware } from "../monitors";
9
9
  export * from "./inject";
10
+ var DYNAMIC_ROUTE_REG = /\/:./;
11
+ function escapeRegexSpecialChars(path) {
12
+ return path.replace(/[()[\]{}*+?.^$|\\]/g, "\\$&");
13
+ }
10
14
  var renderPlugin = function() {
11
15
  return {
12
16
  name: "@modern-js/plugin-render",
@@ -42,13 +46,15 @@ var renderPlugin = function() {
42
46
  8
43
47
  ]);
44
48
  _loop = function() {
45
- var route, _config_server, originUrlPath, _route_entryName, entryName, urlPath, customServerHookMiddleware, customServerMiddleware;
49
+ var route, _config_server, originUrlPath, _route_entryName, entryName, isDynamic, escapedPath, urlPath, customServerHookMiddleware, customServerMiddleware;
46
50
  return _ts_generator(this, function(_state2) {
47
51
  switch (_state2.label) {
48
52
  case 0:
49
53
  route = _step.value;
50
54
  originUrlPath = route.urlPath, _route_entryName = route.entryName, entryName = _route_entryName === void 0 ? MAIN_ENTRY_NAME : _route_entryName;
51
- urlPath = originUrlPath.endsWith("/") ? "".concat(originUrlPath, "*") : "".concat(originUrlPath, "/*");
55
+ isDynamic = DYNAMIC_ROUTE_REG.test(originUrlPath);
56
+ escapedPath = isDynamic ? originUrlPath : escapeRegexSpecialChars(originUrlPath);
57
+ urlPath = escapedPath.endsWith("/") ? "".concat(escapedPath, "*") : "".concat(escapedPath, "/*");
52
58
  if (((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.disableHook) !== true) {
53
59
  customServerHookMiddleware = customServer.getHookMiddleware(entryName, routes);
54
60
  middlewares.push({
@@ -544,7 +544,7 @@ function _csrRender() {
544
544
  var html, rscClientManifest;
545
545
  return _ts_generator(this, function(_state) {
546
546
  html = options.html, rscClientManifest = options.rscClientManifest;
547
- if (!rscClientManifest || process.env.MODERN_DISABLE_INJECT_RSC_DATA) {
547
+ if (!rscClientManifest || process.env.MODERN_DISABLE_INJECT_RSC_DATA || !options.routeInfo.isRSC) {
548
548
  return [
549
549
  2,
550
550
  new Response(html, {
@@ -59,7 +59,8 @@ var injectRoutePlugin = function() {
59
59
  name: "inject-route-info",
60
60
  path: urlPath,
61
61
  handler: injectRoute({
62
- entryName
62
+ entryName,
63
+ urlPath: originUrlPath
63
64
  })
64
65
  });
65
66
  }
@@ -89,15 +89,13 @@ async function getRscSSRManifest(pwd) {
89
89
  const rscSSRManifest = await compatibleRequire(path.join(pwd, "react-ssr-manifest.json")).catch((_) => void 0);
90
90
  return rscSSRManifest;
91
91
  }
92
- const injectRscManifestPlugin = () => ({
92
+ const injectRscManifestPlugin = (enableRsc) => ({
93
93
  name: "@modern-js/plugin-inject-rsc-manifest",
94
94
  setup(api) {
95
95
  return {
96
96
  async prepare() {
97
- var _config_server;
98
97
  const { middlewares, distDirectory: pwd } = api.useAppContext();
99
- const config = api.useConfigContext();
100
- if (!((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.rsc)) {
98
+ if (!enableRsc) {
101
99
  return;
102
100
  }
103
101
  middlewares.push({
@@ -4,6 +4,10 @@ import { sortRoutes } from "../../utils";
4
4
  import { CustomServer } from "../customServer";
5
5
  import { requestLatencyMiddleware } from "../monitors";
6
6
  export * from "./inject";
7
+ const DYNAMIC_ROUTE_REG = /\/:./;
8
+ function escapeRegexSpecialChars(path) {
9
+ return path.replace(/[()[\]{}*+?.^$|\\]/g, "\\$&");
10
+ }
7
11
  const renderPlugin = () => ({
8
12
  name: "@modern-js/plugin-render",
9
13
  setup(api) {
@@ -24,7 +28,9 @@ const renderPlugin = () => ({
24
28
  for (const route of pageRoutes) {
25
29
  var _config_server;
26
30
  const { urlPath: originUrlPath, entryName = MAIN_ENTRY_NAME } = route;
27
- const urlPath = originUrlPath.endsWith("/") ? `${originUrlPath}*` : `${originUrlPath}/*`;
31
+ const isDynamic = DYNAMIC_ROUTE_REG.test(originUrlPath);
32
+ const escapedPath = isDynamic ? originUrlPath : escapeRegexSpecialChars(originUrlPath);
33
+ const urlPath = escapedPath.endsWith("/") ? `${escapedPath}*` : `${escapedPath}/*`;
28
34
  if (((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.disableHook) !== true) {
29
35
  const customServerHookMiddleware = customServer.getHookMiddleware(entryName, routes);
30
36
  middlewares.push({
@@ -236,7 +236,7 @@ function injectFallbackReasonToHtml({ html, reason, framework }) {
236
236
  }
237
237
  async function csrRender(request, options) {
238
238
  const { html, rscClientManifest } = options;
239
- if (!rscClientManifest || process.env.MODERN_DISABLE_INJECT_RSC_DATA) {
239
+ if (!rscClientManifest || process.env.MODERN_DISABLE_INJECT_RSC_DATA || !options.routeInfo.isRSC) {
240
240
  return new Response(html, {
241
241
  status: 200,
242
242
  headers: new Headers({
@@ -28,7 +28,8 @@ const injectRoutePlugin = () => ({
28
28
  name: "inject-route-info",
29
29
  path: urlPath,
30
30
  handler: injectRoute({
31
- entryName
31
+ entryName,
32
+ urlPath: originUrlPath
32
33
  })
33
34
  });
34
35
  }
@@ -7,5 +7,5 @@ export declare function injectServerManifest(pwd: string, routes?: ServerRoute[]
7
7
  export declare function getRscServerManifest(pwd: string): Promise<any>;
8
8
  export declare function getClientManifest(pwd: string): Promise<any>;
9
9
  export declare function getRscSSRManifest(pwd: string): Promise<any>;
10
- export declare const injectRscManifestPlugin: () => ServerPluginLegacy;
10
+ export declare const injectRscManifestPlugin: (enableRsc: boolean) => ServerPluginLegacy;
11
11
  export declare const injectResourcePlugin: () => ServerPluginLegacy;
@@ -58,9 +58,9 @@ type ServerVariables = {
58
58
  */
59
59
  locals?: Record<string, any>;
60
60
  /**
61
- * The current matched route, now only expose entryName field.
61
+ * The current matched route, now only expose entryName and urlPath.
62
62
  */
63
- route: Required<Pick<ServerRoute, 'entryName'>>;
63
+ route: Required<Pick<ServerRoute, 'entryName' | 'urlPath'>>;
64
64
  };
65
65
  export type ServerEnv = {
66
66
  Variables: ServerVariables;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.69.5",
18
+ "version": "2.69.7",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -62,10 +62,10 @@
62
62
  "flatted": "^3.3.3",
63
63
  "hono": "^3.12.2",
64
64
  "ts-deepmerge": "7.0.2",
65
- "@modern-js/plugin": "2.69.5",
66
- "@modern-js/plugin-v2": "2.69.5",
67
- "@modern-js/runtime-utils": "2.69.5",
68
- "@modern-js/utils": "2.69.5"
65
+ "@modern-js/plugin": "2.69.7",
66
+ "@modern-js/plugin-v2": "2.69.7",
67
+ "@modern-js/runtime-utils": "2.69.7",
68
+ "@modern-js/utils": "2.69.7"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/cloneable-readable": "^2.0.3",
@@ -76,8 +76,8 @@
76
76
  "jest": "^29",
77
77
  "ts-jest": "^29.1.0",
78
78
  "typescript": "^5",
79
+ "@modern-js/types": "2.69.7",
79
80
  "@scripts/build": "2.66.0",
80
- "@modern-js/types": "2.69.5",
81
81
  "@scripts/jest-config": "2.66.0"
82
82
  },
83
83
  "sideEffects": false,