@modern-js/runtime 2.60.6 → 2.60.7-alpha.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.
- package/dist/cjs/core/compatible.js +8 -0
- package/dist/cjs/router/cli/code/templates.js +2 -2
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +71 -24
- package/dist/cjs/router/runtime/constants.js +37 -0
- package/dist/cjs/router/runtime/plugin.js +0 -17
- package/dist/cjs/router/runtime/plugin.node.js +0 -16
- package/dist/esm/core/compatible.js +8 -0
- package/dist/esm/router/cli/code/templates.js +2 -2
- package/dist/esm/router/runtime/DeferredDataScripts.node.js +74 -22
- package/dist/esm/router/runtime/constants.js +10 -0
- package/dist/esm/router/runtime/plugin.js +0 -15
- package/dist/esm/router/runtime/plugin.node.js +0 -16
- package/dist/esm-node/core/compatible.js +8 -0
- package/dist/esm-node/router/cli/code/templates.js +2 -2
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +69 -22
- package/dist/esm-node/router/runtime/constants.js +10 -0
- package/dist/esm-node/router/runtime/plugin.js +0 -17
- package/dist/esm-node/router/runtime/plugin.node.js +0 -16
- package/dist/types/core/context/runtime.d.ts +10 -10
- package/dist/types/core/types.d.ts +16 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/router/runtime/constants.d.ts +112 -0
- package/package.json +6 -6
|
@@ -171,8 +171,16 @@ const bootstrap = async (BootApp, id, root, ReactDOM) => {
|
|
|
171
171
|
const useRuntimeContext = () => {
|
|
172
172
|
var _context_ssrContext, _context_ssrContext1;
|
|
173
173
|
const context = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
|
|
174
|
+
const baseSSRContext = context.ssrContext;
|
|
175
|
+
const tSSRContext = baseSSRContext ? {
|
|
176
|
+
isBrowser: context.isBrowser,
|
|
177
|
+
request: baseSSRContext.request || {},
|
|
178
|
+
response: baseSSRContext.response || {},
|
|
179
|
+
logger: baseSSRContext.logger || {}
|
|
180
|
+
} : {};
|
|
174
181
|
const pickedContext = {
|
|
175
182
|
...context,
|
|
183
|
+
context: tSSRContext,
|
|
176
184
|
request: (_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.request,
|
|
177
185
|
response: (_context_ssrContext1 = context.ssrContext) === null || _context_ssrContext1 === void 0 ? void 0 : _context_ssrContext1.response
|
|
178
186
|
};
|
|
@@ -210,8 +210,8 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
210
210
|
components.push(route._component);
|
|
211
211
|
component = `component_${components.length - 1}`;
|
|
212
212
|
} else {
|
|
213
|
-
|
|
214
|
-
component = `
|
|
213
|
+
components.push(route._component);
|
|
214
|
+
component = `component_${components.length - 1}`;
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
} else if (route._component) {
|
|
@@ -25,10 +25,8 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
25
25
|
var import_node = require("@modern-js/runtime-utils/node");
|
|
26
26
|
var import_router = require("@modern-js/runtime-utils/router");
|
|
27
27
|
var import_react = require("react");
|
|
28
|
+
var import_constants = require("./constants");
|
|
28
29
|
var import_utils = require("./utils");
|
|
29
|
-
const setupFnStr = `function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};`;
|
|
30
|
-
const resolveFnStr = `function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};`;
|
|
31
|
-
const preResolvedFnStr = `function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};`;
|
|
32
30
|
const DeferredDataScripts = (props) => {
|
|
33
31
|
const staticContext = props === null || props === void 0 ? void 0 : props.context;
|
|
34
32
|
const hydratedRef = (0, import_react.useRef)(false);
|
|
@@ -44,17 +42,18 @@ const DeferredDataScripts = (props) => {
|
|
|
44
42
|
loaderData: staticContext.loaderData,
|
|
45
43
|
errors: (0, import_utils.serializeErrors)(staticContext.errors)
|
|
46
44
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
`_ROUTER_DATA.s = ${setupFnStr}`,
|
|
50
|
-
`_ROUTER_DATA.r = ${resolveFnStr}`,
|
|
51
|
-
`_ROUTER_DATA.p = ${preResolvedFnStr}
|
|
45
|
+
const initialScript0 = `_ROUTER_DATA = ${(0, import_node.serializeJson)(_ROUTER_DATA)};`;
|
|
46
|
+
const initialScript1 = [
|
|
47
|
+
`_ROUTER_DATA.s = ${import_constants.setupFnStr}`,
|
|
48
|
+
`_ROUTER_DATA.r = ${import_constants.resolveFnStr}`,
|
|
49
|
+
`_ROUTER_DATA.p = ${import_constants.preResolvedFnStr}`,
|
|
50
|
+
import_constants.mergeLoaderDataStr
|
|
52
51
|
].join("\n");
|
|
53
52
|
const deferredDataScripts = [];
|
|
54
|
-
initialScripts
|
|
53
|
+
const initialScripts = Object.entries(activeDeferreds).map(([routeId, deferredData]) => {
|
|
55
54
|
const pendingKeys = new Set(deferredData.pendingKeys);
|
|
56
55
|
const { deferredKeys } = deferredData;
|
|
57
|
-
const
|
|
56
|
+
const deferredKeyPromiseManifests = deferredKeys.map((key) => {
|
|
58
57
|
if (pendingKeys.has(key)) {
|
|
59
58
|
deferredDataScripts.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DeferredDataScript, {
|
|
60
59
|
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
@@ -62,7 +61,14 @@ const DeferredDataScripts = (props) => {
|
|
|
62
61
|
dataKey: key,
|
|
63
62
|
routeId
|
|
64
63
|
}, `${routeId} | ${key}`));
|
|
65
|
-
return
|
|
64
|
+
return {
|
|
65
|
+
key,
|
|
66
|
+
routerDataFnName: "s",
|
|
67
|
+
routerDataFnArgs: [
|
|
68
|
+
(0, import_node.serializeJson)(routeId),
|
|
69
|
+
(0, import_node.serializeJson)(key)
|
|
70
|
+
]
|
|
71
|
+
};
|
|
66
72
|
} else {
|
|
67
73
|
const trackedPromise = deferredData.data[key];
|
|
68
74
|
if (typeof trackedPromise._error !== "undefined") {
|
|
@@ -70,18 +76,39 @@ const DeferredDataScripts = (props) => {
|
|
|
70
76
|
message: trackedPromise._error.message,
|
|
71
77
|
stack: process.env.NODE_ENV !== "production" ? trackedPromise._error.stack : void 0
|
|
72
78
|
};
|
|
73
|
-
return
|
|
79
|
+
return {
|
|
80
|
+
key,
|
|
81
|
+
routerDataFnName: "p",
|
|
82
|
+
routerDataFnArgs: [
|
|
83
|
+
(0, import_node.serializeJson)(void 0),
|
|
84
|
+
(0, import_node.serializeJson)(error)
|
|
85
|
+
]
|
|
86
|
+
};
|
|
74
87
|
} else {
|
|
75
88
|
if (typeof trackedPromise._data === "undefined") {
|
|
76
89
|
throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
|
|
77
90
|
}
|
|
78
|
-
return
|
|
91
|
+
return {
|
|
92
|
+
key,
|
|
93
|
+
routerDataFnName: "p",
|
|
94
|
+
routerDataFnArgs: [
|
|
95
|
+
(0, import_node.serializeJson)(trackedPromise._data)
|
|
96
|
+
]
|
|
97
|
+
};
|
|
79
98
|
}
|
|
80
99
|
}
|
|
81
|
-
})
|
|
82
|
-
return
|
|
83
|
-
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
fnName: `mergeLoaderData`,
|
|
103
|
+
fnArgs: [
|
|
104
|
+
routeId,
|
|
105
|
+
deferredKeyPromiseManifests
|
|
106
|
+
]
|
|
107
|
+
};
|
|
108
|
+
});
|
|
84
109
|
return [
|
|
110
|
+
initialScript0,
|
|
111
|
+
initialScript1,
|
|
85
112
|
initialScripts,
|
|
86
113
|
deferredDataScripts
|
|
87
114
|
];
|
|
@@ -91,15 +118,35 @@ const DeferredDataScripts = (props) => {
|
|
|
91
118
|
}
|
|
92
119
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
93
120
|
children: [
|
|
94
|
-
!hydratedRef.current && /* @__PURE__ */ (0, import_jsx_runtime.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
121
|
+
!hydratedRef.current && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
122
|
+
children: [
|
|
123
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
|
|
124
|
+
async: true,
|
|
125
|
+
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
126
|
+
suppressHydrationWarning: true,
|
|
127
|
+
dangerouslySetInnerHTML: {
|
|
128
|
+
__html: deferredScripts[0]
|
|
129
|
+
}
|
|
130
|
+
}),
|
|
131
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
|
|
132
|
+
async: true,
|
|
133
|
+
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
134
|
+
suppressHydrationWarning: true,
|
|
135
|
+
dangerouslySetInnerHTML: {
|
|
136
|
+
__html: deferredScripts[1]
|
|
137
|
+
}
|
|
138
|
+
}),
|
|
139
|
+
deferredScripts[2].map(({ fnName, fnArgs }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
|
|
140
|
+
async: true,
|
|
141
|
+
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
142
|
+
suppressHydrationWarning: true,
|
|
143
|
+
dangerouslySetInnerHTML: {
|
|
144
|
+
__html: `${fnName}(${fnArgs.map((argv) => `${JSON.stringify(argv)}`).join(",")})`
|
|
145
|
+
}
|
|
146
|
+
}, fnName))
|
|
147
|
+
]
|
|
101
148
|
}),
|
|
102
|
-
!hydratedRef.current && deferredScripts[
|
|
149
|
+
!hydratedRef.current && deferredScripts[3]
|
|
103
150
|
]
|
|
104
151
|
});
|
|
105
152
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var constants_exports = {};
|
|
20
|
+
__export(constants_exports, {
|
|
21
|
+
mergeLoaderDataStr: () => mergeLoaderDataStr,
|
|
22
|
+
preResolvedFnStr: () => preResolvedFnStr,
|
|
23
|
+
resolveFnStr: () => resolveFnStr,
|
|
24
|
+
setupFnStr: () => setupFnStr
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(constants_exports);
|
|
27
|
+
const setupFnStr = `function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};`;
|
|
28
|
+
const resolveFnStr = `function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};`;
|
|
29
|
+
const preResolvedFnStr = `function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};`;
|
|
30
|
+
const mergeLoaderDataStr = `function mergeLoaderData(e,n){const r=n.reduce((function(e,{key:n,routerDataFnName:r,routerDataFnArgs:a}){const t=a.map((e=>{if("undefined"!==e&&null!==e)return JSON.parse(e)}));return console.info("args",t),{...e,[n]:_ROUTER_DATA[r](...t)}}),{});Object.assign(_ROUTER_DATA.loaderData[e],r)}`;
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
mergeLoaderDataStr,
|
|
34
|
+
preResolvedFnStr,
|
|
35
|
+
resolveFnStr,
|
|
36
|
+
setupFnStr
|
|
37
|
+
});
|
|
@@ -160,23 +160,6 @@ const routerPlugin = (userConfig = {}) => {
|
|
|
160
160
|
};
|
|
161
161
|
};
|
|
162
162
|
return getRouteApp();
|
|
163
|
-
},
|
|
164
|
-
pickContext: (pickedContext) => {
|
|
165
|
-
const { remixRouter } = pickedContext;
|
|
166
|
-
if (!remixRouter) {
|
|
167
|
-
return pickedContext;
|
|
168
|
-
}
|
|
169
|
-
const router = {
|
|
170
|
-
...pickedContext.router,
|
|
171
|
-
navigate: remixRouter.navigate,
|
|
172
|
-
get location() {
|
|
173
|
-
return remixRouter.state.location;
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
return {
|
|
177
|
-
...pickedContext,
|
|
178
|
-
router
|
|
179
|
-
};
|
|
180
163
|
}
|
|
181
164
|
};
|
|
182
165
|
}
|
|
@@ -149,22 +149,6 @@ const routerPlugin = (userConfig = {}) => {
|
|
|
149
149
|
};
|
|
150
150
|
};
|
|
151
151
|
return getRouteApp();
|
|
152
|
-
},
|
|
153
|
-
pickContext: (pickedContext) => {
|
|
154
|
-
const { remixRouter } = pickedContext;
|
|
155
|
-
if (!remixRouter) {
|
|
156
|
-
return pickedContext;
|
|
157
|
-
}
|
|
158
|
-
const router = {
|
|
159
|
-
navigate: remixRouter.navigate,
|
|
160
|
-
get location() {
|
|
161
|
-
return remixRouter.state.location;
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
return {
|
|
165
|
-
...pickedContext,
|
|
166
|
-
router
|
|
167
|
-
};
|
|
168
152
|
}
|
|
169
153
|
};
|
|
170
154
|
}
|
|
@@ -193,7 +193,15 @@ var bootstrap = function() {
|
|
|
193
193
|
var useRuntimeContext = function() {
|
|
194
194
|
var _context_ssrContext, _context_ssrContext1;
|
|
195
195
|
var context = useContext(RuntimeReactContext);
|
|
196
|
+
var baseSSRContext = context.ssrContext;
|
|
197
|
+
var tSSRContext = baseSSRContext ? {
|
|
198
|
+
isBrowser: context.isBrowser,
|
|
199
|
+
request: baseSSRContext.request || {},
|
|
200
|
+
response: baseSSRContext.response || {},
|
|
201
|
+
logger: baseSSRContext.logger || {}
|
|
202
|
+
} : {};
|
|
196
203
|
var pickedContext = _object_spread_props(_object_spread({}, context), {
|
|
204
|
+
context: tSSRContext,
|
|
197
205
|
request: (_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.request,
|
|
198
206
|
response: (_context_ssrContext1 = context.ssrContext) === null || _context_ssrContext1 === void 0 ? void 0 : _context_ssrContext1.response
|
|
199
207
|
});
|
|
@@ -211,8 +211,8 @@ var fileSystemRoutes = function() {
|
|
|
211
211
|
components.push(route2._component);
|
|
212
212
|
component2 = "component_".concat(components.length - 1);
|
|
213
213
|
} else {
|
|
214
|
-
|
|
215
|
-
component2 = "
|
|
214
|
+
components.push(route2._component);
|
|
215
|
+
component2 = "component_".concat(components.length - 1);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
} else if (route2._component) {
|
|
@@ -3,10 +3,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
4
4
|
import { Await, useAsyncError } from "@modern-js/runtime-utils/router";
|
|
5
5
|
import { Suspense, useEffect, useMemo, useRef } from "react";
|
|
6
|
+
import { mergeLoaderDataStr, preResolvedFnStr, resolveFnStr, setupFnStr } from "./constants";
|
|
6
7
|
import { serializeErrors } from "./utils";
|
|
7
|
-
var setupFnStr = "function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};";
|
|
8
|
-
var resolveFnStr = "function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};";
|
|
9
|
-
var preResolvedFnStr = "function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};";
|
|
10
8
|
var DeferredDataScripts = function(props) {
|
|
11
9
|
var staticContext = props === null || props === void 0 ? void 0 : props.context;
|
|
12
10
|
var hydratedRef = useRef(false);
|
|
@@ -22,18 +20,19 @@ var DeferredDataScripts = function(props) {
|
|
|
22
20
|
loaderData: staticContext.loaderData,
|
|
23
21
|
errors: serializeErrors(staticContext.errors)
|
|
24
22
|
};
|
|
25
|
-
var
|
|
26
|
-
|
|
23
|
+
var initialScript0 = "_ROUTER_DATA = ".concat(serializeJson(_ROUTER_DATA), ";");
|
|
24
|
+
var initialScript1 = [
|
|
27
25
|
"_ROUTER_DATA.s = ".concat(setupFnStr),
|
|
28
26
|
"_ROUTER_DATA.r = ".concat(resolveFnStr),
|
|
29
|
-
"_ROUTER_DATA.p = ".concat(preResolvedFnStr)
|
|
27
|
+
"_ROUTER_DATA.p = ".concat(preResolvedFnStr),
|
|
28
|
+
mergeLoaderDataStr
|
|
30
29
|
].join("\n");
|
|
31
30
|
var deferredDataScripts = [];
|
|
32
|
-
initialScripts
|
|
31
|
+
var initialScripts = Object.entries(activeDeferreds).map(function(param) {
|
|
33
32
|
var _param = _sliced_to_array(param, 2), routeId = _param[0], deferredData = _param[1];
|
|
34
33
|
var pendingKeys = new Set(deferredData.pendingKeys);
|
|
35
34
|
var deferredKeys = deferredData.deferredKeys;
|
|
36
|
-
var
|
|
35
|
+
var deferredKeyPromiseManifests = deferredKeys.map(function(key) {
|
|
37
36
|
if (pendingKeys.has(key)) {
|
|
38
37
|
deferredDataScripts.push(/* @__PURE__ */ _jsx(DeferredDataScript, {
|
|
39
38
|
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
@@ -41,7 +40,14 @@ var DeferredDataScripts = function(props) {
|
|
|
41
40
|
dataKey: key,
|
|
42
41
|
routeId
|
|
43
42
|
}, "".concat(routeId, " | ").concat(key)));
|
|
44
|
-
return
|
|
43
|
+
return {
|
|
44
|
+
key,
|
|
45
|
+
routerDataFnName: "s",
|
|
46
|
+
routerDataFnArgs: [
|
|
47
|
+
serializeJson(routeId),
|
|
48
|
+
serializeJson(key)
|
|
49
|
+
]
|
|
50
|
+
};
|
|
45
51
|
} else {
|
|
46
52
|
var trackedPromise = deferredData.data[key];
|
|
47
53
|
if (typeof trackedPromise._error !== "undefined") {
|
|
@@ -49,18 +55,39 @@ var DeferredDataScripts = function(props) {
|
|
|
49
55
|
message: trackedPromise._error.message,
|
|
50
56
|
stack: process.env.NODE_ENV !== "production" ? trackedPromise._error.stack : void 0
|
|
51
57
|
};
|
|
52
|
-
return
|
|
58
|
+
return {
|
|
59
|
+
key,
|
|
60
|
+
routerDataFnName: "p",
|
|
61
|
+
routerDataFnArgs: [
|
|
62
|
+
serializeJson(void 0),
|
|
63
|
+
serializeJson(error)
|
|
64
|
+
]
|
|
65
|
+
};
|
|
53
66
|
} else {
|
|
54
67
|
if (typeof trackedPromise._data === "undefined") {
|
|
55
68
|
throw new Error("The deferred data for ".concat(key, " was not resolved, did you forget to return data from a deferred promise"));
|
|
56
69
|
}
|
|
57
|
-
return
|
|
70
|
+
return {
|
|
71
|
+
key,
|
|
72
|
+
routerDataFnName: "p",
|
|
73
|
+
routerDataFnArgs: [
|
|
74
|
+
serializeJson(trackedPromise._data)
|
|
75
|
+
]
|
|
76
|
+
};
|
|
58
77
|
}
|
|
59
78
|
}
|
|
60
|
-
})
|
|
61
|
-
return
|
|
62
|
-
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
fnName: "mergeLoaderData",
|
|
82
|
+
fnArgs: [
|
|
83
|
+
routeId,
|
|
84
|
+
deferredKeyPromiseManifests
|
|
85
|
+
]
|
|
86
|
+
};
|
|
87
|
+
});
|
|
63
88
|
return [
|
|
89
|
+
initialScript0,
|
|
90
|
+
initialScript1,
|
|
64
91
|
initialScripts,
|
|
65
92
|
deferredDataScripts
|
|
66
93
|
];
|
|
@@ -70,15 +97,40 @@ var DeferredDataScripts = function(props) {
|
|
|
70
97
|
}
|
|
71
98
|
return /* @__PURE__ */ _jsxs(_Fragment, {
|
|
72
99
|
children: [
|
|
73
|
-
!hydratedRef.current && /* @__PURE__ */
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
100
|
+
!hydratedRef.current && /* @__PURE__ */ _jsxs(_Fragment, {
|
|
101
|
+
children: [
|
|
102
|
+
/* @__PURE__ */ _jsx("script", {
|
|
103
|
+
async: true,
|
|
104
|
+
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
105
|
+
suppressHydrationWarning: true,
|
|
106
|
+
dangerouslySetInnerHTML: {
|
|
107
|
+
__html: deferredScripts[0]
|
|
108
|
+
}
|
|
109
|
+
}),
|
|
110
|
+
/* @__PURE__ */ _jsx("script", {
|
|
111
|
+
async: true,
|
|
112
|
+
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
113
|
+
suppressHydrationWarning: true,
|
|
114
|
+
dangerouslySetInnerHTML: {
|
|
115
|
+
__html: deferredScripts[1]
|
|
116
|
+
}
|
|
117
|
+
}),
|
|
118
|
+
deferredScripts[2].map(function(param) {
|
|
119
|
+
var fnName = param.fnName, fnArgs = param.fnArgs;
|
|
120
|
+
return /* @__PURE__ */ _jsx("script", {
|
|
121
|
+
async: true,
|
|
122
|
+
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
123
|
+
suppressHydrationWarning: true,
|
|
124
|
+
dangerouslySetInnerHTML: {
|
|
125
|
+
__html: "".concat(fnName, "(").concat(fnArgs.map(function(argv) {
|
|
126
|
+
return "".concat(JSON.stringify(argv));
|
|
127
|
+
}).join(","), ")")
|
|
128
|
+
}
|
|
129
|
+
}, fnName);
|
|
130
|
+
})
|
|
131
|
+
]
|
|
80
132
|
}),
|
|
81
|
-
!hydratedRef.current && deferredScripts[
|
|
133
|
+
!hydratedRef.current && deferredScripts[3]
|
|
82
134
|
]
|
|
83
135
|
});
|
|
84
136
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var setupFnStr = "function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};";
|
|
2
|
+
var resolveFnStr = "function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};";
|
|
3
|
+
var preResolvedFnStr = "function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};";
|
|
4
|
+
var mergeLoaderDataStr = 'function mergeLoaderData(e,n){const r=n.reduce((function(e,{key:n,routerDataFnName:r,routerDataFnArgs:a}){const t=a.map((e=>{if("undefined"!==e&&null!==e)return JSON.parse(e)}));return console.info("args",t),{...e,[n]:_ROUTER_DATA[r](...t)}}),{});Object.assign(_ROUTER_DATA.loaderData[e],r)}';
|
|
5
|
+
export {
|
|
6
|
+
mergeLoaderDataStr,
|
|
7
|
+
preResolvedFnStr,
|
|
8
|
+
resolveFnStr,
|
|
9
|
+
setupFnStr
|
|
10
|
+
};
|
|
@@ -145,21 +145,6 @@ var routerPlugin = function() {
|
|
|
145
145
|
};
|
|
146
146
|
};
|
|
147
147
|
return getRouteApp();
|
|
148
|
-
},
|
|
149
|
-
pickContext: function(pickedContext) {
|
|
150
|
-
var remixRouter = pickedContext.remixRouter;
|
|
151
|
-
if (!remixRouter) {
|
|
152
|
-
return pickedContext;
|
|
153
|
-
}
|
|
154
|
-
var router = _object_spread_props(_object_spread({}, pickedContext.router), {
|
|
155
|
-
navigate: remixRouter.navigate,
|
|
156
|
-
get location() {
|
|
157
|
-
return remixRouter.state.location;
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
return _object_spread_props(_object_spread({}, pickedContext), {
|
|
161
|
-
router
|
|
162
|
-
});
|
|
163
148
|
}
|
|
164
149
|
};
|
|
165
150
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
3
3
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
4
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
5
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
5
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
7
6
|
import { merge } from "@modern-js/runtime-utils/merge";
|
|
@@ -145,21 +144,6 @@ var routerPlugin = function() {
|
|
|
145
144
|
};
|
|
146
145
|
};
|
|
147
146
|
return getRouteApp();
|
|
148
|
-
},
|
|
149
|
-
pickContext: function(pickedContext) {
|
|
150
|
-
var remixRouter = pickedContext.remixRouter;
|
|
151
|
-
if (!remixRouter) {
|
|
152
|
-
return pickedContext;
|
|
153
|
-
}
|
|
154
|
-
var router = {
|
|
155
|
-
navigate: remixRouter.navigate,
|
|
156
|
-
get location() {
|
|
157
|
-
return remixRouter.state.location;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
return _object_spread_props(_object_spread({}, pickedContext), {
|
|
161
|
-
router
|
|
162
|
-
});
|
|
163
147
|
}
|
|
164
148
|
};
|
|
165
149
|
}
|
|
@@ -136,8 +136,16 @@ const bootstrap = async (BootApp, id, root, ReactDOM) => {
|
|
|
136
136
|
const useRuntimeContext = () => {
|
|
137
137
|
var _context_ssrContext, _context_ssrContext1;
|
|
138
138
|
const context = useContext(RuntimeReactContext);
|
|
139
|
+
const baseSSRContext = context.ssrContext;
|
|
140
|
+
const tSSRContext = baseSSRContext ? {
|
|
141
|
+
isBrowser: context.isBrowser,
|
|
142
|
+
request: baseSSRContext.request || {},
|
|
143
|
+
response: baseSSRContext.response || {},
|
|
144
|
+
logger: baseSSRContext.logger || {}
|
|
145
|
+
} : {};
|
|
139
146
|
const pickedContext = {
|
|
140
147
|
...context,
|
|
148
|
+
context: tSSRContext,
|
|
141
149
|
request: (_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.request,
|
|
142
150
|
response: (_context_ssrContext1 = context.ssrContext) === null || _context_ssrContext1 === void 0 ? void 0 : _context_ssrContext1.response
|
|
143
151
|
};
|
|
@@ -174,8 +174,8 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
174
174
|
components.push(route._component);
|
|
175
175
|
component = `component_${components.length - 1}`;
|
|
176
176
|
} else {
|
|
177
|
-
|
|
178
|
-
component = `
|
|
177
|
+
components.push(route._component);
|
|
178
|
+
component = `component_${components.length - 1}`;
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
} else if (route._component) {
|
|
@@ -2,10 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
3
3
|
import { Await, useAsyncError } from "@modern-js/runtime-utils/router";
|
|
4
4
|
import { Suspense, useEffect, useMemo, useRef } from "react";
|
|
5
|
+
import { mergeLoaderDataStr, preResolvedFnStr, resolveFnStr, setupFnStr } from "./constants";
|
|
5
6
|
import { serializeErrors } from "./utils";
|
|
6
|
-
const setupFnStr = `function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};`;
|
|
7
|
-
const resolveFnStr = `function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};`;
|
|
8
|
-
const preResolvedFnStr = `function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};`;
|
|
9
7
|
const DeferredDataScripts = (props) => {
|
|
10
8
|
const staticContext = props === null || props === void 0 ? void 0 : props.context;
|
|
11
9
|
const hydratedRef = useRef(false);
|
|
@@ -21,17 +19,18 @@ const DeferredDataScripts = (props) => {
|
|
|
21
19
|
loaderData: staticContext.loaderData,
|
|
22
20
|
errors: serializeErrors(staticContext.errors)
|
|
23
21
|
};
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const initialScript0 = `_ROUTER_DATA = ${serializeJson(_ROUTER_DATA)};`;
|
|
23
|
+
const initialScript1 = [
|
|
26
24
|
`_ROUTER_DATA.s = ${setupFnStr}`,
|
|
27
25
|
`_ROUTER_DATA.r = ${resolveFnStr}`,
|
|
28
|
-
`_ROUTER_DATA.p = ${preResolvedFnStr}
|
|
26
|
+
`_ROUTER_DATA.p = ${preResolvedFnStr}`,
|
|
27
|
+
mergeLoaderDataStr
|
|
29
28
|
].join("\n");
|
|
30
29
|
const deferredDataScripts = [];
|
|
31
|
-
initialScripts
|
|
30
|
+
const initialScripts = Object.entries(activeDeferreds).map(([routeId, deferredData]) => {
|
|
32
31
|
const pendingKeys = new Set(deferredData.pendingKeys);
|
|
33
32
|
const { deferredKeys } = deferredData;
|
|
34
|
-
const
|
|
33
|
+
const deferredKeyPromiseManifests = deferredKeys.map((key) => {
|
|
35
34
|
if (pendingKeys.has(key)) {
|
|
36
35
|
deferredDataScripts.push(/* @__PURE__ */ _jsx(DeferredDataScript, {
|
|
37
36
|
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
@@ -39,7 +38,14 @@ const DeferredDataScripts = (props) => {
|
|
|
39
38
|
dataKey: key,
|
|
40
39
|
routeId
|
|
41
40
|
}, `${routeId} | ${key}`));
|
|
42
|
-
return
|
|
41
|
+
return {
|
|
42
|
+
key,
|
|
43
|
+
routerDataFnName: "s",
|
|
44
|
+
routerDataFnArgs: [
|
|
45
|
+
serializeJson(routeId),
|
|
46
|
+
serializeJson(key)
|
|
47
|
+
]
|
|
48
|
+
};
|
|
43
49
|
} else {
|
|
44
50
|
const trackedPromise = deferredData.data[key];
|
|
45
51
|
if (typeof trackedPromise._error !== "undefined") {
|
|
@@ -47,18 +53,39 @@ const DeferredDataScripts = (props) => {
|
|
|
47
53
|
message: trackedPromise._error.message,
|
|
48
54
|
stack: process.env.NODE_ENV !== "production" ? trackedPromise._error.stack : void 0
|
|
49
55
|
};
|
|
50
|
-
return
|
|
56
|
+
return {
|
|
57
|
+
key,
|
|
58
|
+
routerDataFnName: "p",
|
|
59
|
+
routerDataFnArgs: [
|
|
60
|
+
serializeJson(void 0),
|
|
61
|
+
serializeJson(error)
|
|
62
|
+
]
|
|
63
|
+
};
|
|
51
64
|
} else {
|
|
52
65
|
if (typeof trackedPromise._data === "undefined") {
|
|
53
66
|
throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
|
|
54
67
|
}
|
|
55
|
-
return
|
|
68
|
+
return {
|
|
69
|
+
key,
|
|
70
|
+
routerDataFnName: "p",
|
|
71
|
+
routerDataFnArgs: [
|
|
72
|
+
serializeJson(trackedPromise._data)
|
|
73
|
+
]
|
|
74
|
+
};
|
|
56
75
|
}
|
|
57
76
|
}
|
|
58
|
-
})
|
|
59
|
-
return
|
|
60
|
-
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
fnName: `mergeLoaderData`,
|
|
80
|
+
fnArgs: [
|
|
81
|
+
routeId,
|
|
82
|
+
deferredKeyPromiseManifests
|
|
83
|
+
]
|
|
84
|
+
};
|
|
85
|
+
});
|
|
61
86
|
return [
|
|
87
|
+
initialScript0,
|
|
88
|
+
initialScript1,
|
|
62
89
|
initialScripts,
|
|
63
90
|
deferredDataScripts
|
|
64
91
|
];
|
|
@@ -68,15 +95,35 @@ const DeferredDataScripts = (props) => {
|
|
|
68
95
|
}
|
|
69
96
|
return /* @__PURE__ */ _jsxs(_Fragment, {
|
|
70
97
|
children: [
|
|
71
|
-
!hydratedRef.current && /* @__PURE__ */
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
98
|
+
!hydratedRef.current && /* @__PURE__ */ _jsxs(_Fragment, {
|
|
99
|
+
children: [
|
|
100
|
+
/* @__PURE__ */ _jsx("script", {
|
|
101
|
+
async: true,
|
|
102
|
+
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
103
|
+
suppressHydrationWarning: true,
|
|
104
|
+
dangerouslySetInnerHTML: {
|
|
105
|
+
__html: deferredScripts[0]
|
|
106
|
+
}
|
|
107
|
+
}),
|
|
108
|
+
/* @__PURE__ */ _jsx("script", {
|
|
109
|
+
async: true,
|
|
110
|
+
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
111
|
+
suppressHydrationWarning: true,
|
|
112
|
+
dangerouslySetInnerHTML: {
|
|
113
|
+
__html: deferredScripts[1]
|
|
114
|
+
}
|
|
115
|
+
}),
|
|
116
|
+
deferredScripts[2].map(({ fnName, fnArgs }) => /* @__PURE__ */ _jsx("script", {
|
|
117
|
+
async: true,
|
|
118
|
+
nonce: props === null || props === void 0 ? void 0 : props.nonce,
|
|
119
|
+
suppressHydrationWarning: true,
|
|
120
|
+
dangerouslySetInnerHTML: {
|
|
121
|
+
__html: `${fnName}(${fnArgs.map((argv) => `${JSON.stringify(argv)}`).join(",")})`
|
|
122
|
+
}
|
|
123
|
+
}, fnName))
|
|
124
|
+
]
|
|
78
125
|
}),
|
|
79
|
-
!hydratedRef.current && deferredScripts[
|
|
126
|
+
!hydratedRef.current && deferredScripts[3]
|
|
80
127
|
]
|
|
81
128
|
});
|
|
82
129
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const setupFnStr = `function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};`;
|
|
2
|
+
const resolveFnStr = `function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};`;
|
|
3
|
+
const preResolvedFnStr = `function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};`;
|
|
4
|
+
const mergeLoaderDataStr = `function mergeLoaderData(e,n){const r=n.reduce((function(e,{key:n,routerDataFnName:r,routerDataFnArgs:a}){const t=a.map((e=>{if("undefined"!==e&&null!==e)return JSON.parse(e)}));return console.info("args",t),{...e,[n]:_ROUTER_DATA[r](...t)}}),{});Object.assign(_ROUTER_DATA.loaderData[e],r)}`;
|
|
5
|
+
export {
|
|
6
|
+
mergeLoaderDataStr,
|
|
7
|
+
preResolvedFnStr,
|
|
8
|
+
resolveFnStr,
|
|
9
|
+
setupFnStr
|
|
10
|
+
};
|
|
@@ -134,23 +134,6 @@ const routerPlugin = (userConfig = {}) => {
|
|
|
134
134
|
};
|
|
135
135
|
};
|
|
136
136
|
return getRouteApp();
|
|
137
|
-
},
|
|
138
|
-
pickContext: (pickedContext) => {
|
|
139
|
-
const { remixRouter } = pickedContext;
|
|
140
|
-
if (!remixRouter) {
|
|
141
|
-
return pickedContext;
|
|
142
|
-
}
|
|
143
|
-
const router = {
|
|
144
|
-
...pickedContext.router,
|
|
145
|
-
navigate: remixRouter.navigate,
|
|
146
|
-
get location() {
|
|
147
|
-
return remixRouter.state.location;
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
return {
|
|
151
|
-
...pickedContext,
|
|
152
|
-
router
|
|
153
|
-
};
|
|
154
137
|
}
|
|
155
138
|
};
|
|
156
139
|
}
|
|
@@ -115,22 +115,6 @@ const routerPlugin = (userConfig = {}) => {
|
|
|
115
115
|
};
|
|
116
116
|
};
|
|
117
117
|
return getRouteApp();
|
|
118
|
-
},
|
|
119
|
-
pickContext: (pickedContext) => {
|
|
120
|
-
const { remixRouter } = pickedContext;
|
|
121
|
-
if (!remixRouter) {
|
|
122
|
-
return pickedContext;
|
|
123
|
-
}
|
|
124
|
-
const router = {
|
|
125
|
-
navigate: remixRouter.navigate,
|
|
126
|
-
get location() {
|
|
127
|
-
return remixRouter.state.location;
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
return {
|
|
131
|
-
...pickedContext,
|
|
132
|
-
router
|
|
133
|
-
};
|
|
134
118
|
}
|
|
135
119
|
};
|
|
136
120
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { Store } from '@modern-js-reduck/store';
|
|
3
|
-
import type { Router,
|
|
3
|
+
import type { Router, StaticHandlerContext } from '@modern-js/runtime-utils/remix-router';
|
|
4
4
|
import type { RouteManifest } from '../../router/runtime/types';
|
|
5
5
|
import { createLoaderManager } from '../loader/loaderManager';
|
|
6
6
|
import type { PluginRunner, runtime } from '../plugin';
|
|
7
|
-
import type { SSRServerContext } from '../types';
|
|
8
|
-
|
|
7
|
+
import type { SSRServerContext, TSSRContext } from '../types';
|
|
8
|
+
interface BaseRuntimeContext {
|
|
9
9
|
initialData?: Record<string, unknown>;
|
|
10
10
|
loaderManager: ReturnType<typeof createLoaderManager>;
|
|
11
|
+
isBrowser: boolean;
|
|
11
12
|
runner: ReturnType<typeof runtime.init>;
|
|
12
13
|
ssrContext?: SSRServerContext;
|
|
13
14
|
store?: Store;
|
|
@@ -27,17 +28,16 @@ export interface RuntimeContext extends BaseRuntimeContext {
|
|
|
27
28
|
}
|
|
28
29
|
export declare const RuntimeReactContext: import("react").Context<RuntimeContext>;
|
|
29
30
|
export declare const ServerRouterContext: import("react").Context<any>;
|
|
30
|
-
export interface
|
|
31
|
+
export interface TRuntimeContext extends Partial<BaseRuntimeContext> {
|
|
31
32
|
initialData?: Record<string, unknown>;
|
|
33
|
+
isBrowser: boolean;
|
|
34
|
+
context: TSSRContext;
|
|
35
|
+
/** @deprecated use context.request field instead */
|
|
32
36
|
request?: SSRServerContext['request'];
|
|
37
|
+
/** @deprecated use context.response field instead */
|
|
33
38
|
response?: SSRServerContext['response'];
|
|
34
39
|
store?: Store;
|
|
35
|
-
router?: {
|
|
36
|
-
navigate: Router['navigate'];
|
|
37
|
-
location: RouterState['location'];
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
export interface TRuntimeContext extends BaseTRuntimeContext {
|
|
41
40
|
[key: string]: any;
|
|
42
41
|
}
|
|
43
42
|
export declare const getInitialContext: (runner: PluginRunner, isBrowser?: boolean, routeManifest?: RouteManifest) => RuntimeContext;
|
|
43
|
+
export {};
|
|
@@ -53,4 +53,20 @@ export type SSRServerContext = Pick<BaseSSRServerContext, 'redirection' | 'respo
|
|
|
53
53
|
onError?: (e: unknown) => void;
|
|
54
54
|
onTiming?: (name: string, dur: number) => void;
|
|
55
55
|
};
|
|
56
|
+
interface TSSRBaseContext {
|
|
57
|
+
request: BaseSSRServerContext['request'] & {
|
|
58
|
+
userAgent: string;
|
|
59
|
+
cookie: string;
|
|
60
|
+
};
|
|
61
|
+
[propName: string]: any;
|
|
62
|
+
}
|
|
63
|
+
interface ServerContext extends TSSRBaseContext {
|
|
64
|
+
isBrowser: false;
|
|
65
|
+
response: BaseSSRServerContext['response'];
|
|
66
|
+
logger: BaseSSRServerContext['logger'];
|
|
67
|
+
}
|
|
68
|
+
interface ClientContext extends TSSRBaseContext {
|
|
69
|
+
isBrowser: true;
|
|
70
|
+
}
|
|
71
|
+
export declare type TSSRContext = ServerContext | ClientContext;
|
|
56
72
|
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { StateConfig } from './state';
|
|
|
3
3
|
export type { Plugin } from './core';
|
|
4
4
|
export type { AppConfig, RuntimeConfig } from './common';
|
|
5
5
|
export { isBrowser } from './common';
|
|
6
|
-
export type {
|
|
6
|
+
export type { RuntimeContext } from './core/context/runtime';
|
|
7
7
|
export type { RuntimeUserConfig } from './config';
|
|
8
8
|
export { createApp, useLoader, bootstrap, RuntimeReactContext, defineConfig, defineRuntimeConfig, useRuntimeContext, } from './core';
|
|
9
9
|
export type { StateConfig, RouterConfig };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* setup promises for deferred data
|
|
3
|
+
* original function:
|
|
4
|
+
function setupDeferredPromise(routeId, key) {
|
|
5
|
+
_ROUTER_DATA.r = _ROUTER_DATA.r || {};
|
|
6
|
+
_ROUTER_DATA.r[routeId] = _ROUTER_DATA.r[routeId] || {};
|
|
7
|
+
const promise = new Promise(function (resolve, reject) {
|
|
8
|
+
_ROUTER_DATA.r[routeId][key] = {
|
|
9
|
+
resolve,
|
|
10
|
+
reject,
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
return promise;
|
|
14
|
+
};
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export declare const setupFnStr = "function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};";
|
|
18
|
+
/**
|
|
19
|
+
* resolve promises for deferred data
|
|
20
|
+
* original function:
|
|
21
|
+
function resolveDeferredPromise(routeId, key, data, error) {
|
|
22
|
+
if (error) {
|
|
23
|
+
_ROUTER_DATA.r[routeId][key].reject(error);
|
|
24
|
+
} else {
|
|
25
|
+
_ROUTER_DATA.r[routeId][key].resolve(data);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
*/
|
|
29
|
+
export declare const resolveFnStr = "function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};";
|
|
30
|
+
/**
|
|
31
|
+
* update data for pre resolved promises
|
|
32
|
+
* original function:
|
|
33
|
+
* function preResovledDeferredPromise(data, error) {
|
|
34
|
+
if(typeof error !== 'undefined'){
|
|
35
|
+
return Promise.reject(new Error(error.message));
|
|
36
|
+
}else{
|
|
37
|
+
return Promise.resolve(data);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
*/
|
|
41
|
+
export declare const preResolvedFnStr = "function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};";
|
|
42
|
+
/**
|
|
43
|
+
* let initialScripts = '...';
|
|
44
|
+
* initialScripts += Object.entries(activeDeferreds)
|
|
45
|
+
.map(([routeId, deferredData]) => {
|
|
46
|
+
const pendingKeys = new Set(deferredData.pendingKeys);
|
|
47
|
+
const { deferredKeys } = deferredData;
|
|
48
|
+
const deferredKeyPromiseStr = deferredKeys
|
|
49
|
+
.map(key => {
|
|
50
|
+
if (pendingKeys.has(key)) {
|
|
51
|
+
deferredDataScripts.push(
|
|
52
|
+
<DeferredDataScript
|
|
53
|
+
nonce={props?.nonce}
|
|
54
|
+
key={`${routeId} | ${key}`}
|
|
55
|
+
data={deferredData.data[key]}
|
|
56
|
+
dataKey={key}
|
|
57
|
+
routeId={routeId}
|
|
58
|
+
/>,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return `${JSON.stringify(key)}: _ROUTER_DATA.s(${JSON.stringify(
|
|
62
|
+
routeId,
|
|
63
|
+
)},${JSON.stringify(key)}) `;
|
|
64
|
+
} else {
|
|
65
|
+
const trackedPromise = deferredData.data[key] as TrackedPromise;
|
|
66
|
+
if (typeof trackedPromise._error !== 'undefined') {
|
|
67
|
+
const error = {
|
|
68
|
+
message: trackedPromise._error.message,
|
|
69
|
+
stack:
|
|
70
|
+
process.env.NODE_ENV !== 'production'
|
|
71
|
+
? trackedPromise._error.stack
|
|
72
|
+
: undefined,
|
|
73
|
+
};
|
|
74
|
+
return `${JSON.stringify(
|
|
75
|
+
key,
|
|
76
|
+
)}: _ROUTER_DATA.p(${undefined}, ${serializeJson(error)})`;
|
|
77
|
+
} else {
|
|
78
|
+
if (typeof trackedPromise._data === 'undefined') {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return `${JSON.stringify(key)}: _ROUTER_DATA.p(${serializeJson(
|
|
84
|
+
trackedPromise._data,
|
|
85
|
+
)})`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
.join(',\n');
|
|
90
|
+
|
|
91
|
+
return `Object.assign(_ROUTER_DATA.loaderData[${JSON.stringify(
|
|
92
|
+
routeId,
|
|
93
|
+
)}], {${deferredKeyPromiseStr}});`;
|
|
94
|
+
})
|
|
95
|
+
.join('\n');
|
|
96
|
+
*/
|
|
97
|
+
/**
|
|
98
|
+
* Abstracting the above logic to `mergeLoaderData`:
|
|
99
|
+
* function mergeLoaderData (routeIdJsonStr, deferredKeyPromiseManifests) {
|
|
100
|
+
const source = deferredKeyPromiseManifests.reduce(function(o, {key, routerDataFnName, routerDataFnArgs }) {
|
|
101
|
+
const args = routerDataFnArgs.map(arg => {
|
|
102
|
+
if (arg === 'undefined' || arg === null) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
return JSON.parse(arg);
|
|
106
|
+
});
|
|
107
|
+
return {...o, [key]: _ROUTER_DATA[routerDataFnName](...args)};
|
|
108
|
+
}, {});
|
|
109
|
+
Object.assign(_ROUTER_DATA.loaderData[routeIdJsonStr], source);
|
|
110
|
+
};
|
|
111
|
+
*/
|
|
112
|
+
export declare const mergeLoaderDataStr = "function mergeLoaderData(e,n){const r=n.reduce((function(e,{key:n,routerDataFnName:r,routerDataFnArgs:a}){const t=a.map((e=>{if(\"undefined\"!==e&&null!==e)return JSON.parse(e)}));return console.info(\"args\",t),{...e,[n]:_ROUTER_DATA[r](...t)}}),{});Object.assign(_ROUTER_DATA.loaderData[e],r)}";
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.60.
|
|
18
|
+
"version": "2.60.7-alpha.0",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -202,8 +202,8 @@
|
|
|
202
202
|
"@modern-js/plugin": "2.60.6",
|
|
203
203
|
"@modern-js/plugin-data-loader": "2.60.6",
|
|
204
204
|
"@modern-js/runtime-utils": "2.60.6",
|
|
205
|
-
"@modern-js/
|
|
206
|
-
"@modern-js/
|
|
205
|
+
"@modern-js/types": "2.60.6",
|
|
206
|
+
"@modern-js/utils": "2.60.6"
|
|
207
207
|
},
|
|
208
208
|
"peerDependencies": {
|
|
209
209
|
"react": ">=17",
|
|
@@ -211,7 +211,7 @@
|
|
|
211
211
|
},
|
|
212
212
|
"devDependencies": {
|
|
213
213
|
"@remix-run/web-fetch": "^4.1.3",
|
|
214
|
-
"@rsbuild/core": "~1.0.
|
|
214
|
+
"@rsbuild/core": "~1.1.0-beta.1",
|
|
215
215
|
"@testing-library/react": "^13.4.0",
|
|
216
216
|
"@types/cookie": "0.6.0",
|
|
217
217
|
"@types/invariant": "^2.2.30",
|
|
@@ -225,10 +225,10 @@
|
|
|
225
225
|
"react-dom": "^18.3.1",
|
|
226
226
|
"ts-jest": "^29.1.0",
|
|
227
227
|
"typescript": "^5",
|
|
228
|
-
"webpack": "^5.
|
|
228
|
+
"webpack": "^5.96.1",
|
|
229
229
|
"@modern-js/app-tools": "2.60.6",
|
|
230
|
-
"@modern-js/core": "2.60.6",
|
|
231
230
|
"@scripts/build": "2.60.6",
|
|
231
|
+
"@modern-js/core": "2.60.6",
|
|
232
232
|
"@scripts/jest-config": "2.60.6"
|
|
233
233
|
},
|
|
234
234
|
"sideEffects": false,
|