Skip to content

Commit 575a19e

Browse files
committed
special case handling of prerendering
1 parent a7fe0ae commit 575a19e

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

packages/start/src/server/handler.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,21 @@ export function createBaseHandler(
7777
return html;
7878
}
7979

80-
const stream = renderToStream(() => {
80+
const _stream = renderToStream(() => {
8181
(sharedConfig.context as any).event = context;
8282
return fn(context);
8383
}, resolvedOptions);
84+
const stream = _stream as typeof _stream & Promise<string> // stream has a hidden 'then' method
85+
86+
if (event.request.headers.get("x-nitro-prerender")) {
87+
const _html = await stream;
88+
const html = _html.replaceAll(/data-hk=(\d+)(?=\s|>)/g, 'data-hk="$1"');
89+
return html
90+
}
8491

8592
// insert redirect handling here
8693

87-
if (mode === "async") return stream as unknown as Promise<string>; // stream has a hidden 'then' method
94+
if (mode === "async") return stream
8895

8996
const { writable, readable } = new TransformStream();
9097
stream.pipeTo(writable);

0 commit comments

Comments
 (0)