After updating to version 0.17.5 HTML pages are build without pre-rendered content
varmiral opened this issue · comments
Single-page example
0.17.5 | 0.17.4 build settings are the same
v0.17.5:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hello World</title>
<script
type="module"
async=""
crossorigin=""
src="/assets/app.06133d47.js"
></script>
<link rel="modulepreload" href="/assets/vendor.4b3284e1.js" />
<link rel="stylesheet" href="/assets/app.9ae45141.css" />
</head>
<body>
<div id="app" data-server-rendered="true"></div>
<script>
window.__INITIAL_STATE__="{\"pinia\":{\"root\":{\"user\":{\"id\":1,\"firstName\":\"Jane\",\"lastName\":\"Doe\"}}}}"
</script>
</body>
</html>
v0.17.4:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hello World</title>
<script
type="module"
async=""
crossorigin=""
src="/assets/app.e0d6d9bd.js"
></script>
<link rel="modulepreload" href="/assets/vendor.d630207c.js" />
<link rel="stylesheet" href="/assets/app.9ae45141.css" />
</head>
<body>
<div id="app" data-server-rendered="true">
<!--[-->
<h2>Hello</h2>
<p>World</p>
<h3>Initial State:</h3>
<pre>
{
"id": 1,
"firstName": "Jane",
"lastName": "Doe"
}</pre
>
<!--]-->
</div>
<script>
window.__INITIAL_STATE__="{\"pinia\":{\"root\":{\"user\":{\"id\":1,\"firstName\":\"Jane\",\"lastName\":\"Doe\"}}}}"
</script>
</body>
</html>
+1
Some research:
triggerOnSSRAppRendered
was added in 77597f5
to bring the feature create onSsrAppRendered option
.
The method triggerOnSSRAppRendered
as part of the feature is available on the ViteSSGContext
(aka appContext
) to process the created HTML during the build: https://github.com/antfu/vite-ssg/blob/46dab451b4027d17c3788b4d3e55c48c8e9c4ffd/src/node/build.ts#L154-L157
Previously this was not there and appHTML
was processed where transformedAppHTML
is now used in the code, see the old version here:
https://github.com/antfu/vite-ssg/blob/445cf96f755a32ef006f94157a33aa25527f7315/src/node/build.ts#L152-L155
In both implementations (single-page
and normal
), this method is always supplied and always returns an Array wrapped in a Promise, where previously there was a string. Therefore in my opinion this implementation broke vite-ssg
.
triggerOnSSRAppRendered
is typed as triggerOnSSRAppRendered(route: string, appHTML: string, appCtx: ViteSSGContext): Promise<any>
see here, maybe changing the return type to Promise<unknown[]>
would already make the problem visible in Typescript.
Will look into it