Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 99c7201

Browse files
committed
Support data-ssr-root attr in index.html
1 parent b810630 commit 99c7201

File tree

6 files changed

+15
-5
lines changed

6 files changed

+15
-5
lines changed

examples/feature-apps/monaco-editor/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</head>
3232

3333
<body>
34-
<div id="root"><!-- ssr-body --></div>
34+
<div id="root" data-ssr-root></div>
3535
<script type="module" src="./main.tsx"></script>
3636
</body>
3737

examples/feature-apps/suspense-ssr/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</head>
99

1010
<body>
11-
<div id="root"><!-- ssr-body --></div>
11+
<div id="root" data-ssr-root></div>
1212
<script type="module" src="./main.tsx"></script>
1313
</body>
1414

examples/feature-apps/unocss/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</head>
3535

3636
<body>
37-
<div id="root"><!-- ssr-body --></div>
37+
<div id="root" data-ssr-root></div>
3838
<script type="module" src="./main.tsx"></script>
3939
</body>
4040

examples/react-app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</head>
1010

1111
<body>
12-
<div id="root"><!-- ssr-body --></div>
12+
<div id="root" data-ssr-root></div>
1313
<script type="module" src="./main.tsx"></script>
1414
</body>
1515

examples/vue-app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</head>
2020

2121
<body>
22-
<div id="root"><!-- ssr-body --></div>
22+
<div id="root" data-ssr-root></div>
2323
<script type="module" src="./main.js"></script>
2424
</body>
2525

server/html.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ async function loadIndexHtml(): Promise<{ html: Uint8Array; hasSSRBody: boolean
3737
element: () => hasSSRBody = true,
3838
});
3939
rewriter.on("*", {
40+
element: (e: Element) => {
41+
if (e.hasAttribute("data-ssr-root")) {
42+
if (hasSSRBody) {
43+
e.removeAttribute("data-ssr-root");
44+
} else {
45+
e.setInnerContent("<ssr-body></ssr-body>", { html: true });
46+
hasSSRBody = true;
47+
}
48+
}
49+
},
4050
comments: (c: Comment) => {
4151
const text = c.text.trim();
4252
if (text === "ssr-body" || text === "ssr-output") {

0 commit comments

Comments
 (0)