antfu-collective / vite-ssg

Static site generation for Vue 3 on Vite
MIT License
1.32k stars 136 forks source link

fix: renderHTML indexHTML.replace when appHTML with $ #389

Closed YunYouJun closed 9 months ago

YunYouJun commented 9 months ago

Description

When $` in appHTML, indexHTML.replace (renderHTML) will result in an abnormal replacement.

Specifying a string as the replacement | MDN

image

https://github.com/antfu/vite-ssg/blob/8015d55b798fa9d5f3ebb7c79763ec7ad429a795/src/node/build.ts#L279-L283

In order for it not to be affected by special rules, we need to convert it into a function.

() => `<div id="${rootContainerId}" data-server-rendered="true">${appHTML}</div>${stateScript}`

Linked Issues

https://github.com/YunYouJun/valaxy/issues/295

It can be reproduced in the vite-ssg examples.

<a href="https://github.com/antfu/vite-ssg" aria-label="Permalink to &quot;Usage `^`, `$`&quot;"></a>

Additional context