Skip to content

Commit

Permalink
fix: rendertoreadablestream is not a function
Browse files Browse the repository at this point in the history
  • Loading branch information
奇风 committed Oct 9, 2023
1 parent 542304a commit 335e6a6
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions packages/server/src/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,28 +240,19 @@ export default function createRequestHandler(
}

export function createUmiHandler(opts: CreateRequestHandlerOptions) {
return function (req: Request, params?: CreateRequestHandlerOptions) {
return new Promise(async (resolve, reject) => {
const jsxGeneratorDeferrer = createJSXGenerator({
...opts,
...params,
});
const jsx = await jsxGeneratorDeferrer(new URL(req.url).pathname);
return async function (req: Request, params?: CreateRequestHandlerOptions) {
const jsxGeneratorDeferrer = createJSXGenerator({
...opts,
...params,
});
const jsx = await jsxGeneratorDeferrer(new URL(req.url).pathname);

if (!jsx) {
reject(new Error('no page resource'));
return;
}
if (!jsx) {
throw new Error('no page resource')
}

// 同时兼容target = node 和 target = webworker 两个场景
const stream = await (ReactDomServer.renderToReadableStream || ReactDomServer.renderToNodeStream)(jsx.element, {
bootstrapScripts: [jsx.manifest.assets['umi.js'] || '/umi.js'],
onError(err: any) {
reject(err);
},
});
resolve(stream);
});
const stream = await ReactDomServer.renderToNodeStream(jsx.element);
return stream;
};
}

Expand Down

0 comments on commit 335e6a6

Please sign in to comment.