Skip to content

Commit

Permalink
feat: Pip after onAllReady when pre render SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
answershuto committed Nov 29, 2023
1 parent 3f89726 commit 5a3889a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
13 changes: 0 additions & 13 deletions packages/ice/src/middlewares/renderMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,9 @@ export default function createRenderMiddleware(options: Options): Middleware {
req,
res,
};

// Simulating window object for wormhole.
// @ts-ignore
global.window = {};

serverModule.renderToResponse(requestContext, {
renderMode,
documentOnly,
preRender: true,
streamOptions: {
onAllReady: (params) => {
console.log('middleware onAllReady');
console.log('params', params);
res.write(params.renderAssets.join(','));
},
},
});
}
} else {
Expand Down
42 changes: 22 additions & 20 deletions packages/runtime/src/server/streamRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ export function renderToNodeStream(
const {
preRender = false,
} = renderOptions;
console.log('preRender', preRender);

const { pipe } = ReactDOMServer.renderToPipeableStream(element, {
onShellReady() {
// Pip after onAllReady when pre render SSR.
if (!preRender) {
pipe(res);
}
Expand All @@ -53,30 +54,31 @@ export function renderToNodeStream(
options?.onError && options?.onError(error);
},
onAllReady() {
const {
renderOptions,
routerContext,
} = renderToNodeStreamOptions;
// For pre render SSR.
if (preRender) {
const {
renderOptions,
routerContext,
} = renderToNodeStreamOptions;

const {
assetsManifest,
} = renderOptions;
const {
assetsManifest,
} = renderOptions;

const {
matches,
loaderData,
} = routerContext;
const {
matches,
loaderData,
} = routerContext;

let renderAssets = getAllAssets(loaderData, matches, assetsManifest);
if (typeof window !== 'undefined' && window.renderAssets) {
renderAssets = renderAssets.concat(window.renderAssets);
}
let renderAssets = getAllAssets(loaderData, matches, assetsManifest);
if (typeof window !== 'undefined' && window.renderAssets) {
renderAssets = renderAssets.concat(window.renderAssets);
}

options?.onAllReady && options?.onAllReady({
renderAssets,
});
options?.onAllReady && options?.onAllReady({
renderAssets,
});

if (preRender) {
pipe(res);
}
},
Expand Down

0 comments on commit 5a3889a

Please sign in to comment.