@modern-js/runtime 2.67.11 → 2.68.1
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/alias.js +1 -1
- package/dist/cjs/cli/code.js +6 -3
- package/dist/cjs/cli/index.js +4 -2
- package/dist/cjs/cli/ssr/index.js +1 -1
- package/dist/cjs/cli/template.js +72 -21
- package/dist/cjs/cli/template.server.js +62 -13
- package/dist/cjs/core/context/index.js +19 -2
- package/dist/cjs/core/context/serverPayload.server.js +40 -0
- package/dist/cjs/core/server/requestHandler.js +47 -11
- package/dist/cjs/router/cli/code/index.js +13 -6
- package/dist/cjs/router/cli/code/templates.js +44 -20
- package/dist/cjs/router/cli/handler.js +17 -2
- package/dist/cjs/router/cli/index.js +6 -5
- package/dist/cjs/router/index.js +0 -21
- package/dist/cjs/router/internal.js +30 -0
- package/dist/cjs/router/runtime/PrefetchLink.js +3 -4
- package/dist/cjs/router/runtime/constants.js +2 -2
- package/dist/cjs/router/runtime/index.js +1 -12
- package/dist/cjs/router/runtime/internal.js +36 -0
- package/dist/cjs/router/runtime/plugin.js +135 -76
- package/dist/cjs/router/runtime/plugin.node.js +73 -32
- package/dist/cjs/router/runtime/rsc-router.js +322 -0
- package/dist/cjs/router/runtime/utils.js +76 -1
- package/dist/cjs/rsc/client.js +11 -0
- package/dist/cjs/rsc/server.js +40 -0
- package/dist/esm/cli/alias.js +1 -1
- package/dist/esm/cli/code.js +6 -3
- package/dist/esm/cli/index.js +4 -2
- package/dist/esm/cli/ssr/index.js +1 -1
- package/dist/esm/cli/template.js +25 -6
- package/dist/esm/cli/template.server.js +3 -3
- package/dist/esm/core/context/index.js +14 -1
- package/dist/esm/core/context/serverPayload.server.js +15 -0
- package/dist/esm/core/server/requestHandler.js +102 -9
- package/dist/esm/router/cli/code/index.js +12 -6
- package/dist/esm/router/cli/code/templates.js +29 -13
- package/dist/esm/router/cli/handler.js +33 -6
- package/dist/esm/router/cli/index.js +6 -5
- package/dist/esm/router/index.js +0 -6
- package/dist/esm/router/internal.js +5 -0
- package/dist/esm/router/runtime/PrefetchLink.js +2 -2
- package/dist/esm/router/runtime/constants.js +2 -2
- package/dist/esm/router/runtime/index.js +1 -9
- package/dist/esm/router/runtime/internal.js +10 -0
- package/dist/esm/router/runtime/plugin.js +135 -85
- package/dist/esm/router/runtime/plugin.node.js +110 -40
- package/dist/esm/router/runtime/rsc-router.js +437 -0
- package/dist/esm/router/runtime/utils.js +95 -1
- package/dist/esm/rsc/client.js +6 -0
- package/dist/esm/rsc/server.js +86 -0
- package/dist/esm-node/cli/alias.js +1 -1
- package/dist/esm-node/cli/code.js +6 -3
- package/dist/esm-node/cli/index.js +4 -2
- package/dist/esm-node/cli/ssr/index.js +1 -1
- package/dist/esm-node/cli/template.js +72 -21
- package/dist/esm-node/cli/template.server.js +62 -13
- package/dist/esm-node/core/context/index.js +14 -1
- package/dist/esm-node/core/context/serverPayload.server.js +15 -0
- package/dist/esm-node/core/server/requestHandler.js +45 -9
- package/dist/esm-node/router/cli/code/index.js +12 -6
- package/dist/esm-node/router/cli/code/templates.js +44 -20
- package/dist/esm-node/router/cli/handler.js +17 -2
- package/dist/esm-node/router/cli/index.js +6 -5
- package/dist/esm-node/router/index.js +0 -6
- package/dist/esm-node/router/internal.js +5 -0
- package/dist/esm-node/router/runtime/PrefetchLink.js +2 -2
- package/dist/esm-node/router/runtime/constants.js +2 -2
- package/dist/esm-node/router/runtime/index.js +1 -9
- package/dist/esm-node/router/runtime/internal.js +10 -0
- package/dist/esm-node/router/runtime/plugin.js +127 -78
- package/dist/esm-node/router/runtime/plugin.node.js +75 -34
- package/dist/esm-node/router/runtime/rsc-router.js +284 -0
- package/dist/esm-node/router/runtime/utils.js +74 -1
- package/dist/esm-node/rsc/client.js +6 -0
- package/dist/esm-node/rsc/server.js +35 -0
- package/dist/types/cli/template.d.ts +4 -2
- package/dist/types/cli/template.server.d.ts +2 -1
- package/dist/types/common.d.ts +1 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/core/context/index.d.ts +38 -3
- package/dist/types/core/context/serverPayload.server.d.ts +3 -0
- package/dist/types/core/server/requestHandler.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/router/cli/code/index.d.ts +1 -0
- package/dist/types/router/cli/code/templates.d.ts +4 -2
- package/dist/types/router/index.d.ts +0 -2
- package/dist/types/router/internal.d.ts +2 -0
- package/dist/types/router/runtime/PrefetchLink.d.ts +0 -1
- package/dist/types/router/runtime/constants.d.ts +3 -3
- package/dist/types/router/runtime/index.d.ts +1 -9
- package/dist/types/router/runtime/internal.d.ts +8 -0
- package/dist/types/router/runtime/rsc-router.d.ts +14 -0
- package/dist/types/router/runtime/utils.d.ts +26 -5
- package/dist/types/rsc/client.d.ts +1 -0
- package/dist/types/rsc/server.d.ts +1 -0
- package/package.json +22 -13
- package/static/modern-inline.js +1 -1
package/dist/cjs/cli/alias.js
CHANGED
package/dist/cjs/cli/code.js
CHANGED
|
@@ -71,7 +71,8 @@ const generateCode = async (entrypoints, appContext, config, hooks) => {
|
|
|
71
71
|
metaName,
|
|
72
72
|
entryName,
|
|
73
73
|
mountId,
|
|
74
|
-
urlPath: (_serverRoutes_find = serverRoutes.find((route) => route.entryName === entryName)) === null || _serverRoutes_find === void 0 ? void 0 : _serverRoutes_find.urlPath
|
|
74
|
+
urlPath: (_serverRoutes_find = serverRoutes.find((route) => route.entryName === entryName)) === null || _serverRoutes_find === void 0 ? void 0 : _serverRoutes_find.urlPath,
|
|
75
|
+
isNestedRouter: entrypoint.nestedRoutesEntry
|
|
75
76
|
});
|
|
76
77
|
} else {
|
|
77
78
|
indexCode = template.index({
|
|
@@ -83,7 +84,8 @@ const generateCode = async (entrypoints, appContext, config, hooks) => {
|
|
|
83
84
|
customEntry,
|
|
84
85
|
customBootstrap,
|
|
85
86
|
mountId,
|
|
86
|
-
enableRsc: config.server.rsc
|
|
87
|
+
enableRsc: config.server.rsc,
|
|
88
|
+
isNestedRouter: !!entrypoint.nestedRoutesEntry
|
|
87
89
|
});
|
|
88
90
|
}
|
|
89
91
|
const indexFile = import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_POINT_FILE_NAME}`);
|
|
@@ -112,6 +114,7 @@ const generateCode = async (entrypoints, appContext, config, hooks) => {
|
|
|
112
114
|
} else if (config.server.rsc) {
|
|
113
115
|
const indexServerFile = import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.SERVER_ENTRY_POINT_FILE_NAME}`);
|
|
114
116
|
const indexServerCode = serverTemplate.entryForCSRWithRSC({
|
|
117
|
+
entryName,
|
|
115
118
|
metaName
|
|
116
119
|
});
|
|
117
120
|
await import_utils.fs.outputFile(indexServerFile, indexServerCode, "utf8");
|
|
@@ -130,7 +133,7 @@ const generateCode = async (entrypoints, appContext, config, hooks) => {
|
|
|
130
133
|
const registerRuntimeFile = import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME}`);
|
|
131
134
|
await import_utils.fs.outputFile(registerRuntimeFile, registerRuntimeCode, "utf8");
|
|
132
135
|
let contextCode = "";
|
|
133
|
-
if (!config.server.rsc) {
|
|
136
|
+
if (!config.server.rsc || entrypoint.nestedRoutesEntry) {
|
|
134
137
|
contextCode = template.runtimeGlobalContext({
|
|
135
138
|
entryName,
|
|
136
139
|
srcDirectory,
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -105,7 +105,7 @@ const runtimePlugin = (params) => ({
|
|
|
105
105
|
return {
|
|
106
106
|
runtime: {},
|
|
107
107
|
runtimeByEntries: {},
|
|
108
|
-
|
|
108
|
+
resolve: {
|
|
109
109
|
alias: {
|
|
110
110
|
/**
|
|
111
111
|
* twin.macro inserts styled-components into the code during the compilation process
|
|
@@ -121,7 +121,9 @@ const runtimePlugin = (params) => ({
|
|
|
121
121
|
"@meta/runtime/react$": require.resolve("@modern-js/runtime/react"),
|
|
122
122
|
"@meta/runtime/context$": require.resolve("@modern-js/runtime/context"),
|
|
123
123
|
"@meta/runtime$": require.resolve("@modern-js/runtime")
|
|
124
|
-
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
source: {
|
|
125
127
|
globalVars: {
|
|
126
128
|
"process.env.IS_REACT18": process.env.IS_REACT18
|
|
127
129
|
}
|
|
@@ -118,7 +118,7 @@ const ssrPlugin = () => ({
|
|
|
118
118
|
builderPlugins: [
|
|
119
119
|
ssrBuilderPlugin(api)
|
|
120
120
|
],
|
|
121
|
-
|
|
121
|
+
resolve: {
|
|
122
122
|
alias: {
|
|
123
123
|
// ensure that all packages use the same storage in @modern-js/runtime-utils/node
|
|
124
124
|
"@modern-js/runtime-utils/node$": require.resolve("@modern-js/runtime-utils/node").replace(`${import_path.default.sep}cjs${import_path.default.sep}`, `${import_path.default.sep}esm${import_path.default.sep}`)
|
package/dist/cjs/cli/template.js
CHANGED
|
@@ -41,7 +41,21 @@ module.exports = __toCommonJS(template_exports);
|
|
|
41
41
|
var import_path = __toESM(require("path"));
|
|
42
42
|
var import_utils = require("@modern-js/utils");
|
|
43
43
|
var import_constants = require("./constants");
|
|
44
|
-
const
|
|
44
|
+
const genRenderStatement = ({ customBootstrap, enableRsc, mountId, isNestedRouter }) => {
|
|
45
|
+
if (customBootstrap) {
|
|
46
|
+
return `customBootstrap(ModernRoot, () => render(<ModernRoot />, '${mountId || "root"}'));`;
|
|
47
|
+
}
|
|
48
|
+
if (enableRsc) {
|
|
49
|
+
if (!isNestedRouter) {
|
|
50
|
+
return `render(<ModernRoot>
|
|
51
|
+
<RscClientRoot rscPayload={data} />
|
|
52
|
+
</ModernRoot>, '${mountId || "root"}');`;
|
|
53
|
+
}
|
|
54
|
+
return `render(<ModernRoot rscPayload={data} />, '${mountId || "root"}');`;
|
|
55
|
+
}
|
|
56
|
+
return `render(<ModernRoot />, '${mountId || "root"}');`;
|
|
57
|
+
};
|
|
58
|
+
const genRenderCode = ({ srcDirectory, internalSrcAlias, metaName, entry, customEntry, customBootstrap, mountId, enableRsc, isNestedRouter }) => {
|
|
45
59
|
if (customEntry) {
|
|
46
60
|
return `import '${(0, import_utils.formatImportPath)(entry.replace(srcDirectory, internalSrcAlias))}'`;
|
|
47
61
|
}
|
|
@@ -60,11 +74,14 @@ ${customBootstrap ? `import customBootstrap from '${(0, import_utils.formatImpor
|
|
|
60
74
|
|
|
61
75
|
const ModernRoot = createRoot();
|
|
62
76
|
|
|
63
|
-
${
|
|
64
|
-
|
|
65
|
-
|
|
77
|
+
${genRenderStatement({
|
|
78
|
+
customBootstrap,
|
|
79
|
+
enableRsc,
|
|
80
|
+
mountId,
|
|
81
|
+
isNestedRouter
|
|
82
|
+
})}`;
|
|
66
83
|
};
|
|
67
|
-
const entryForCSRWithRSC = ({ metaName, entryName, urlPath = "/", mountId = "root" }) => {
|
|
84
|
+
const entryForCSRWithRSC = ({ metaName, entryName, urlPath = "/", mountId = "root", isNestedRouter }) => {
|
|
68
85
|
return `
|
|
69
86
|
import '@${metaName}/runtime/registry/${entryName}';
|
|
70
87
|
import { render } from '@${metaName}/runtime/browser';
|
|
@@ -72,28 +89,61 @@ const entryForCSRWithRSC = ({ metaName, entryName, urlPath = "/", mountId = "roo
|
|
|
72
89
|
|
|
73
90
|
import {
|
|
74
91
|
RscClientRoot,
|
|
75
|
-
createFromFetch
|
|
92
|
+
createFromFetch,
|
|
93
|
+
isRedirectResponse,
|
|
94
|
+
rscStream,
|
|
95
|
+
callServer,
|
|
96
|
+
createFromReadableStream
|
|
76
97
|
} from '@${metaName}/runtime/rsc/client';
|
|
77
98
|
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
99
|
+
const handleRedirectResponse = (res: Response) => {
|
|
100
|
+
const { headers } = res;
|
|
101
|
+
const location = headers.get('X-Modernjs-Redirect');
|
|
102
|
+
const baseUrl = headers.get('X-Modernjs-BaseUrl');
|
|
103
|
+
if (location) {
|
|
104
|
+
if (baseUrl !== '/') {
|
|
105
|
+
window.location.replace(baseUrl + location);
|
|
106
|
+
} else {
|
|
107
|
+
window.location.replace(location);
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
return res;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
${process.env.MODERN_DISABLE_INJECT_RSC_DATA ? `
|
|
115
|
+
const data = createFromFetch(
|
|
116
|
+
fetch(location.pathname, {
|
|
117
|
+
headers: {
|
|
118
|
+
'x-rsc-tree': 'true',
|
|
119
|
+
},
|
|
120
|
+
}).then(handleRedirectResponse),
|
|
121
|
+
)
|
|
122
|
+
` : `
|
|
123
|
+
const data = createFromReadableStream(rscStream, {
|
|
124
|
+
callServer: callServer,
|
|
125
|
+
});
|
|
126
|
+
`}
|
|
85
127
|
|
|
86
128
|
const ModernRoot = createRoot();
|
|
87
129
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
130
|
+
${isNestedRouter ? `
|
|
131
|
+
render(
|
|
132
|
+
<ModernRoot rscPayload={data}>
|
|
133
|
+
</ModernRoot>,
|
|
134
|
+
'${mountId}',
|
|
135
|
+
);
|
|
136
|
+
` : `
|
|
137
|
+
render(
|
|
138
|
+
<ModernRoot>
|
|
139
|
+
<RscClientRoot rscPayload={data} />
|
|
140
|
+
</ModernRoot>,
|
|
141
|
+
'${mountId}',
|
|
142
|
+
);
|
|
143
|
+
`}
|
|
94
144
|
`;
|
|
95
145
|
};
|
|
96
|
-
const index = ({ srcDirectory, internalSrcAlias, metaName, entry, entryName, customEntry, customBootstrap, mountId, enableRsc }) => `import '@${metaName}/runtime/registry/${entryName}';
|
|
146
|
+
const index = ({ srcDirectory, internalSrcAlias, metaName, entry, entryName, customEntry, customBootstrap, mountId, enableRsc, isNestedRouter }) => `import '@${metaName}/runtime/registry/${entryName}';
|
|
97
147
|
${genRenderCode({
|
|
98
148
|
srcDirectory,
|
|
99
149
|
internalSrcAlias,
|
|
@@ -102,7 +152,8 @@ ${genRenderCode({
|
|
|
102
152
|
customEntry,
|
|
103
153
|
customBootstrap,
|
|
104
154
|
mountId,
|
|
105
|
-
enableRsc
|
|
155
|
+
enableRsc,
|
|
156
|
+
isNestedRouter
|
|
106
157
|
})}
|
|
107
158
|
`;
|
|
108
159
|
const register = () => `import './${import_constants.ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME}';
|
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
createRequestHandler,
|
|
49
49
|
} from '@#metaName/runtime/ssr/server';
|
|
50
50
|
import { RSCServerSlot } from '@#metaName/runtime/rsc/client';
|
|
51
|
+
import { renderRsc } from '@#metaName/runtime/rsc/server';
|
|
51
52
|
export { handleAction } from '@#metaName/runtime/rsc/server';
|
|
52
53
|
|
|
53
54
|
const handleRequest = async (request, ServerRoot, options) => {
|
|
@@ -58,7 +59,7 @@ const handleRequest = async (request, ServerRoot, options) => {
|
|
|
58
59
|
</ServerRoot>,
|
|
59
60
|
{
|
|
60
61
|
...options,
|
|
61
|
-
rscRoot:
|
|
62
|
+
rscRoot: options.rscRoot,
|
|
62
63
|
},
|
|
63
64
|
);
|
|
64
65
|
|
|
@@ -70,7 +71,22 @@ const handleRequest = async (request, ServerRoot, options) => {
|
|
|
70
71
|
};
|
|
71
72
|
|
|
72
73
|
export const requestHandler = createRequestHandler(handleRequest, {
|
|
73
|
-
enableRsc: true
|
|
74
|
+
enableRsc: true
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const handleRSCRequest = async (request, ServerRoot, options) => {
|
|
78
|
+
const { serverPayload } = options;
|
|
79
|
+
const stream = renderRsc({
|
|
80
|
+
element: options.rscRoot,
|
|
81
|
+
clientManifest: options.rscClientManifest!,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return new Response(stream);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
export const rscPayloadHandler = createRequestHandler(handleRSCRequest, {
|
|
89
|
+
enableRsc: true
|
|
74
90
|
});
|
|
75
91
|
`;
|
|
76
92
|
const serverIndex = (options) => {
|
|
@@ -80,24 +96,57 @@ const serverIndex = (options) => {
|
|
|
80
96
|
${genHandlerCode(options)}
|
|
81
97
|
`;
|
|
82
98
|
};
|
|
83
|
-
const entryForCSRWithRSC = ({ metaName }) => {
|
|
99
|
+
const entryForCSRWithRSC = ({ metaName, entryName }) => {
|
|
84
100
|
return `
|
|
85
|
-
import
|
|
86
|
-
import {
|
|
101
|
+
import '@${metaName}/runtime/registry/${entryName}';
|
|
102
|
+
import {
|
|
103
|
+
createRequestHandler,
|
|
104
|
+
} from '@${metaName}/runtime/ssr/server';
|
|
105
|
+
import { renderRsc, processRSCStream } from '@${metaName}/runtime/rsc/server'
|
|
87
106
|
export { handleAction } from '@${metaName}/runtime/rsc/server';
|
|
88
107
|
|
|
108
|
+
const handleCSRRender = async (request, ServerRoot, options) => {
|
|
109
|
+
const rscPayloadStream = renderRsc({
|
|
110
|
+
element: options.rscRoot,
|
|
111
|
+
clientManifest: options.rscClientManifest!,
|
|
112
|
+
});
|
|
113
|
+
const stream = new ReadableStream({
|
|
114
|
+
start(controller) {
|
|
115
|
+
const encoder = new TextEncoder();
|
|
116
|
+
|
|
117
|
+
controller.enqueue(encoder.encode(options.html));
|
|
89
118
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
119
|
+
processRSCStream(rscPayloadStream, controller, encoder)
|
|
120
|
+
.catch(err => {
|
|
121
|
+
controller.error(err);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return new Response(stream, {
|
|
127
|
+
status: 200,
|
|
128
|
+
headers: new Headers({
|
|
129
|
+
'content-type': 'text/html; charset=UTF-8',
|
|
130
|
+
}),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export const renderRscStreamHandler = createRequestHandler(handleCSRRender, {
|
|
135
|
+
enableRsc: true
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const handleRequest = async (request, ServerRoot, options) => {
|
|
93
139
|
const stream = renderRsc({
|
|
94
|
-
|
|
95
|
-
clientManifest
|
|
96
|
-
})
|
|
140
|
+
element: options.rscRoot,
|
|
141
|
+
clientManifest: options.rscClientManifest!,
|
|
142
|
+
});
|
|
97
143
|
|
|
98
|
-
|
|
99
|
-
return response
|
|
144
|
+
return new Response(stream);
|
|
100
145
|
}
|
|
146
|
+
|
|
147
|
+
export const rscPayloadHandler = createRequestHandler(handleRequest, {
|
|
148
|
+
enableRsc: true
|
|
149
|
+
});
|
|
101
150
|
`;
|
|
102
151
|
};
|
|
103
152
|
function genHandlerCode({ mode, metaName, customServerEntry, srcDirectory, internalSrcAlias, enableRsc }) {
|
|
@@ -23,17 +23,28 @@ __export(context_exports, {
|
|
|
23
23
|
getGlobalApp: () => getGlobalApp,
|
|
24
24
|
getGlobalAppConfig: () => getGlobalAppConfig,
|
|
25
25
|
getGlobalAppInit: () => getGlobalAppInit,
|
|
26
|
+
getGlobalEnableRsc: () => getGlobalEnableRsc,
|
|
26
27
|
getGlobalInternalRuntimeContext: () => getGlobalInternalRuntimeContext,
|
|
28
|
+
getGlobalIsRscClient: () => getGlobalIsRscClient,
|
|
27
29
|
getGlobalLayoutApp: () => getGlobalLayoutApp,
|
|
28
30
|
getGlobalRSCRoot: () => getGlobalRSCRoot,
|
|
29
31
|
getGlobalRoutes: () => getGlobalRoutes,
|
|
30
32
|
getInitialContext: () => import_runtime.getInitialContext,
|
|
33
|
+
getServerPayload: () => import_serverPayload.getServerPayload,
|
|
31
34
|
setGlobalContext: () => setGlobalContext,
|
|
32
|
-
setGlobalInternalRuntimeContext: () => setGlobalInternalRuntimeContext
|
|
35
|
+
setGlobalInternalRuntimeContext: () => setGlobalInternalRuntimeContext,
|
|
36
|
+
setServerPayload: () => import_serverPayload.setServerPayload
|
|
33
37
|
});
|
|
34
38
|
module.exports = __toCommonJS(context_exports);
|
|
35
39
|
var import_runtime = require("./runtime");
|
|
40
|
+
var import_serverPayload = require("./serverPayload.server");
|
|
36
41
|
const globalContext = {};
|
|
42
|
+
function getGlobalIsRscClient() {
|
|
43
|
+
return globalContext.isRscClient;
|
|
44
|
+
}
|
|
45
|
+
function getGlobalEnableRsc() {
|
|
46
|
+
return globalContext.enableRsc;
|
|
47
|
+
}
|
|
37
48
|
function setGlobalContext(context) {
|
|
38
49
|
globalContext.entryName = context.entryName;
|
|
39
50
|
globalContext.App = context.App;
|
|
@@ -42,6 +53,8 @@ function setGlobalContext(context) {
|
|
|
42
53
|
globalContext.appConfig = typeof context.appConfig === "function" ? context.appConfig() : context.appConfig;
|
|
43
54
|
globalContext.layoutApp = context.layoutApp;
|
|
44
55
|
globalContext.RSCRoot = context.RSCRoot;
|
|
56
|
+
globalContext.isRscClient = context.isRscClient;
|
|
57
|
+
globalContext.enableRsc = context.enableRsc;
|
|
45
58
|
}
|
|
46
59
|
function getCurrentEntryName() {
|
|
47
60
|
return globalContext.entryName;
|
|
@@ -79,11 +92,15 @@ function getGlobalLayoutApp() {
|
|
|
79
92
|
getGlobalApp,
|
|
80
93
|
getGlobalAppConfig,
|
|
81
94
|
getGlobalAppInit,
|
|
95
|
+
getGlobalEnableRsc,
|
|
82
96
|
getGlobalInternalRuntimeContext,
|
|
97
|
+
getGlobalIsRscClient,
|
|
83
98
|
getGlobalLayoutApp,
|
|
84
99
|
getGlobalRSCRoot,
|
|
85
100
|
getGlobalRoutes,
|
|
86
101
|
getInitialContext,
|
|
102
|
+
getServerPayload,
|
|
87
103
|
setGlobalContext,
|
|
88
|
-
setGlobalInternalRuntimeContext
|
|
104
|
+
setGlobalInternalRuntimeContext,
|
|
105
|
+
setServerPayload
|
|
89
106
|
});
|
|
@@ -0,0 +1,40 @@
|
|
|
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 serverPayload_server_exports = {};
|
|
20
|
+
__export(serverPayload_server_exports, {
|
|
21
|
+
getServerPayload: () => getServerPayload,
|
|
22
|
+
setServerPayload: () => setServerPayload
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(serverPayload_server_exports);
|
|
25
|
+
var import_node = require("@modern-js/runtime-utils/node");
|
|
26
|
+
const getServerPayload = () => {
|
|
27
|
+
const context = import_node.storage.useContext();
|
|
28
|
+
return context === null || context === void 0 ? void 0 : context.serverPayload;
|
|
29
|
+
};
|
|
30
|
+
const setServerPayload = (payload) => {
|
|
31
|
+
const context = import_node.storage.useContext();
|
|
32
|
+
if (context) {
|
|
33
|
+
context.serverPayload = payload;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
getServerPayload,
|
|
39
|
+
setServerPayload
|
|
40
|
+
});
|
|
@@ -21,15 +21,40 @@ __export(requestHandler_exports, {
|
|
|
21
21
|
createRequestHandler: () => createRequestHandler
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(requestHandler_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
25
|
var import_node = require("@modern-js/runtime-utils/node");
|
|
25
26
|
var import_request = require("@modern-js/runtime-utils/universal/request");
|
|
27
|
+
var import_react = require("react");
|
|
26
28
|
var import_context = require("../context");
|
|
27
29
|
var import_runtime = require("../context/runtime");
|
|
30
|
+
var import_serverPayload = require("../context/serverPayload.server");
|
|
28
31
|
var import_loaderManager = require("../loader/loaderManager");
|
|
29
|
-
var
|
|
32
|
+
var import_react2 = require("../react");
|
|
30
33
|
var import_constants = require("./constants");
|
|
31
34
|
var import_tracer = require("./tracer");
|
|
32
35
|
var import_utils = require("./utils");
|
|
36
|
+
async function handleRSCRequest(request, Root, context, options, handleRequest) {
|
|
37
|
+
const serverPayload = (0, import_serverPayload.getServerPayload)();
|
|
38
|
+
if (typeof serverPayload !== "undefined") {
|
|
39
|
+
return await handleRequest(request, Root, {
|
|
40
|
+
...options,
|
|
41
|
+
runtimeContext: context,
|
|
42
|
+
rscRoot: serverPayload
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const App = (0, import_context.getGlobalRSCRoot)();
|
|
46
|
+
if (App) {
|
|
47
|
+
return await handleRequest(request, import_react.Fragment, {
|
|
48
|
+
...options,
|
|
49
|
+
runtimeContext: context,
|
|
50
|
+
rscRoot: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {})
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return await handleRequest(request, Root, {
|
|
54
|
+
...options,
|
|
55
|
+
runtimeContext: context
|
|
56
|
+
});
|
|
57
|
+
}
|
|
33
58
|
function createSSRContext(request, options) {
|
|
34
59
|
const { config, loaderContext, onError, onTiming, locals, resource, params, responseProxy, logger, metrics, reporter } = options;
|
|
35
60
|
const { nonce, useJsonScript } = config;
|
|
@@ -100,10 +125,11 @@ const createRequestHandler = async (handleRequest, createRequestOptions) => {
|
|
|
100
125
|
request,
|
|
101
126
|
monitors: options.monitors,
|
|
102
127
|
responseProxy,
|
|
103
|
-
activeDeferreds
|
|
128
|
+
activeDeferreds,
|
|
129
|
+
serverPayload: void 0
|
|
104
130
|
}, async () => {
|
|
105
131
|
var _context_routerContext, _context_routerContext1, _context_routerContext2;
|
|
106
|
-
const Root = (0,
|
|
132
|
+
const Root = (0, import_react2.createRoot)();
|
|
107
133
|
const internalRuntimeContext = (0, import_context.getGlobalInternalRuntimeContext)();
|
|
108
134
|
const hooks = internalRuntimeContext.hooks;
|
|
109
135
|
const { routeManifest } = options.resource;
|
|
@@ -158,15 +184,25 @@ const createRequestHandler = async (handleRequest, createRequestOptions) => {
|
|
|
158
184
|
context.initialData = initialData;
|
|
159
185
|
const redirectResponse = getRedirectResponse(initialData);
|
|
160
186
|
if (redirectResponse) {
|
|
161
|
-
|
|
187
|
+
if (createRequestOptions === null || createRequestOptions === void 0 ? void 0 : createRequestOptions.enableRsc) {
|
|
188
|
+
return initialData;
|
|
189
|
+
} else {
|
|
190
|
+
return redirectResponse;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (!(createRequestOptions === null || createRequestOptions === void 0 ? void 0 : createRequestOptions.enableRsc)) {
|
|
194
|
+
const { htmlTemplate } = options.resource;
|
|
195
|
+
options.resource.htmlTemplate = htmlTemplate.replace("</head>", `${import_constants.CHUNK_CSS_PLACEHOLDER}</head>`);
|
|
196
|
+
}
|
|
197
|
+
let response;
|
|
198
|
+
if (createRequestOptions === null || createRequestOptions === void 0 ? void 0 : createRequestOptions.enableRsc) {
|
|
199
|
+
response = await handleRSCRequest(request, Root, context, options, handleRequest);
|
|
200
|
+
} else {
|
|
201
|
+
response = await handleRequest(request, Root, {
|
|
202
|
+
...options,
|
|
203
|
+
runtimeContext: context
|
|
204
|
+
});
|
|
162
205
|
}
|
|
163
|
-
const { htmlTemplate } = options.resource;
|
|
164
|
-
options.resource.htmlTemplate = htmlTemplate.replace("</head>", `${import_constants.CHUNK_CSS_PLACEHOLDER}</head>`);
|
|
165
|
-
const response = await handleRequest(request, Root, {
|
|
166
|
-
...options,
|
|
167
|
-
runtimeContext: context,
|
|
168
|
-
RSCRoot: (createRequestOptions === null || createRequestOptions === void 0 ? void 0 : createRequestOptions.enableRsc) && (0, import_context.getGlobalRSCRoot)()
|
|
169
|
-
});
|
|
170
206
|
Object.entries(responseProxy.headers).forEach(([key, value]) => {
|
|
171
207
|
response.headers.set(key, value);
|
|
172
208
|
});
|
|
@@ -29,7 +29,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var code_exports = {};
|
|
30
30
|
__export(code_exports, {
|
|
31
31
|
generateCode: () => generateCode,
|
|
32
|
-
generatorRegisterCode: () => generatorRegisterCode
|
|
32
|
+
generatorRegisterCode: () => generatorRegisterCode,
|
|
33
|
+
generatorServerRegisterCode: () => generatorServerRegisterCode
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(code_exports);
|
|
35
36
|
var import_path = __toESM(require("path"));
|
|
@@ -107,14 +108,15 @@ const generateCode = async (appContext, config, entrypoints, api, isRouterV5) =>
|
|
|
107
108
|
code: await templates.fileSystemRoutes({
|
|
108
109
|
metaName,
|
|
109
110
|
routes,
|
|
110
|
-
ssrMode: useSSG ? "string" : mode,
|
|
111
|
+
ssrMode: useSSG ? "string" : (0, import_utils.isUseRsc)(config2) ? "stream" : mode,
|
|
111
112
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
112
113
|
entryName: entrypoint.entryName,
|
|
113
114
|
internalDirectory,
|
|
114
|
-
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output = config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
|
|
115
|
+
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output = config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks,
|
|
116
|
+
isRscClient: (0, import_utils.isUseRsc)(config2)
|
|
115
117
|
})
|
|
116
118
|
});
|
|
117
|
-
if (entrypoint.nestedRoutesEntry && (0, import_utils.isUseSSRBundle)(config2)) {
|
|
119
|
+
if (entrypoint.nestedRoutesEntry && ((0, import_utils.isUseSSRBundle)(config2) || (0, import_utils.isUseRsc)(config2))) {
|
|
118
120
|
var _config_output1;
|
|
119
121
|
const routesServerFile = (0, import_utils3.getServerLoadersFile)(internalDirectory, entryName);
|
|
120
122
|
const filtedRoutesForServer = (0, import_utils2.filterRoutesForServer)(routes);
|
|
@@ -131,7 +133,8 @@ const generateCode = async (appContext, config, entrypoints, api, isRouterV5) =>
|
|
|
131
133
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
132
134
|
entryName: entrypoint.entryName,
|
|
133
135
|
internalDirectory,
|
|
134
|
-
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output1 = config2.output) === null || _config_output1 === void 0 ? void 0 : _config_output1.splitRouteChunks
|
|
136
|
+
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output1 = config2.output) === null || _config_output1 === void 0 ? void 0 : _config_output1.splitRouteChunks,
|
|
137
|
+
isRscClient: false
|
|
135
138
|
});
|
|
136
139
|
await import_utils.fs.outputFile(import_path.default.resolve(internalDirectory, `./${entryName}/routes.server.js`), serverRoutesCode, "utf8");
|
|
137
140
|
}
|
|
@@ -148,8 +151,12 @@ const generateCode = async (appContext, config, entrypoints, api, isRouterV5) =>
|
|
|
148
151
|
function generatorRegisterCode(internalDirectory, entryName, code) {
|
|
149
152
|
import_utils.fs.outputFileSync(import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME}.js`), code, "utf8");
|
|
150
153
|
}
|
|
154
|
+
function generatorServerRegisterCode(internalDirectory, entryName, code) {
|
|
155
|
+
import_utils.fs.outputFileSync(import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME}.server.js`), code, "utf8");
|
|
156
|
+
}
|
|
151
157
|
// Annotate the CommonJS export names for ESM import in node:
|
|
152
158
|
0 && (module.exports = {
|
|
153
159
|
generateCode,
|
|
154
|
-
generatorRegisterCode
|
|
160
|
+
generatorRegisterCode,
|
|
161
|
+
generatorServerRegisterCode
|
|
155
162
|
});
|