Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/waku/src/lib/plugins/vite-plugin-rsc-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { Plugin } from 'vite';

import { SRC_MAIN } from '../constants.js';

export const DEFAULT_HTML_HEAD = `
// This should be consistent with the one in renderers/html.ts
const DEFAULT_HTML_HEAD = `
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="Waku" />
Expand Down
18 changes: 11 additions & 7 deletions packages/waku/src/lib/renderers/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ import { renderRsc, renderRscElement, getExtractFormState } from './rsc.js';
// TODO move types somewhere
import type { HandlerContext } from '../middleware/types.js';

// HACK depending on these constants is not ideal
import { DEFAULT_HTML_HEAD } from '../plugins/vite-plugin-rsc-index.js';
// This should be consistent with the one in vite-plugin-rsc-index.ts
const DEFAULT_HTML_HEAD = [
createElement('meta', { charSet: 'utf-8' }),
createElement('meta', {
name: 'viewport',
content: 'width=device-width, initial-scale=1',
}),
createElement('meta', { name: 'generator', content: 'Waku' }),
];

type Elements = Record<string, ReactNode>;

Expand Down Expand Up @@ -56,11 +63,7 @@ const injectHtmlHead = (
data.slice(0, closingHeadIndex + CLOSING_HEAD.length),
data.slice(closingHeadIndex + CLOSING_HEAD.length),
];
head =
head.slice(0, -CLOSING_HEAD.length) +
DEFAULT_HTML_HEAD +
htmlHead +
CLOSING_HEAD;
head = head.slice(0, -CLOSING_HEAD.length) + htmlHead + CLOSING_HEAD;
const matchPrefetched = head.match(
// HACK This is very brittle
/(.*<script[^>]*>\nglobalThis\.__WAKU_PREFETCHED__ = {\n)(.*?)(\n};.*)/s,
Expand Down Expand Up @@ -226,6 +229,7 @@ export async function renderHtml(
Omit<ComponentProps<typeof ServerRoot>, 'children'>
>,
{ elements: elementsPromise },
...DEFAULT_HTML_HEAD,
htmlNode as any,
),
{
Expand Down
Loading