@modern-js/runtime 2.58.2-alpha.0 → 2.58.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/cli/code.js +1 -1
- package/dist/cjs/cli/ssr/index.js +14 -1
- package/dist/cjs/core/browser/index.js +34 -15
- package/dist/cjs/core/loader/loaderManager.js +1 -1
- package/dist/cjs/core/server/requestHandler.js +7 -4
- package/dist/cjs/core/server/string/index.js +13 -13
- package/dist/esm/cli/code.js +2 -3
- package/dist/esm/cli/ssr/index.js +16 -1
- package/dist/esm/core/browser/index.js +31 -12
- package/dist/esm/core/loader/loaderManager.js +3 -1
- package/dist/esm/core/server/requestHandler.js +5 -2
- package/dist/esm/core/server/string/index.js +4 -7
- package/dist/esm-node/cli/code.js +2 -2
- package/dist/esm-node/cli/ssr/index.js +14 -1
- package/dist/esm-node/core/browser/index.js +34 -15
- package/dist/esm-node/core/loader/loaderManager.js +1 -1
- package/dist/esm-node/core/server/requestHandler.js +5 -2
- package/dist/esm-node/core/server/string/index.js +13 -13
- package/dist/types/cli/alias.d.ts +1 -1
- package/dist/types/cli/code.d.ts +1 -1
- package/dist/types/core/browser/hydrate.d.ts +3 -3
- package/dist/types/core/browser/index.d.ts +1 -1
- package/dist/types/core/browser/withCallback.d.ts +1 -1
- package/dist/types/core/compatible.d.ts +2 -2
- package/dist/types/core/config.d.ts +1 -1
- package/dist/types/core/context/index.d.ts +1 -1
- package/dist/types/core/context/runtime.d.ts +5 -5
- package/dist/types/core/loader/loaderManager.d.ts +2 -2
- package/dist/types/core/plugin/base.d.ts +2 -2
- package/dist/types/core/plugin/index.d.ts +1 -1
- package/dist/types/core/plugin/runner.d.ts +1 -1
- package/dist/types/core/react/index.d.ts +1 -1
- package/dist/types/core/react/wrapper.d.ts +1 -1
- package/dist/types/core/server/helmet.d.ts +1 -1
- package/dist/types/core/server/index.d.ts +1 -1
- package/dist/types/core/server/react/nossr/index.d.ts +1 -1
- package/dist/types/core/server/react/prerender/util.d.ts +1 -1
- package/dist/types/core/server/requestHandler.d.ts +3 -3
- package/dist/types/core/server/stream/afterTemplate.d.ts +4 -4
- package/dist/types/core/server/stream/beforeTemplate.d.ts +2 -2
- package/dist/types/core/server/stream/createReadableStream.d.ts +1 -1
- package/dist/types/core/server/stream/createReadableStream.worker.d.ts +1 -1
- package/dist/types/core/server/stream/shared.d.ts +3 -3
- package/dist/types/core/server/string/index.d.ts +1 -1
- package/dist/types/core/server/string/loadable.d.ts +1 -1
- package/dist/types/core/server/string/prefetch.d.ts +5 -5
- package/dist/types/core/server/string/ssrData.d.ts +4 -4
- package/dist/types/core/server/string/styledComponent.d.ts +1 -1
- package/dist/types/core/server/string/types.d.ts +2 -2
- package/dist/types/core/server/utils.d.ts +3 -3
- package/dist/types/core/types.d.ts +1 -1
- package/dist/types/document/DocumentStructureContext.d.ts +1 -1
- package/dist/types/document/cli/index.d.ts +1 -1
- package/dist/types/exports/server.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/router/cli/code/index.d.ts +2 -2
- package/dist/types/router/cli/entry.d.ts +1 -1
- package/dist/types/router/cli/handler.d.ts +3 -3
- package/dist/types/router/runtime/DeferredDataScripts.node.d.ts +1 -1
- package/dist/types/router/runtime/PrefetchLink.d.ts +1 -1
- package/dist/types/router/runtime/hooks.d.ts +1 -1
- package/dist/types/router/runtime/plugin.d.ts +1 -1
- package/dist/types/router/runtime/routeModule.d.ts +1 -1
- package/dist/types/router/runtime/types.d.ts +1 -1
- package/dist/types/router/runtime/utils.d.ts +2 -2
- package/dist/types/router/runtime/withRouter.d.ts +1 -1
- package/package.json +13 -12
- package/types/index.d.ts +1 -1
- package/types/router.d.ts +1 -1
package/dist/cjs/cli/code.js
CHANGED
|
@@ -36,7 +36,7 @@ var import_utils = require("@modern-js/utils");
|
|
|
36
36
|
var import_constants = require("./constants");
|
|
37
37
|
var template = __toESM(require("./template"));
|
|
38
38
|
var serverTemplate = __toESM(require("./template.server"));
|
|
39
|
-
function getSSRMode(entry
|
|
39
|
+
function getSSRMode(entry, config) {
|
|
40
40
|
const { ssr, ssrByEntries } = config.server;
|
|
41
41
|
if (config.output.ssg) {
|
|
42
42
|
return "string";
|
|
@@ -86,6 +86,7 @@ const ssrPlugin = () => ({
|
|
|
86
86
|
"@modern-js/runtime"
|
|
87
87
|
],
|
|
88
88
|
setup: (api) => {
|
|
89
|
+
const appContext = api.useAppContext();
|
|
89
90
|
return {
|
|
90
91
|
// for bundle
|
|
91
92
|
config() {
|
|
@@ -123,7 +124,19 @@ const ssrPlugin = () => ({
|
|
|
123
124
|
}
|
|
124
125
|
},
|
|
125
126
|
tools: {
|
|
126
|
-
babel: babelHandler
|
|
127
|
+
babel: babelHandler,
|
|
128
|
+
bundlerChain: (chain, { isServer }) => {
|
|
129
|
+
if (isServer && appContext.moduleType === "module") {
|
|
130
|
+
chain.output.libraryTarget("module").set("chunkFormat", "module");
|
|
131
|
+
chain.output.library({
|
|
132
|
+
type: "module"
|
|
133
|
+
});
|
|
134
|
+
chain.experiments({
|
|
135
|
+
...chain.get("experiments"),
|
|
136
|
+
outputModule: true
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
127
140
|
}
|
|
128
141
|
};
|
|
129
142
|
}
|
|
@@ -41,24 +41,43 @@ var import_wrapper = require("../react/wrapper");
|
|
|
41
41
|
var import_constants = require("../constants");
|
|
42
42
|
var import_hydrate = require("./hydrate");
|
|
43
43
|
const IS_REACT18 = process.env.IS_REACT18 === "true";
|
|
44
|
+
const getQuery = () => window.location.search.substring(1).split("&").reduce((res, item) => {
|
|
45
|
+
const [key, value] = item.split("=");
|
|
46
|
+
if (key) {
|
|
47
|
+
res[key] = value;
|
|
48
|
+
}
|
|
49
|
+
return res;
|
|
50
|
+
}, {});
|
|
44
51
|
function getSSRData() {
|
|
52
|
+
var _ssrData_context, _ssrData_context1, _ssrRequest_headers;
|
|
45
53
|
const ssrData = window._SSR_DATA;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
const ssrRequest = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_context = ssrData.context) === null || _ssrData_context === void 0 ? void 0 : _ssrData_context.request;
|
|
55
|
+
const finalSSRData = {
|
|
56
|
+
...ssrData || {
|
|
57
|
+
renderLevel: 0,
|
|
58
|
+
mode: "string"
|
|
59
|
+
},
|
|
60
|
+
context: {
|
|
61
|
+
...(ssrData === null || ssrData === void 0 ? void 0 : ssrData.context) || {},
|
|
62
|
+
request: {
|
|
63
|
+
...(ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_context1 = ssrData.context) === null || _ssrData_context1 === void 0 ? void 0 : _ssrData_context1.request) || {},
|
|
64
|
+
params: (ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.params) || {},
|
|
65
|
+
host: (ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.host) || location.host,
|
|
66
|
+
pathname: (ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.pathname) || location.pathname,
|
|
67
|
+
headers: (ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.headers) || {},
|
|
68
|
+
cookieMap: import_cookie.default.parse(document.cookie || "") || {},
|
|
69
|
+
cookie: document.cookie || "",
|
|
70
|
+
userAgent: (ssrRequest === null || ssrRequest === void 0 ? void 0 : (_ssrRequest_headers = ssrRequest.headers) === null || _ssrRequest_headers === void 0 ? void 0 : _ssrRequest_headers["user-agent"]) || navigator.userAgent,
|
|
71
|
+
referer: document.referrer,
|
|
72
|
+
query: {
|
|
73
|
+
...getQuery(),
|
|
74
|
+
...(ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.query) || {}
|
|
75
|
+
},
|
|
76
|
+
url: location.href
|
|
58
77
|
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
return finalSSRData;
|
|
62
81
|
}
|
|
63
82
|
function isClientArgs(id) {
|
|
64
83
|
return typeof id === "undefined" || typeof id === "string" || typeof HTMLElement !== "undefined" && id instanceof HTMLElement;
|
|
@@ -58,7 +58,7 @@ const createLoader = (id, initialData = {
|
|
|
58
58
|
reloading: false,
|
|
59
59
|
data: void 0,
|
|
60
60
|
error: void 0
|
|
61
|
-
}, loaderFn, skip = false) => {
|
|
61
|
+
}, loaderFn = () => Promise.resolve(), skip = false) => {
|
|
62
62
|
let promise;
|
|
63
63
|
let status = 0;
|
|
64
64
|
let { data, error } = initialData;
|
|
@@ -22,7 +22,7 @@ __export(requestHandler_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(requestHandler_exports);
|
|
24
24
|
var import_request = require("@modern-js/runtime-utils/universal/request");
|
|
25
|
-
var
|
|
25
|
+
var import_react = require("../react");
|
|
26
26
|
var import_context = require("../context");
|
|
27
27
|
var import_runner = require("../plugin/runner");
|
|
28
28
|
var import_runtime = require("../context/runtime");
|
|
@@ -41,7 +41,10 @@ function createSSRContext(request, options) {
|
|
|
41
41
|
const headersData = (0, import_request.parseHeaders)(request);
|
|
42
42
|
const url = new URL(request.url);
|
|
43
43
|
const host = headers.get("X-Forwarded-Host") || headers.get("host") || url.host;
|
|
44
|
-
|
|
44
|
+
let protocol = (headers.get("X-Forwarded-Proto") || url.protocol || "http").split(/\s*,\s*/, 1)[0];
|
|
45
|
+
if (!protocol.endsWith(":")) {
|
|
46
|
+
protocol += ":";
|
|
47
|
+
}
|
|
45
48
|
const ssrConfig = (0, import_utils.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries);
|
|
46
49
|
const ssrMode = (0, import_utils.getSSRMode)(ssrConfig);
|
|
47
50
|
const loaderFailureMode = typeof ssrConfig === "object" ? ssrConfig.loaderFailureMode : void 0;
|
|
@@ -53,7 +56,7 @@ function createSSRContext(request, options) {
|
|
|
53
56
|
logger,
|
|
54
57
|
metrics,
|
|
55
58
|
request: {
|
|
56
|
-
url: request.url.replace(url.host, host).replace(url.protocol,
|
|
59
|
+
url: request.url.replace(url.host, host).replace(url.protocol, protocol),
|
|
57
60
|
baseUrl: route.urlPath,
|
|
58
61
|
userAgent: headers.get("user-agent"),
|
|
59
62
|
cookie,
|
|
@@ -83,7 +86,7 @@ function createSSRContext(request, options) {
|
|
|
83
86
|
}
|
|
84
87
|
const createRequestHandler = async (handleRequest) => {
|
|
85
88
|
const requestHandler = async (request, options) => {
|
|
86
|
-
const Root = (0,
|
|
89
|
+
const Root = (0, import_react.createRoot)();
|
|
87
90
|
const runner = (0, import_runner.getGlobalRunner)();
|
|
88
91
|
const { routeManifest } = options.resource;
|
|
89
92
|
const context = (0, import_runtime.getInitialContext)(runner, false, routeManifest);
|
|
@@ -105,22 +105,22 @@ async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifie
|
|
|
105
105
|
const end = (0, import_time.time)();
|
|
106
106
|
let html = "";
|
|
107
107
|
let helmetData;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
try {
|
|
109
|
+
const finalApp = collectors.reduce((pre, creator) => {
|
|
110
|
+
var _creator_collect;
|
|
111
|
+
return ((_creator_collect = creator.collect) === null || _creator_collect === void 0 ? void 0 : _creator_collect.call(creator, pre)) || pre;
|
|
112
|
+
}, App);
|
|
113
|
+
if (chunkSet.renderLevel >= import_constants2.RenderLevel.SERVER_PREFETCH) {
|
|
114
114
|
html = import_server.default.renderToString(finalApp);
|
|
115
|
-
helmetData = import_react_helmet.default.renderStatic();
|
|
116
115
|
chunkSet.renderLevel = import_constants2.RenderLevel.SERVER_RENDER;
|
|
117
|
-
await Promise.all(collectors.map((component) => component.effect()));
|
|
118
|
-
const cost = end();
|
|
119
|
-
onTiming(import_tracer.SSRTimings.RENDER_HTML, cost);
|
|
120
|
-
} catch (e) {
|
|
121
|
-
chunkSet.renderLevel = import_constants2.RenderLevel.CLIENT_RENDER;
|
|
122
|
-
onError(import_tracer.SSRErrors.RENDER_HTML, e);
|
|
123
116
|
}
|
|
117
|
+
helmetData = import_react_helmet.default.renderStatic();
|
|
118
|
+
await Promise.all(collectors.map((component) => component.effect()));
|
|
119
|
+
const cost = end();
|
|
120
|
+
onTiming(import_tracer.SSRTimings.RENDER_HTML, cost);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
chunkSet.renderLevel = import_constants2.RenderLevel.CLIENT_RENDER;
|
|
123
|
+
onError(import_tracer.SSRErrors.RENDER_HTML, e);
|
|
124
124
|
}
|
|
125
125
|
const { ssrScripts, cssChunk, jsChunk } = chunkSet;
|
|
126
126
|
const finalHtml = await (0, import_shared.buildHtml)(htmlTemplate, [
|
package/dist/esm/cli/code.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import path from "path";
|
|
4
|
-
import {
|
|
4
|
+
import { fs } from "@modern-js/utils";
|
|
5
5
|
import { INDEX_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_POINT_REGISTER_FILE_NAME, ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME, ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME, SERVER_ENTRY_POINT_FILE_NAME, ENTRY_SERVER_BOOTSTRAP_FILE_NAME } from "./constants";
|
|
6
6
|
import * as template from "./template";
|
|
7
7
|
import * as serverTemplate from "./template.server";
|
|
8
|
-
function getSSRMode() {
|
|
9
|
-
var entry = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : MAIN_ENTRY_NAME, config = arguments.length > 1 ? arguments[1] : void 0;
|
|
8
|
+
function getSSRMode(entry, config) {
|
|
10
9
|
var _config_server = config.server, ssr = _config_server.ssr, ssrByEntries = _config_server.ssrByEntries;
|
|
11
10
|
if (config.output.ssg) {
|
|
12
11
|
return "string";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
|
+
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
1
3
|
import path from "path";
|
|
2
4
|
import { LOADABLE_STATS_FILE, isUseSSRBundle } from "@modern-js/utils";
|
|
3
5
|
var hasStringSSREntry = function(userConfig) {
|
|
@@ -75,6 +77,7 @@ var ssrPlugin = function() {
|
|
|
75
77
|
"@modern-js/runtime"
|
|
76
78
|
],
|
|
77
79
|
setup: function(api) {
|
|
80
|
+
var appContext = api.useAppContext();
|
|
78
81
|
return {
|
|
79
82
|
// for bundle
|
|
80
83
|
config: function config() {
|
|
@@ -112,7 +115,19 @@ var ssrPlugin = function() {
|
|
|
112
115
|
}
|
|
113
116
|
},
|
|
114
117
|
tools: {
|
|
115
|
-
babel: babelHandler
|
|
118
|
+
babel: babelHandler,
|
|
119
|
+
bundlerChain: function(chain, param) {
|
|
120
|
+
var isServer = param.isServer;
|
|
121
|
+
if (isServer && appContext.moduleType === "module") {
|
|
122
|
+
chain.output.libraryTarget("module").set("chunkFormat", "module");
|
|
123
|
+
chain.output.library({
|
|
124
|
+
type: "module"
|
|
125
|
+
});
|
|
126
|
+
chain.experiments(_object_spread_props(_object_spread({}, chain.get("experiments")), {
|
|
127
|
+
outputModule: true
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
116
131
|
}
|
|
117
132
|
};
|
|
118
133
|
}
|
|
@@ -2,6 +2,7 @@ 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
4
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
5
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
5
6
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
7
|
import cookieTool from "cookie";
|
|
7
8
|
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
@@ -13,21 +14,39 @@ import { wrapRuntimeContextProvider } from "../react/wrapper";
|
|
|
13
14
|
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../constants";
|
|
14
15
|
import { hydrateRoot } from "./hydrate";
|
|
15
16
|
var IS_REACT18 = process.env.IS_REACT18 === "true";
|
|
17
|
+
var getQuery = function() {
|
|
18
|
+
return window.location.search.substring(1).split("&").reduce(function(res, item) {
|
|
19
|
+
var _item_split = _sliced_to_array(item.split("="), 2), key = _item_split[0], value = _item_split[1];
|
|
20
|
+
if (key) {
|
|
21
|
+
res[key] = value;
|
|
22
|
+
}
|
|
23
|
+
return res;
|
|
24
|
+
}, {});
|
|
25
|
+
};
|
|
16
26
|
function getSSRData() {
|
|
27
|
+
var _ssrData_context, _ssrData_context1, _ssrRequest_headers;
|
|
17
28
|
var ssrData = window._SSR_DATA;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
var ssrRequest = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_context = ssrData.context) === null || _ssrData_context === void 0 ? void 0 : _ssrData_context.request;
|
|
30
|
+
var finalSSRData = _object_spread_props(_object_spread({}, ssrData || {
|
|
31
|
+
renderLevel: 0,
|
|
32
|
+
mode: "string"
|
|
33
|
+
}), {
|
|
34
|
+
context: _object_spread_props(_object_spread({}, (ssrData === null || ssrData === void 0 ? void 0 : ssrData.context) || {}), {
|
|
35
|
+
request: _object_spread_props(_object_spread({}, (ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_context1 = ssrData.context) === null || _ssrData_context1 === void 0 ? void 0 : _ssrData_context1.request) || {}), {
|
|
36
|
+
params: (ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.params) || {},
|
|
37
|
+
host: (ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.host) || location.host,
|
|
38
|
+
pathname: (ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.pathname) || location.pathname,
|
|
39
|
+
headers: (ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.headers) || {},
|
|
40
|
+
cookieMap: cookieTool.parse(document.cookie || "") || {},
|
|
41
|
+
cookie: document.cookie || "",
|
|
42
|
+
userAgent: (ssrRequest === null || ssrRequest === void 0 ? void 0 : (_ssrRequest_headers = ssrRequest.headers) === null || _ssrRequest_headers === void 0 ? void 0 : _ssrRequest_headers["user-agent"]) || navigator.userAgent,
|
|
43
|
+
referer: document.referrer,
|
|
44
|
+
query: _object_spread({}, getQuery(), (ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.query) || {}),
|
|
45
|
+
url: location.href
|
|
27
46
|
})
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
return finalSSRData;
|
|
31
50
|
}
|
|
32
51
|
function isClientArgs(id) {
|
|
33
52
|
return typeof id === "undefined" || typeof id === "string" || typeof HTMLElement !== "undefined" && _instanceof(id, HTMLElement);
|
|
@@ -30,7 +30,9 @@ var createLoader = function(id) {
|
|
|
30
30
|
reloading: false,
|
|
31
31
|
data: void 0,
|
|
32
32
|
error: void 0
|
|
33
|
-
}, loaderFn = arguments.length > 2
|
|
33
|
+
}, loaderFn = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : function() {
|
|
34
|
+
return Promise.resolve();
|
|
35
|
+
}, skip = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
|
|
34
36
|
var promise;
|
|
35
37
|
var status = 0;
|
|
36
38
|
var data = initialData.data, error = initialData.error;
|
|
@@ -24,7 +24,10 @@ function createSSRContext(request, options) {
|
|
|
24
24
|
var headersData = parseHeaders(request);
|
|
25
25
|
var url = new URL(request.url);
|
|
26
26
|
var host = headers.get("X-Forwarded-Host") || headers.get("host") || url.host;
|
|
27
|
-
var
|
|
27
|
+
var protocol = (headers.get("X-Forwarded-Proto") || url.protocol || "http").split(/\s*,\s*/, 1)[0];
|
|
28
|
+
if (!protocol.endsWith(":")) {
|
|
29
|
+
protocol += ":";
|
|
30
|
+
}
|
|
28
31
|
var ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
|
|
29
32
|
var ssrMode = getSSRMode(ssrConfig);
|
|
30
33
|
var loaderFailureMode = typeof ssrConfig === "object" ? ssrConfig.loaderFailureMode : void 0;
|
|
@@ -36,7 +39,7 @@ function createSSRContext(request, options) {
|
|
|
36
39
|
logger,
|
|
37
40
|
metrics,
|
|
38
41
|
request: {
|
|
39
|
-
url: request.url.replace(url.host, host).replace(url.protocol,
|
|
42
|
+
url: request.url.replace(url.host, host).replace(url.protocol, protocol),
|
|
40
43
|
baseUrl: route.urlPath,
|
|
41
44
|
userAgent: headers.get("user-agent"),
|
|
42
45
|
cookie,
|
|
@@ -128,11 +128,6 @@ function _generateHtml() {
|
|
|
128
128
|
onError = param.onError, onTiming = param.onTiming;
|
|
129
129
|
end = time();
|
|
130
130
|
html = "";
|
|
131
|
-
if (!(chunkSet.renderLevel >= RenderLevel.SERVER_PREFETCH))
|
|
132
|
-
return [
|
|
133
|
-
3,
|
|
134
|
-
4
|
|
135
|
-
];
|
|
136
131
|
_state.label = 1;
|
|
137
132
|
case 1:
|
|
138
133
|
_state.trys.push([
|
|
@@ -145,9 +140,11 @@ function _generateHtml() {
|
|
|
145
140
|
var _creator_collect;
|
|
146
141
|
return ((_creator_collect = creator.collect) === null || _creator_collect === void 0 ? void 0 : _creator_collect.call(creator, pre)) || pre;
|
|
147
142
|
}, App);
|
|
148
|
-
|
|
143
|
+
if (chunkSet.renderLevel >= RenderLevel.SERVER_PREFETCH) {
|
|
144
|
+
html = ReactDomServer.renderToString(finalApp);
|
|
145
|
+
chunkSet.renderLevel = RenderLevel.SERVER_RENDER;
|
|
146
|
+
}
|
|
149
147
|
helmetData = ReactHelmet.renderStatic();
|
|
150
|
-
chunkSet.renderLevel = RenderLevel.SERVER_RENDER;
|
|
151
148
|
return [
|
|
152
149
|
4,
|
|
153
150
|
Promise.all(collectors.map(function(component) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
2
|
+
import { fs } from "@modern-js/utils";
|
|
3
3
|
import { INDEX_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_POINT_REGISTER_FILE_NAME, ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME, ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME, SERVER_ENTRY_POINT_FILE_NAME, ENTRY_SERVER_BOOTSTRAP_FILE_NAME } from "./constants";
|
|
4
4
|
import * as template from "./template";
|
|
5
5
|
import * as serverTemplate from "./template.server";
|
|
6
|
-
function getSSRMode(entry
|
|
6
|
+
function getSSRMode(entry, config) {
|
|
7
7
|
const { ssr, ssrByEntries } = config.server;
|
|
8
8
|
if (config.output.ssg) {
|
|
9
9
|
return "string";
|
|
@@ -52,6 +52,7 @@ const ssrPlugin = () => ({
|
|
|
52
52
|
"@modern-js/runtime"
|
|
53
53
|
],
|
|
54
54
|
setup: (api) => {
|
|
55
|
+
const appContext = api.useAppContext();
|
|
55
56
|
return {
|
|
56
57
|
// for bundle
|
|
57
58
|
config() {
|
|
@@ -89,7 +90,19 @@ const ssrPlugin = () => ({
|
|
|
89
90
|
}
|
|
90
91
|
},
|
|
91
92
|
tools: {
|
|
92
|
-
babel: babelHandler
|
|
93
|
+
babel: babelHandler,
|
|
94
|
+
bundlerChain: (chain, { isServer }) => {
|
|
95
|
+
if (isServer && appContext.moduleType === "module") {
|
|
96
|
+
chain.output.libraryTarget("module").set("chunkFormat", "module");
|
|
97
|
+
chain.output.library({
|
|
98
|
+
type: "module"
|
|
99
|
+
});
|
|
100
|
+
chain.experiments({
|
|
101
|
+
...chain.get("experiments"),
|
|
102
|
+
outputModule: true
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
93
106
|
}
|
|
94
107
|
};
|
|
95
108
|
}
|
|
@@ -8,24 +8,43 @@ import { wrapRuntimeContextProvider } from "../react/wrapper";
|
|
|
8
8
|
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../constants";
|
|
9
9
|
import { hydrateRoot } from "./hydrate";
|
|
10
10
|
const IS_REACT18 = process.env.IS_REACT18 === "true";
|
|
11
|
+
const getQuery = () => window.location.search.substring(1).split("&").reduce((res, item) => {
|
|
12
|
+
const [key, value] = item.split("=");
|
|
13
|
+
if (key) {
|
|
14
|
+
res[key] = value;
|
|
15
|
+
}
|
|
16
|
+
return res;
|
|
17
|
+
}, {});
|
|
11
18
|
function getSSRData() {
|
|
19
|
+
var _ssrData_context, _ssrData_context1, _ssrRequest_headers;
|
|
12
20
|
const ssrData = window._SSR_DATA;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const ssrRequest = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_context = ssrData.context) === null || _ssrData_context === void 0 ? void 0 : _ssrData_context.request;
|
|
22
|
+
const finalSSRData = {
|
|
23
|
+
...ssrData || {
|
|
24
|
+
renderLevel: 0,
|
|
25
|
+
mode: "string"
|
|
26
|
+
},
|
|
27
|
+
context: {
|
|
28
|
+
...(ssrData === null || ssrData === void 0 ? void 0 : ssrData.context) || {},
|
|
29
|
+
request: {
|
|
30
|
+
...(ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_context1 = ssrData.context) === null || _ssrData_context1 === void 0 ? void 0 : _ssrData_context1.request) || {},
|
|
31
|
+
params: (ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.params) || {},
|
|
32
|
+
host: (ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.host) || location.host,
|
|
33
|
+
pathname: (ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.pathname) || location.pathname,
|
|
34
|
+
headers: (ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.headers) || {},
|
|
35
|
+
cookieMap: cookieTool.parse(document.cookie || "") || {},
|
|
36
|
+
cookie: document.cookie || "",
|
|
37
|
+
userAgent: (ssrRequest === null || ssrRequest === void 0 ? void 0 : (_ssrRequest_headers = ssrRequest.headers) === null || _ssrRequest_headers === void 0 ? void 0 : _ssrRequest_headers["user-agent"]) || navigator.userAgent,
|
|
38
|
+
referer: document.referrer,
|
|
39
|
+
query: {
|
|
40
|
+
...getQuery(),
|
|
41
|
+
...(ssrRequest === null || ssrRequest === void 0 ? void 0 : ssrRequest.query) || {}
|
|
42
|
+
},
|
|
43
|
+
url: location.href
|
|
25
44
|
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return finalSSRData;
|
|
29
48
|
}
|
|
30
49
|
function isClientArgs(id) {
|
|
31
50
|
return typeof id === "undefined" || typeof id === "string" || typeof HTMLElement !== "undefined" && id instanceof HTMLElement;
|
|
@@ -24,7 +24,7 @@ const createLoader = (id, initialData = {
|
|
|
24
24
|
reloading: false,
|
|
25
25
|
data: void 0,
|
|
26
26
|
error: void 0
|
|
27
|
-
}, loaderFn, skip = false) => {
|
|
27
|
+
}, loaderFn = () => Promise.resolve(), skip = false) => {
|
|
28
28
|
let promise;
|
|
29
29
|
let status = 0;
|
|
30
30
|
let { data, error } = initialData;
|
|
@@ -18,7 +18,10 @@ function createSSRContext(request, options) {
|
|
|
18
18
|
const headersData = parseHeaders(request);
|
|
19
19
|
const url = new URL(request.url);
|
|
20
20
|
const host = headers.get("X-Forwarded-Host") || headers.get("host") || url.host;
|
|
21
|
-
|
|
21
|
+
let protocol = (headers.get("X-Forwarded-Proto") || url.protocol || "http").split(/\s*,\s*/, 1)[0];
|
|
22
|
+
if (!protocol.endsWith(":")) {
|
|
23
|
+
protocol += ":";
|
|
24
|
+
}
|
|
22
25
|
const ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
|
|
23
26
|
const ssrMode = getSSRMode(ssrConfig);
|
|
24
27
|
const loaderFailureMode = typeof ssrConfig === "object" ? ssrConfig.loaderFailureMode : void 0;
|
|
@@ -30,7 +33,7 @@ function createSSRContext(request, options) {
|
|
|
30
33
|
logger,
|
|
31
34
|
metrics,
|
|
32
35
|
request: {
|
|
33
|
-
url: request.url.replace(url.host, host).replace(url.protocol,
|
|
36
|
+
url: request.url.replace(url.host, host).replace(url.protocol, protocol),
|
|
34
37
|
baseUrl: route.urlPath,
|
|
35
38
|
userAgent: headers.get("user-agent"),
|
|
36
39
|
cookie,
|
|
@@ -72,22 +72,22 @@ async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifie
|
|
|
72
72
|
const end = time();
|
|
73
73
|
let html = "";
|
|
74
74
|
let helmetData;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
try {
|
|
76
|
+
const finalApp = collectors.reduce((pre, creator) => {
|
|
77
|
+
var _creator_collect;
|
|
78
|
+
return ((_creator_collect = creator.collect) === null || _creator_collect === void 0 ? void 0 : _creator_collect.call(creator, pre)) || pre;
|
|
79
|
+
}, App);
|
|
80
|
+
if (chunkSet.renderLevel >= RenderLevel.SERVER_PREFETCH) {
|
|
81
81
|
html = ReactDomServer.renderToString(finalApp);
|
|
82
|
-
helmetData = ReactHelmet.renderStatic();
|
|
83
82
|
chunkSet.renderLevel = RenderLevel.SERVER_RENDER;
|
|
84
|
-
await Promise.all(collectors.map((component) => component.effect()));
|
|
85
|
-
const cost = end();
|
|
86
|
-
onTiming(SSRTimings.RENDER_HTML, cost);
|
|
87
|
-
} catch (e) {
|
|
88
|
-
chunkSet.renderLevel = RenderLevel.CLIENT_RENDER;
|
|
89
|
-
onError(SSRErrors.RENDER_HTML, e);
|
|
90
83
|
}
|
|
84
|
+
helmetData = ReactHelmet.renderStatic();
|
|
85
|
+
await Promise.all(collectors.map((component) => component.effect()));
|
|
86
|
+
const cost = end();
|
|
87
|
+
onTiming(SSRTimings.RENDER_HTML, cost);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
chunkSet.renderLevel = RenderLevel.CLIENT_RENDER;
|
|
90
|
+
onError(SSRErrors.RENDER_HTML, e);
|
|
91
91
|
}
|
|
92
92
|
const { ssrScripts, cssChunk, jsChunk } = chunkSet;
|
|
93
93
|
const finalHtml = await buildHtml(htmlTemplate, [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Entrypoint } from '@modern-js/types';
|
|
1
|
+
import type { Entrypoint } from '@modern-js/types';
|
|
2
2
|
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
3
3
|
export declare const builderPluginAlias: ({ entrypoints, internalDirectory, metaName, }: {
|
|
4
4
|
entrypoints: Entrypoint[];
|
package/dist/types/cli/code.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AppTools, IAppContext, NormalizedConfig, RuntimePlugin } from '@modern-js/app-tools';
|
|
2
|
-
import { Entrypoint } from '@modern-js/types';
|
|
2
|
+
import type { Entrypoint } from '@modern-js/types';
|
|
3
3
|
import type { MaybeAsync } from '@modern-js/plugin';
|
|
4
4
|
export declare const generateCode: (entrypoints: Entrypoint[], appContext: IAppContext, config: NormalizedConfig<AppTools>, onCollectRuntimePlugins: (params: {
|
|
5
5
|
entrypoint: Entrypoint;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Root } from 'react-dom/client';
|
|
3
|
-
import { RuntimeContext } from '../context';
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { Root } from 'react-dom/client';
|
|
3
|
+
import type { RuntimeContext } from '../context';
|
|
4
4
|
export declare const isReact18: () => boolean;
|
|
5
5
|
export declare function hydrateRoot(App: React.ReactElement, context: RuntimeContext, ModernRender: (App: React.ReactElement) => Promise<HTMLElement | Root>, ModernHydrate: (App: React.ReactElement, callback?: () => void) => Promise<HTMLElement | Root>): Promise<HTMLElement | Root>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Renderer } from 'react-dom';
|
|
3
3
|
import type { hydrateRoot, createRoot } from 'react-dom/client';
|
|
4
|
-
import { RuntimeContext, TRuntimeContext } from './context/runtime';
|
|
5
|
-
import { Plugin, runtime } from './plugin';
|
|
4
|
+
import { type RuntimeContext, type TRuntimeContext } from './context/runtime';
|
|
5
|
+
import { type Plugin, type runtime } from './plugin';
|
|
6
6
|
export type CreateAppOptions = {
|
|
7
7
|
plugins: Plugin[];
|
|
8
8
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { NestedRoute, PageRoute } from '@modern-js/types';
|
|
3
|
-
import { AppConfig } from '../../common';
|
|
3
|
+
import type { AppConfig } from '../../common';
|
|
4
4
|
export { RuntimeReactContext, type RuntimeContext, getInitialContext, } from './runtime';
|
|
5
5
|
interface GlobalContext {
|
|
6
6
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { Store } from '@modern-js-reduck/store';
|
|
3
|
-
import {
|
|
2
|
+
import type { Store } from '@modern-js-reduck/store';
|
|
3
|
+
import type { StaticHandlerContext, Router, RouterState } from '@modern-js/runtime-utils/remix-router';
|
|
4
4
|
import { createLoaderManager } from '../loader/loaderManager';
|
|
5
|
-
import { PluginRunner, runtime } from '../plugin';
|
|
6
|
-
import { RouteManifest } from '../../router/runtime/types';
|
|
7
|
-
import { SSRServerContext } from '../types';
|
|
5
|
+
import type { PluginRunner, runtime } from '../plugin';
|
|
6
|
+
import type { RouteManifest } from '../../router/runtime/types';
|
|
7
|
+
import type { SSRServerContext } from '../types';
|
|
8
8
|
export interface BaseRuntimeContext {
|
|
9
9
|
initialData?: Record<string, unknown>;
|
|
10
10
|
loaderManager: ReturnType<typeof createLoaderManager>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoaderOptions } from './useLoader';
|
|
1
|
+
import type { LoaderOptions } from './useLoader';
|
|
2
2
|
export declare enum LoaderStatus {
|
|
3
3
|
idle = 0,
|
|
4
4
|
loading = 1,
|
|
@@ -12,7 +12,7 @@ export type LoaderResult = {
|
|
|
12
12
|
error: any;
|
|
13
13
|
_error?: any;
|
|
14
14
|
};
|
|
15
|
-
declare const createLoader: (id: string, initialData
|
|
15
|
+
declare const createLoader: (id: string, initialData?: Partial<LoaderResult>, loaderFn?: () => Promise<any>, skip?: boolean) => {
|
|
16
16
|
readonly result: {
|
|
17
17
|
loading: boolean;
|
|
18
18
|
reloading: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { PluginOptions, Setup } from '@modern-js/plugin';
|
|
3
|
-
import { RuntimeContext, TRuntimeContext } from '../context/runtime';
|
|
2
|
+
import { type PluginOptions, type Setup } from '@modern-js/plugin';
|
|
3
|
+
import type { RuntimeContext, TRuntimeContext } from '../context/runtime';
|
|
4
4
|
import type { RuntimeConfig } from './index';
|
|
5
5
|
export declare const RuntimeConfigContext: import("@modern-js/plugin").Context<RuntimeConfig>;
|
|
6
6
|
export declare const useRuntimeConfigContext: () => RuntimeConfig;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { PluginRunner } from './base';
|
|
2
|
+
import { type PluginRunner } from './base';
|
|
3
3
|
export declare function setGlobalRunner(runner: PluginRunner): void;
|
|
4
4
|
export declare function getGlobalRunner(): import("@modern-js/plugin").ToRunners<{
|
|
5
5
|
beforeRender: import("@modern-js/plugin").AsyncInterruptWorkflow<import("..").RuntimeContext, void>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import type React from 'react';
|
|
2
2
|
export declare function createRoot(UserApp?: React.ComponentType | null): React.ComponentType<any>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { RuntimeContext } from '../context';
|
|
2
|
+
import { type RuntimeContext } from '../context';
|
|
3
3
|
export declare function wrapRuntimeContextProvider(App: React.ReactElement, contextValue: RuntimeContext): React.FunctionComponentElement<React.ProviderProps<RuntimeContext>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { HelmetData } from 'react-helmet';
|
|
1
|
+
import type { HelmetData } from 'react-helmet';
|
|
2
2
|
export declare function createReplaceHelemt(helmetData?: HelmetData): (template: string) => string;
|
|
3
3
|
export declare function helmetReplace(content: string, helmetData: HelmetData): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GeneralizedProps, MetaKeyMap, MetaKeyMatch } from './type';
|
|
1
|
+
import type { GeneralizedProps, MetaKeyMap, MetaKeyMatch } from './type';
|
|
2
2
|
export declare const getInnermostProperty: (propsList: GeneralizedProps[], propName: string) => any;
|
|
3
3
|
export declare const getOutermostProperty: (propsList: GeneralizedProps[], propName: string) => any;
|
|
4
4
|
export declare const aggKeysFromPropsList: (propsList: GeneralizedProps[], propName: string) => MetaKeyMap;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RequestHandler, RequestHandlerOptions } from '@modern-js/app-tools';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { RuntimeContext } from '../context';
|
|
1
|
+
import type { RequestHandler, RequestHandlerOptions } from '@modern-js/app-tools';
|
|
2
|
+
import type React from 'react';
|
|
3
|
+
import { type RuntimeContext } from '../context';
|
|
4
4
|
export type { RequestHandlerConfig as HandleRequestConfig } from '@modern-js/app-tools';
|
|
5
5
|
export type HandleRequestOptions = Exclude<RequestHandlerOptions, 'staticGenerate'> & {
|
|
6
6
|
runtimeContext: RuntimeContext;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SSRConfig } from '../shared';
|
|
2
|
-
import { RenderLevel } from '../../constants';
|
|
3
|
-
import { HandleRequestConfig } from '../requestHandler';
|
|
4
|
-
import { RuntimeContext } from '../../context';
|
|
1
|
+
import { type SSRConfig } from '../shared';
|
|
2
|
+
import type { RenderLevel } from '../../constants';
|
|
3
|
+
import type { HandleRequestConfig } from '../requestHandler';
|
|
4
|
+
import type { RuntimeContext } from '../../context';
|
|
5
5
|
export type BuildShellAfterTemplateOptions = {
|
|
6
6
|
runtimeContext: RuntimeContext;
|
|
7
7
|
renderLevel: RenderLevel;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RuntimeContext } from '../../context';
|
|
2
|
-
import { HandleRequestConfig } from '../requestHandler';
|
|
1
|
+
import type { RuntimeContext } from '../../context';
|
|
2
|
+
import type { HandleRequestConfig } from '../requestHandler';
|
|
3
3
|
export interface BuildShellBeforeTemplateOptions {
|
|
4
4
|
runtimeContext: RuntimeContext;
|
|
5
5
|
entryName: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CreateReadableStreamFromElement } from './shared';
|
|
1
|
+
import { type CreateReadableStreamFromElement } from './shared';
|
|
2
2
|
export declare const createReadableStreamFromElement: CreateReadableStreamFromElement;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CreateReadableStreamFromElement } from './shared';
|
|
1
|
+
import { type CreateReadableStreamFromElement } from './shared';
|
|
2
2
|
export declare const createReadableStreamFromElement: CreateReadableStreamFromElement;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { RuntimeContext } from '../../context';
|
|
3
|
-
import { HandleRequestConfig } from '../requestHandler';
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { RuntimeContext } from '../../context';
|
|
3
|
+
import type { HandleRequestConfig } from '../requestHandler';
|
|
4
4
|
import type { RenderStreaming, SSRConfig } from '../shared';
|
|
5
5
|
export type CreateReadableStreamFromElementOptions = {
|
|
6
6
|
runtimeContext: RuntimeContext;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RenderString } from '../shared';
|
|
1
|
+
import { type RenderString } from '../shared';
|
|
2
2
|
export declare const renderString: RenderString;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { LoaderResult } from '../../loader/loaderManager';
|
|
3
|
-
import { HandleRequestOptions } from '../requestHandler';
|
|
4
|
-
import { Tracer } from '../tracer';
|
|
5
|
-
import { SSRConfig } from '../shared';
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { LoaderResult } from '../../loader/loaderManager';
|
|
3
|
+
import type { HandleRequestOptions } from '../requestHandler';
|
|
4
|
+
import { type Tracer } from '../tracer';
|
|
5
|
+
import type { SSRConfig } from '../shared';
|
|
6
6
|
export declare const prefetch: (App: React.ReactElement, request: Request, options: HandleRequestOptions, ssrConfig: SSRConfig, { onError, onTiming }: Tracer) => Promise<{
|
|
7
7
|
initialData: Record<string, unknown> | undefined;
|
|
8
8
|
i18nData: any;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { StaticHandlerContext } from '@modern-js/runtime-utils/remix-router';
|
|
2
|
-
import { SSRConfig } from '../shared';
|
|
3
|
-
import { SSRServerContext } from '../../types';
|
|
4
|
-
import { Collector, ChunkSet } from './types';
|
|
1
|
+
import type { StaticHandlerContext } from '@modern-js/runtime-utils/remix-router';
|
|
2
|
+
import type { SSRConfig } from '../shared';
|
|
3
|
+
import type { SSRServerContext } from '../../types';
|
|
4
|
+
import type { Collector, ChunkSet } from './types';
|
|
5
5
|
export interface SSRDataCreatorOptions {
|
|
6
6
|
request: Request;
|
|
7
7
|
prefetchData: Record<string, any>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReactElement } from 'react';
|
|
2
|
-
import { RenderLevel } from '../../constants';
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { RenderLevel } from '../../constants';
|
|
3
3
|
export interface Collector {
|
|
4
4
|
collect?: (comopnent: ReactElement) => ReactElement;
|
|
5
5
|
effect: () => void | Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { StaticHandlerContext } from '@modern-js/runtime-utils/remix-router';
|
|
2
|
-
import { ServerUserConfig } from '@modern-js/app-tools';
|
|
3
|
-
import { SSRConfig } from './shared';
|
|
1
|
+
import { type StaticHandlerContext } from '@modern-js/runtime-utils/remix-router';
|
|
2
|
+
import type { ServerUserConfig } from '@modern-js/app-tools';
|
|
3
|
+
import type { SSRConfig } from './shared';
|
|
4
4
|
export declare function attributesToString(attributes: Record<string, any>): string;
|
|
5
5
|
/**
|
|
6
6
|
* @param source
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CliPlugin, AppTools } from '@modern-js/app-tools';
|
|
2
|
-
import { Entrypoint } from '@modern-js/types/cli';
|
|
2
|
+
import type { Entrypoint } from '@modern-js/types/cli';
|
|
3
3
|
export declare const getDocumenByEntryName: (entrypoints: Entrypoint[], entryName: string, fallbackDir?: string) => string | undefined;
|
|
4
4
|
export declare const documentPlugin: () => CliPlugin<AppTools>;
|
|
5
5
|
export default documentPlugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AfterMatchContext, AfterRenderContext, MiddlewareContext, NextFunction } from '@modern-js/types';
|
|
1
|
+
import type { AfterMatchContext, AfterRenderContext, MiddlewareContext, NextFunction } from '@modern-js/types';
|
|
2
2
|
export type { Container, CacheControl, CacheOptionProvider, CacheOption, UnstableMiddlewareContext, UnstableMiddleware, UnstableNext, MonitorEvent, Monitors, CoreMonitor, LogEvent, LogLevel, TimingEvent, } from '@modern-js/types';
|
|
3
3
|
export declare const hook: (attacher: ({ addMiddleware, afterMatch, afterRender, }: {
|
|
4
4
|
addMiddleware: (mid: Middleware) => void;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export { isBrowser } from './common';
|
|
|
6
6
|
export type { BaseRuntimeContext, RuntimeContext, BaseTRuntimeContext, } from './core/context/runtime';
|
|
7
7
|
export type { RuntimeUserConfig } from './config';
|
|
8
8
|
export { createApp, useLoader, bootstrap, RuntimeReactContext, defineConfig, defineRuntimeConfig, useRuntimeContext, } from './core';
|
|
9
|
-
export { StateConfig, RouterConfig };
|
|
9
|
+
export type { StateConfig, RouterConfig };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IAppContext, PluginAPI } from '@modern-js/core';
|
|
1
|
+
import type { IAppContext, PluginAPI } from '@modern-js/core';
|
|
2
2
|
import type { Entrypoint } from '@modern-js/types';
|
|
3
|
-
import { AppNormalizedConfig, AppTools } from '@modern-js/app-tools';
|
|
3
|
+
import type { AppNormalizedConfig, AppTools } from '@modern-js/app-tools';
|
|
4
4
|
export declare const generateCode: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>, entrypoints: Entrypoint[], api: PluginAPI<AppTools<'shared'>>) => Promise<void>;
|
|
5
5
|
export declare function generatorRegisterCode(internalDirectory: string, entryName: string, code: string): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Entrypoint } from '@modern-js/types';
|
|
1
|
+
import type { Entrypoint } from '@modern-js/types';
|
|
2
2
|
export declare const hasPages: (dir: string) => boolean;
|
|
3
3
|
export declare const hasNestedRoutes: (dir: string) => boolean;
|
|
4
4
|
export declare const isRouteEntry: (dir: string) => string | false;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Entrypoint } from '@modern-js/types';
|
|
2
|
-
import { PluginAPI } from '@modern-js/core';
|
|
3
|
-
import { AppTools } from '@modern-js/app-tools';
|
|
1
|
+
import type { Entrypoint } from '@modern-js/types';
|
|
2
|
+
import type { PluginAPI } from '@modern-js/core';
|
|
3
|
+
import type { AppTools } from '@modern-js/app-tools';
|
|
4
4
|
export declare function handleModifyEntrypoints(api: PluginAPI<AppTools<'shared'>>, entrypoints: Entrypoint[]): Promise<Entrypoint[]>;
|
|
5
5
|
export declare function handleGeneratorEntryCode(api: PluginAPI<AppTools<'shared'>>, entrypoints: Entrypoint[]): Promise<Entrypoint[]>;
|
|
6
6
|
export declare function handleFileChange(api: PluginAPI<AppTools<'shared'>>, e: any): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { StaticHandlerContext } from '@modern-js/runtime-utils/remix-router';
|
|
2
|
+
import type { StaticHandlerContext } from '@modern-js/runtime-utils/remix-router';
|
|
3
3
|
/**
|
|
4
4
|
* DeferredDataScripts only renders in server side,
|
|
5
5
|
* it doesn't need to be hydrated in client side.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { LinkProps as RouterLinkProps, NavLinkProps as RouterNavLinkProps } from '@modern-js/runtime-utils/router';
|
|
2
|
+
import { type LinkProps as RouterLinkProps, type NavLinkProps as RouterNavLinkProps } from '@modern-js/runtime-utils/router';
|
|
3
3
|
export declare function composeEventHandlers<EventType extends React.SyntheticEvent | Event>(theirHandler: ((event: EventType) => any) | undefined, ourHandler: (event: EventType) => any): (event: EventType) => any;
|
|
4
4
|
/**
|
|
5
5
|
* Modified from https://github.com/remix-run/remix/blob/9a0601bd704d2f3ee622e0ddacab9b611eb0c5bc/packages/remix-react/components.tsx#L218
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type Module from 'module';
|
|
3
|
-
import { ShouldRevalidateFunction } from '@modern-js/runtime-utils/remix-router';
|
|
3
|
+
import type { ShouldRevalidateFunction } from '@modern-js/runtime-utils/remix-router';
|
|
4
4
|
export declare const createShouldRevalidate: (routeId: string) => ShouldRevalidateFunction;
|
|
5
5
|
export declare const handleRouteModule: (routeModule: Module, routeId: string) => Module;
|
|
6
6
|
export declare const handleRouteModuleError: (error: Error) => null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { RouteProps, RouteObject, Params } from '@modern-js/runtime-utils/router';
|
|
3
|
-
import { PageRoute, NestedRoute } from '@modern-js/types';
|
|
3
|
+
import type { PageRoute, NestedRoute } from '@modern-js/types';
|
|
4
4
|
import type { RequestContext } from '@modern-js/runtime-utils/node';
|
|
5
5
|
declare global {
|
|
6
6
|
interface Window {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import type React from 'react';
|
|
2
2
|
import type { Reporter, NestedRoute, PageRoute, SSRMode } from '@modern-js/types';
|
|
3
3
|
import { type StaticHandlerContext, type Router } from '@modern-js/runtime-utils/remix-router';
|
|
4
|
-
import { RouterConfig } from './types';
|
|
4
|
+
import type { RouterConfig } from './types';
|
|
5
5
|
export declare function getRouteComponents(routes: (NestedRoute | PageRoute)[], { globalApp, ssrMode, props, reporter, }: {
|
|
6
6
|
globalApp?: React.ComponentType<any>;
|
|
7
7
|
ssrMode?: SSRMode;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.58.2
|
|
18
|
+
"version": "2.58.2",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -199,11 +199,11 @@
|
|
|
199
199
|
"react-is": "^18",
|
|
200
200
|
"react-side-effect": "^2.1.1",
|
|
201
201
|
"styled-components": "^5.3.1",
|
|
202
|
-
"@modern-js/plugin": "2.58.
|
|
203
|
-
"@modern-js/plugin-data-loader": "2.58.
|
|
204
|
-
"@modern-js/
|
|
205
|
-
"@modern-js/
|
|
206
|
-
"@modern-js/runtime-utils": "2.58.
|
|
202
|
+
"@modern-js/plugin": "2.58.2",
|
|
203
|
+
"@modern-js/plugin-data-loader": "2.58.2",
|
|
204
|
+
"@modern-js/utils": "2.58.2",
|
|
205
|
+
"@modern-js/types": "2.58.2",
|
|
206
|
+
"@modern-js/runtime-utils": "2.58.2"
|
|
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.1-beta.
|
|
214
|
+
"@rsbuild/core": "1.0.1-beta.14",
|
|
215
215
|
"@testing-library/react": "^13.4.0",
|
|
216
216
|
"@types/cookie": "0.5.1",
|
|
217
217
|
"@types/invariant": "^2.2.30",
|
|
@@ -226,15 +226,16 @@
|
|
|
226
226
|
"ts-jest": "^29.1.0",
|
|
227
227
|
"typescript": "^5",
|
|
228
228
|
"webpack": "^5.93.0",
|
|
229
|
-
"@modern-js/
|
|
230
|
-
"@modern-js/
|
|
231
|
-
"@scripts/build": "2.58.
|
|
232
|
-
"@scripts/jest-config": "2.58.
|
|
229
|
+
"@modern-js/core": "2.58.2",
|
|
230
|
+
"@modern-js/app-tools": "2.58.2",
|
|
231
|
+
"@scripts/build": "2.58.2",
|
|
232
|
+
"@scripts/jest-config": "2.58.2"
|
|
233
233
|
},
|
|
234
234
|
"sideEffects": false,
|
|
235
235
|
"publishConfig": {
|
|
236
236
|
"registry": "https://registry.npmjs.org/",
|
|
237
|
-
"access": "public"
|
|
237
|
+
"access": "public",
|
|
238
|
+
"provenance": true
|
|
238
239
|
},
|
|
239
240
|
"scripts": {
|
|
240
241
|
"dev": "modern-lib build --watch",
|
package/types/index.d.ts
CHANGED
package/types/router.d.ts
CHANGED