@modern-js/runtime 2.68.7 → 2.68.9

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.
@@ -76,7 +76,7 @@ const optimizeRoute = (routeTree) => {
76
76
  const { children } = routeTree;
77
77
  if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config && !routeTree.clientData) {
78
78
  const newRoutes = children.map((child) => {
79
- const routePath = `${routeTree.path ? routeTree.path : ""}${child.path ? `/${child.path}` : ""}`;
79
+ const routePath = routeTree.path ? `${routeTree.path}${child.path ? `/${child.path}` : ""}` : child.path || "";
80
80
  const newRoute = {
81
81
  ...child,
82
82
  path: routePath.replace(/\/\//g, "/")
@@ -105,7 +105,10 @@ const routerPlugin = (userConfig = {}) => {
105
105
  if (!finalRouteConfig.routes && !createRoutes) {
106
106
  return App;
107
107
  }
108
- const selectBasePath = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
108
+ const selectBasePath = (pathname) => {
109
+ const match = serverBase.find((baseUrl) => isSegmentPrefix(pathname, baseUrl));
110
+ return match || "/";
111
+ };
109
112
  const RouterWrapper = (props) => {
110
113
  const { router, routes } = useRouterCreation({
111
114
  ...props,
@@ -152,6 +155,16 @@ const safeUse = (promise) => {
152
155
  }
153
156
  return null;
154
157
  };
158
+ function normalizeBase(b) {
159
+ if (b.length > 1 && b.endsWith("/"))
160
+ return b.slice(0, -1);
161
+ return b || "/";
162
+ }
163
+ function isSegmentPrefix(pathname, base) {
164
+ const b = normalizeBase(base);
165
+ const p = pathname || "/";
166
+ return p === b || p.startsWith(`${b}/`);
167
+ }
155
168
  function useRouterCreation(props, options) {
156
169
  const { api, createRoutes, supportHtml5History, selectBasePath, basename } = options;
157
170
  const runtimeContext = (0, import_react.useContext)(import_core.RuntimeReactContext);
@@ -43,7 +43,7 @@ var optimizeRoute = function(routeTree) {
43
43
  var children = routeTree.children;
44
44
  if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config && !routeTree.clientData) {
45
45
  var newRoutes = children.map(function(child) {
46
- var routePath = "".concat(routeTree.path ? routeTree.path : "").concat(child.path ? "/".concat(child.path) : "");
46
+ var routePath = routeTree.path ? "".concat(routeTree.path).concat(child.path ? "/".concat(child.path) : "") : child.path || "";
47
47
  var newRoute = _object_spread_props(_object_spread({}, child), {
48
48
  path: routePath.replace(/\/\//g, "/")
49
49
  });
@@ -73,9 +73,10 @@ var routerPlugin = function() {
73
73
  return App;
74
74
  }
75
75
  var selectBasePath = function(pathname) {
76
- return serverBase.find(function(baseUrl) {
77
- return pathname.search(baseUrl) === 0;
78
- }) || "/";
76
+ var match = serverBase.find(function(baseUrl) {
77
+ return isSegmentPrefix(pathname, baseUrl);
78
+ });
79
+ return match || "/";
79
80
  };
80
81
  var RouterWrapper = function(props) {
81
82
  var _useRouterCreation = useRouterCreation(_object_spread_props(_object_spread({}, props), {
@@ -126,6 +127,16 @@ var safeUse = function(promise) {
126
127
  }
127
128
  return null;
128
129
  };
130
+ function normalizeBase(b) {
131
+ if (b.length > 1 && b.endsWith("/"))
132
+ return b.slice(0, -1);
133
+ return b || "/";
134
+ }
135
+ function isSegmentPrefix(pathname, base) {
136
+ var b = normalizeBase(base);
137
+ var p = pathname || "/";
138
+ return p === b || p.startsWith("".concat(b, "/"));
139
+ }
129
140
  function useRouterCreation(props, options) {
130
141
  var api = options.api, createRoutes = options.createRoutes, supportHtml5History = options.supportHtml5History, selectBasePath = options.selectBasePath, basename = options.basename;
131
142
  var runtimeContext = useContext(RuntimeReactContext);
@@ -41,7 +41,7 @@ const optimizeRoute = (routeTree) => {
41
41
  const { children } = routeTree;
42
42
  if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config && !routeTree.clientData) {
43
43
  const newRoutes = children.map((child) => {
44
- const routePath = `${routeTree.path ? routeTree.path : ""}${child.path ? `/${child.path}` : ""}`;
44
+ const routePath = routeTree.path ? `${routeTree.path}${child.path ? `/${child.path}` : ""}` : child.path || "";
45
45
  const newRoute = {
46
46
  ...child,
47
47
  path: routePath.replace(/\/\//g, "/")
@@ -69,7 +69,10 @@ const routerPlugin = (userConfig = {}) => {
69
69
  if (!finalRouteConfig.routes && !createRoutes) {
70
70
  return App;
71
71
  }
72
- const selectBasePath = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
72
+ const selectBasePath = (pathname) => {
73
+ const match = serverBase.find((baseUrl) => isSegmentPrefix(pathname, baseUrl));
74
+ return match || "/";
75
+ };
73
76
  const RouterWrapper = (props) => {
74
77
  const { router, routes } = useRouterCreation({
75
78
  ...props,
@@ -116,6 +119,16 @@ const safeUse = (promise) => {
116
119
  }
117
120
  return null;
118
121
  };
122
+ function normalizeBase(b) {
123
+ if (b.length > 1 && b.endsWith("/"))
124
+ return b.slice(0, -1);
125
+ return b || "/";
126
+ }
127
+ function isSegmentPrefix(pathname, base) {
128
+ const b = normalizeBase(base);
129
+ const p = pathname || "/";
130
+ return p === b || p.startsWith(`${b}/`);
131
+ }
119
132
  function useRouterCreation(props, options) {
120
133
  const { api, createRoutes, supportHtml5History, selectBasePath, basename } = options;
121
134
  const runtimeContext = useContext(RuntimeReactContext);
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.68.7",
18
+ "version": "2.68.9",
19
19
  "engines": {
20
20
  "node": ">=14.17.6"
21
21
  },
@@ -219,13 +219,13 @@
219
219
  "react-is": "^18",
220
220
  "react-side-effect": "^2.1.2",
221
221
  "styled-components": "^5.3.1",
222
- "@modern-js/plugin": "2.68.7",
223
- "@modern-js/plugin-data-loader": "2.68.7",
224
- "@modern-js/plugin-v2": "2.68.7",
225
- "@modern-js/runtime-utils": "2.68.7",
226
- "@modern-js/render": "2.68.7",
227
- "@modern-js/types": "2.68.7",
228
- "@modern-js/utils": "2.68.7"
222
+ "@modern-js/plugin": "2.68.9",
223
+ "@modern-js/plugin-data-loader": "2.68.9",
224
+ "@modern-js/plugin-v2": "2.68.9",
225
+ "@modern-js/render": "2.68.9",
226
+ "@modern-js/runtime-utils": "2.68.9",
227
+ "@modern-js/types": "2.68.9",
228
+ "@modern-js/utils": "2.68.9"
229
229
  },
230
230
  "peerDependencies": {
231
231
  "react": ">=17",
@@ -233,7 +233,7 @@
233
233
  },
234
234
  "devDependencies": {
235
235
  "@remix-run/web-fetch": "^4.1.3",
236
- "@rsbuild/core": "1.4.14",
236
+ "@rsbuild/core": "1.4.15",
237
237
  "@testing-library/react": "^13.4.0",
238
238
  "@types/cookie": "0.6.0",
239
239
  "@types/invariant": "^2.2.30",
@@ -249,10 +249,10 @@
249
249
  "ts-node": "^10.9.1",
250
250
  "typescript": "^5",
251
251
  "webpack": "^5.101.0",
252
+ "@modern-js/app-tools": "2.68.9",
252
253
  "@scripts/build": "2.66.0",
253
254
  "@scripts/jest-config": "2.66.0",
254
- "@modern-js/app-tools": "2.68.7",
255
- "@modern-js/core": "2.68.7"
255
+ "@modern-js/core": "2.68.9"
256
256
  },
257
257
  "sideEffects": false,
258
258
  "publishConfig": {