@modern-js/runtime-utils 3.9.0 → 3.9.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.
- package/dist/cjs/browser/nestedRoutes.js +2 -1
- package/dist/cjs/node/fileReader.js +3 -2
- package/dist/cjs/node/loaderContext/createRequestCtx.js +1 -1
- package/dist/cjs/router.js +1 -1
- package/dist/cjs/universal/async_storage.js +14 -13
- package/dist/esm/browser/nestedRoutes.mjs +2 -1
- package/dist/esm/node/fileReader.mjs +3 -2
- package/dist/esm/node/loaderContext/createRequestCtx.mjs +1 -1
- package/dist/esm/router.mjs +1 -1
- package/dist/esm/universal/async_storage.mjs +4 -2
- package/dist/esm-node/browser/nestedRoutes.mjs +2 -1
- package/dist/esm-node/node/fileReader.mjs +3 -2
- package/dist/esm-node/node/loaderContext/createRequestCtx.mjs +1 -1
- package/dist/esm-node/router.mjs +1 -1
- package/dist/esm-node/universal/async_storage.mjs +14 -13
- package/dist/types/browser/index.d.ts +2 -2
- package/dist/types/node/fileReader.d.ts +1 -1
- package/dist/types/node/index.d.ts +3 -3
- package/dist/types/node/loaderContext/createRequestCtx.d.ts +1 -1
- package/dist/types/node/loaderContext/index.d.ts +3 -3
- package/dist/types/node/storer/index.d.ts +2 -2
- package/dist/types/server/index.d.ts +1 -1
- package/dist/types/universal/async_storage.d.ts +1 -1
- package/package.json +5 -6
|
@@ -91,6 +91,7 @@ const renderNestedRoute = (nestedRoute, options = {})=>{
|
|
|
91
91
|
routeProps.element = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_router_namespaceObject.Outlet, {});
|
|
92
92
|
}
|
|
93
93
|
if (element) routeProps.element = element;
|
|
94
|
+
if (nestedRoute.loading) routeProps.hydrateFallbackElement = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(nestedRoute.loading, {});
|
|
94
95
|
const childElements = children?.map((childRoute)=>renderNestedRoute(childRoute, {
|
|
95
96
|
parent: nestedRoute
|
|
96
97
|
}));
|
|
@@ -126,7 +127,7 @@ function createLoader(route) {
|
|
|
126
127
|
}
|
|
127
128
|
return res;
|
|
128
129
|
};
|
|
129
|
-
return ()=>{
|
|
130
|
+
else return ()=>{
|
|
130
131
|
if ('function' == typeof route.lazyImport) route.lazyImport();
|
|
131
132
|
return null;
|
|
132
133
|
};
|
|
@@ -68,9 +68,10 @@ class FileReader {
|
|
|
68
68
|
const content = await fs.promises.readFile(path);
|
|
69
69
|
this.storage.set(path, content);
|
|
70
70
|
return this.encodingContent(content, encoding);
|
|
71
|
+
} else {
|
|
72
|
+
this.storage.set(path, null);
|
|
73
|
+
return null;
|
|
71
74
|
}
|
|
72
|
-
this.storage.set(path, null);
|
|
73
|
-
return null;
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
77
|
reset(fs) {
|
|
@@ -31,7 +31,7 @@ function createRequestContext(context) {
|
|
|
31
31
|
const _context = context || new Map();
|
|
32
32
|
function get(key) {
|
|
33
33
|
if ('string' == typeof key) return _context.get(key);
|
|
34
|
-
return _context.get(key.symbol) || key.getDefaultValue();
|
|
34
|
+
else return _context.get(key.symbol) || key.getDefaultValue();
|
|
35
35
|
}
|
|
36
36
|
function set(key, value) {
|
|
37
37
|
if ('string' == typeof key) _context.set(key, value);
|
package/dist/cjs/router.js
CHANGED
|
@@ -33,22 +33,23 @@ const getAsyncLocalStorage = async ()=>{
|
|
|
33
33
|
if (isBrowser) {
|
|
34
34
|
console.error('You should not get async storage in browser');
|
|
35
35
|
return null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return serverStorage.getAsyncLocalStorage();
|
|
40
|
-
} catch (extensionError) {
|
|
41
|
-
try {
|
|
42
|
-
const serverStorage = await import("./async_storage.server");
|
|
36
|
+
} else {
|
|
37
|
+
if (!IS_WEB_FALLBACK) try {
|
|
38
|
+
const serverStorage = await import("./async_storage.server.js");
|
|
43
39
|
return serverStorage.getAsyncLocalStorage();
|
|
44
|
-
} catch (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
})
|
|
40
|
+
} catch (extensionError) {
|
|
41
|
+
try {
|
|
42
|
+
const serverStorage = await import("./async_storage.server");
|
|
43
|
+
return serverStorage.getAsyncLocalStorage();
|
|
44
|
+
} catch (fallbackError) {
|
|
45
|
+
console.error('Failed to load server async storage', {
|
|
46
|
+
extensionError: extensionError instanceof Error ? extensionError.message : extensionError,
|
|
47
|
+
fallbackError: fallbackError instanceof Error ? fallbackError.message : fallbackError
|
|
48
|
+
});
|
|
49
|
+
}
|
|
49
50
|
}
|
|
51
|
+
return null;
|
|
50
52
|
}
|
|
51
|
-
return null;
|
|
52
53
|
};
|
|
53
54
|
__webpack_require__.d(__webpack_exports__, {}, {
|
|
54
55
|
getAsyncLocalStorage: getAsyncLocalStorage
|
|
@@ -58,6 +58,7 @@ const renderNestedRoute = (nestedRoute, options = {})=>{
|
|
|
58
58
|
routeProps.element = /*#__PURE__*/ jsx(Outlet, {});
|
|
59
59
|
}
|
|
60
60
|
if (element) routeProps.element = element;
|
|
61
|
+
if (nestedRoute.loading) routeProps.hydrateFallbackElement = /*#__PURE__*/ jsx(nestedRoute.loading, {});
|
|
61
62
|
const childElements = children?.map((childRoute)=>renderNestedRoute(childRoute, {
|
|
62
63
|
parent: nestedRoute
|
|
63
64
|
}));
|
|
@@ -93,7 +94,7 @@ function createLoader(route) {
|
|
|
93
94
|
}
|
|
94
95
|
return res;
|
|
95
96
|
};
|
|
96
|
-
return ()=>{
|
|
97
|
+
else return ()=>{
|
|
97
98
|
if ('function' == typeof route.lazyImport) route.lazyImport();
|
|
98
99
|
return null;
|
|
99
100
|
};
|
|
@@ -25,9 +25,10 @@ class FileReader {
|
|
|
25
25
|
const content = await fs.promises.readFile(path);
|
|
26
26
|
this.storage.set(path, content);
|
|
27
27
|
return this.encodingContent(content, encoding);
|
|
28
|
+
} else {
|
|
29
|
+
this.storage.set(path, null);
|
|
30
|
+
return null;
|
|
28
31
|
}
|
|
29
|
-
this.storage.set(path, null);
|
|
30
|
-
return null;
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
34
|
reset(fs) {
|
|
@@ -2,7 +2,7 @@ function createRequestContext(context) {
|
|
|
2
2
|
const _context = context || new Map();
|
|
3
3
|
function get(key) {
|
|
4
4
|
if ('string' == typeof key) return _context.get(key);
|
|
5
|
-
return _context.get(key.symbol) || key.getDefaultValue();
|
|
5
|
+
else return _context.get(key.symbol) || key.getDefaultValue();
|
|
6
6
|
}
|
|
7
7
|
function set(key, value) {
|
|
8
8
|
if ('string' == typeof key) _context.set(key, value);
|
package/dist/esm/router.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const isBrowser = "u" > typeof window && void 0 !== window.document;
|
|
2
2
|
const getAsyncLocalStorage = async ()=>{
|
|
3
3
|
if (!isBrowser) return null;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
else {
|
|
5
|
+
console.error('You should not get async storage in browser');
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
6
8
|
};
|
|
7
9
|
export { getAsyncLocalStorage };
|
|
@@ -59,6 +59,7 @@ const renderNestedRoute = (nestedRoute, options = {})=>{
|
|
|
59
59
|
routeProps.element = /*#__PURE__*/ jsx(Outlet, {});
|
|
60
60
|
}
|
|
61
61
|
if (element) routeProps.element = element;
|
|
62
|
+
if (nestedRoute.loading) routeProps.hydrateFallbackElement = /*#__PURE__*/ jsx(nestedRoute.loading, {});
|
|
62
63
|
const childElements = children?.map((childRoute)=>renderNestedRoute(childRoute, {
|
|
63
64
|
parent: nestedRoute
|
|
64
65
|
}));
|
|
@@ -94,7 +95,7 @@ function createLoader(route) {
|
|
|
94
95
|
}
|
|
95
96
|
return res;
|
|
96
97
|
};
|
|
97
|
-
return ()=>{
|
|
98
|
+
else return ()=>{
|
|
98
99
|
if ('function' == typeof route.lazyImport) route.lazyImport();
|
|
99
100
|
return null;
|
|
100
101
|
};
|
|
@@ -26,9 +26,10 @@ class FileReader {
|
|
|
26
26
|
const content = await fs.promises.readFile(path);
|
|
27
27
|
this.storage.set(path, content);
|
|
28
28
|
return this.encodingContent(content, encoding);
|
|
29
|
+
} else {
|
|
30
|
+
this.storage.set(path, null);
|
|
31
|
+
return null;
|
|
29
32
|
}
|
|
30
|
-
this.storage.set(path, null);
|
|
31
|
-
return null;
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
reset(fs) {
|
|
@@ -3,7 +3,7 @@ function createRequestContext(context) {
|
|
|
3
3
|
const _context = context || new Map();
|
|
4
4
|
function get(key) {
|
|
5
5
|
if ('string' == typeof key) return _context.get(key);
|
|
6
|
-
return _context.get(key.symbol) || key.getDefaultValue();
|
|
6
|
+
else return _context.get(key.symbol) || key.getDefaultValue();
|
|
7
7
|
}
|
|
8
8
|
function set(key, value) {
|
|
9
9
|
if ('string' == typeof key) _context.set(key, value);
|
package/dist/esm-node/router.mjs
CHANGED
|
@@ -5,21 +5,22 @@ const getAsyncLocalStorage = async ()=>{
|
|
|
5
5
|
if (isBrowser) {
|
|
6
6
|
console.error('You should not get async storage in browser');
|
|
7
7
|
return null;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return serverStorage.getAsyncLocalStorage();
|
|
12
|
-
} catch (extensionError) {
|
|
13
|
-
try {
|
|
14
|
-
const serverStorage = await import("./async_storage.server");
|
|
8
|
+
} else {
|
|
9
|
+
if (!IS_WEB_FALLBACK) try {
|
|
10
|
+
const serverStorage = await import("./async_storage.server.mjs");
|
|
15
11
|
return serverStorage.getAsyncLocalStorage();
|
|
16
|
-
} catch (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
})
|
|
12
|
+
} catch (extensionError) {
|
|
13
|
+
try {
|
|
14
|
+
const serverStorage = await import("./async_storage.server");
|
|
15
|
+
return serverStorage.getAsyncLocalStorage();
|
|
16
|
+
} catch (fallbackError) {
|
|
17
|
+
console.error('Failed to load server async storage', {
|
|
18
|
+
extensionError: extensionError instanceof Error ? extensionError.message : extensionError,
|
|
19
|
+
fallbackError: fallbackError instanceof Error ? fallbackError.message : fallbackError
|
|
20
|
+
});
|
|
21
|
+
}
|
|
21
22
|
}
|
|
23
|
+
return null;
|
|
22
24
|
}
|
|
23
|
-
return null;
|
|
24
25
|
};
|
|
25
26
|
export { getAsyncLocalStorage };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './nestedRoutes';
|
|
2
|
-
export * from './deferreds';
|
|
1
|
+
export * from './nestedRoutes.js';
|
|
2
|
+
export * from './deferreds.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ssr helpers
|
|
3
3
|
*/
|
|
4
|
-
export { storage } from '../universal/async_storage.server';
|
|
5
|
-
export { serializeJson } from './serialize';
|
|
6
|
-
export * from './loaderContext';
|
|
4
|
+
export { storage } from '../universal/async_storage.server.js';
|
|
5
|
+
export { serializeJson } from './serialize.js';
|
|
6
|
+
export * from './loaderContext/index.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RequestPayload } from '@modern-js/types';
|
|
2
|
-
import type { LoaderContext } from './createLoaderCtx';
|
|
2
|
+
import type { LoaderContext } from './createLoaderCtx.js';
|
|
3
3
|
interface Get<P extends Record<string, unknown>> {
|
|
4
4
|
<Key extends keyof P>(key: Key): P[Key];
|
|
5
5
|
<T>(key: LoaderContext<T>): T;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Reporter } from '@modern-js/types';
|
|
2
|
-
export { createRequestContext, type RequestContext, } from './createRequestCtx';
|
|
3
|
-
export type { LoaderContext } from './createLoaderCtx';
|
|
4
|
-
export declare const reporterCtx: import("./createLoaderCtx").LoaderContext<Reporter>;
|
|
2
|
+
export { createRequestContext, type RequestContext, } from './createRequestCtx.js';
|
|
3
|
+
export type { LoaderContext } from './createLoaderCtx.js';
|
|
4
|
+
export declare const reporterCtx: import("./createLoaderCtx.js").LoaderContext<Reporter>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Storage } from './storage';
|
|
2
|
-
export { Storage } from './storage';
|
|
1
|
+
import { Storage } from './storage.js';
|
|
2
|
+
export { Storage } from './storage.js';
|
|
3
3
|
export declare function createMemoryStorage<V extends {} | null>(namespace: string): Storage<V>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './nestedRoutes';
|
|
1
|
+
export * from './nestedRoutes.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Storage } from './async_storage.server';
|
|
1
|
+
import type { Storage } from './async_storage.server.js';
|
|
2
2
|
export declare const getAsyncLocalStorage: () => Promise<Storage | null>;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "3.9.
|
|
18
|
+
"version": "3.9.2",
|
|
19
19
|
"_comment": "Provide ESM and CJS exports, ESM is used by runtime package, for treeshaking",
|
|
20
20
|
"exports": {
|
|
21
21
|
"./router": {
|
|
@@ -159,8 +159,8 @@
|
|
|
159
159
|
"lru-cache": "^10.4.3",
|
|
160
160
|
"react-router": "7.15.1",
|
|
161
161
|
"serialize-javascript": "^6.0.2",
|
|
162
|
-
"@modern-js/types": "3.9.
|
|
163
|
-
"@modern-js/utils": "3.9.
|
|
162
|
+
"@modern-js/types": "3.9.2",
|
|
163
|
+
"@modern-js/utils": "3.9.2"
|
|
164
164
|
},
|
|
165
165
|
"peerDependencies": {
|
|
166
166
|
"react": ">=18.3.1",
|
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
}
|
|
176
176
|
},
|
|
177
177
|
"devDependencies": {
|
|
178
|
-
"@rslib/core": "0.
|
|
178
|
+
"@rslib/core": "1.0.0",
|
|
179
179
|
"@types/ioredis-mock": "^8.2.7",
|
|
180
180
|
"@types/node": "^20",
|
|
181
181
|
"@types/serialize-javascript": "^5.0.4",
|
|
@@ -191,6 +191,5 @@
|
|
|
191
191
|
"dev": "rslib build --watch",
|
|
192
192
|
"build": "rslib build",
|
|
193
193
|
"test": "rstest --passWithNoTests"
|
|
194
|
-
}
|
|
195
|
-
"types": "./dist/types/index.d.ts"
|
|
194
|
+
}
|
|
196
195
|
}
|