Skip to content

Commit

Permalink
chore: Switch React example to use prerender export
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Jan 17, 2025
1 parent fd4f3ef commit 026cef3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions examples/react/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ if (typeof window !== 'undefined') {
}

export async function prerender(data) {
const { renderToString } = await import('react-dom/server');
const { prerender: reactPrerender } = await import('react-dom/static');
const { parseLinks } = await import('vite-prerender-plugin/parse');

const html = await renderToString(<App {...data} />);
const { prelude } = await reactPrerender(<App {...data} />);
const reader = prelude.getReader();
let html = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
html += Buffer.from(value).toString('utf-8');
}

const links = parseLinks(html);

return { html, links };
Expand Down

0 comments on commit 026cef3

Please sign in to comment.