@umijs/server 4.0.0-canary.20231009.1 → 4.0.0-canary.20231010.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/ssr.d.ts +3 -2
- package/dist/ssr.js +12 -20
- package/package.json +2 -2
package/dist/ssr.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare type ServerInsertedHTMLHook = (callbacks: () => React.ReactNode)
|
|
|
6
6
|
interface CreateRequestHandlerOptions {
|
|
7
7
|
routesWithServerLoader: RouteLoaders;
|
|
8
8
|
PluginManager: any;
|
|
9
|
-
manifest: (() => {
|
|
9
|
+
manifest: ((sourceDir?: string) => {
|
|
10
10
|
assets: Record<string, string>;
|
|
11
11
|
}) | {
|
|
12
12
|
assets: Record<string, string>;
|
|
@@ -19,9 +19,10 @@ interface CreateRequestHandlerOptions {
|
|
|
19
19
|
helmetContext?: any;
|
|
20
20
|
ServerInsertedHTMLContext: React.Context<ServerInsertedHTMLHook | null>;
|
|
21
21
|
withoutHTML?: boolean;
|
|
22
|
+
sourceDir?: string;
|
|
22
23
|
}
|
|
23
24
|
export declare function createMarkupGenerator(opts: CreateRequestHandlerOptions): (url: string) => Promise<unknown>;
|
|
24
25
|
export default function createRequestHandler(opts: CreateRequestHandlerOptions): (req: any, res: any, next: any) => Promise<any>;
|
|
25
|
-
export declare function createUmiHandler(opts: CreateRequestHandlerOptions): (req: Request) => Promise<
|
|
26
|
+
export declare function createUmiHandler(opts: CreateRequestHandlerOptions): (req: Request, params?: CreateRequestHandlerOptions) => Promise<NodeJS.ReadableStream>;
|
|
26
27
|
export declare function createUmiServerLoader(opts: CreateRequestHandlerOptions): (req: Request) => Promise<any>;
|
|
27
28
|
export {};
|
package/dist/ssr.js
CHANGED
|
@@ -62,7 +62,8 @@ function createJSXGenerator(opts) {
|
|
|
62
62
|
getPlugins,
|
|
63
63
|
getValidKeys,
|
|
64
64
|
getRoutes,
|
|
65
|
-
createHistory
|
|
65
|
+
createHistory,
|
|
66
|
+
sourceDir
|
|
66
67
|
} = opts;
|
|
67
68
|
createHistory({ type: "memory", initialEntries: [url], initialIndex: 1 });
|
|
68
69
|
const pluginManager = PluginManager.create({
|
|
@@ -91,7 +92,7 @@ function createJSXGenerator(opts) {
|
|
|
91
92
|
})
|
|
92
93
|
)
|
|
93
94
|
);
|
|
94
|
-
const manifest = typeof opts.manifest === "function" ? opts.manifest() : opts.manifest;
|
|
95
|
+
const manifest = typeof opts.manifest === "function" ? opts.manifest(sourceDir) : opts.manifest;
|
|
95
96
|
const context = {
|
|
96
97
|
routes,
|
|
97
98
|
routeComponents,
|
|
@@ -203,25 +204,16 @@ function createRequestHandler(opts) {
|
|
|
203
204
|
};
|
|
204
205
|
}
|
|
205
206
|
function createUmiHandler(opts) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return function(req) {
|
|
211
|
-
return new Promise(async (resolve, reject) => {
|
|
212
|
-
const jsx = await jsxGeneratorDeferrer(new URL(req.url).pathname);
|
|
213
|
-
if (!jsx) {
|
|
214
|
-
reject(new Error("no page resource"));
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
const stream = await ReactDomServer.renderToReadableStream(jsx.element, {
|
|
218
|
-
bootstrapScripts: [jsx.manifest.assets["umi.js"] || "/umi.js"],
|
|
219
|
-
onError(err) {
|
|
220
|
-
reject(err);
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
resolve(stream);
|
|
207
|
+
return async function(req, params) {
|
|
208
|
+
const jsxGeneratorDeferrer = createJSXGenerator({
|
|
209
|
+
...opts,
|
|
210
|
+
...params
|
|
224
211
|
});
|
|
212
|
+
const jsx = await jsxGeneratorDeferrer(new URL(req.url).pathname);
|
|
213
|
+
if (!jsx) {
|
|
214
|
+
throw new Error("no page resource");
|
|
215
|
+
}
|
|
216
|
+
return ReactDomServer.renderToNodeStream(jsx.element);
|
|
225
217
|
};
|
|
226
218
|
}
|
|
227
219
|
function createUmiServerLoader(opts) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/server",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.20231010.2",
|
|
4
4
|
"description": "@umijs/server",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/server#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"react": "18.1.0",
|
|
20
20
|
"react-dom": "18.1.0",
|
|
21
21
|
"react-router-dom": "6.3.0",
|
|
22
|
-
"@umijs/bundler-utils": "4.0.0-canary.
|
|
22
|
+
"@umijs/bundler-utils": "4.0.0-canary.20231010.2"
|
|
23
23
|
},
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|