replace </?script in json

This commit is contained in:
Eric
2026-09-24 23:39:56 +10:00
parent 2e3ee38846
commit 33e64c1e06
+6 -1
View File
@@ -280,9 +280,14 @@ export default async function createApp(vite) {
html = await vite.transformIndexHtml(req.originalUrl, html); html = await vite.transformIndexHtml(req.originalUrl, html);
} }
const safeProps = JSON.stringify(props).replace(/<(?=\/?script)/ig, '\\u003c');
html = html.replace( html = html.replace(
'<head>', '<head>',
()=>{ return `<head>\n<script id="props" >window.__INITIAL_PROPS__ = ${JSON.stringify(props)}</script>\n${ogMetaTags}`; } `<head>\n`
+ `<script id="props">`
+ `window.__INITIAL_PROPS__ = ` + safeProps
+ `</script>\n`
+ ogMetaTags
); );
return html; return html;