Skip to content

Commit 3c4323c

Browse files
committed
fix(react): preload templates missing html.cspNonce
1 parent 72dd7e4 commit 3c4323c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/fastify-react/plugin/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ export default function viteFastifyVue () {
5151
order: 'post',
5252
handler: transformIndexHtml.bind(context)
5353
},
54-
closeBundle: closeBundle.bind(context),
54+
closeBundle: {
55+
order: 'post',
56+
handler: closeBundle.bind(context),
57+
},
5558
}]
5659
}
5760

packages/fastify-react/plugin/preload.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { writeFileSync, mkdirSync, existsSync } from 'node:fs'
1+
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'
22
import { join, parse as parsePath } from 'node:path'
33
import { HTMLRewriter } from 'html-rewriter-wasm'
44

@@ -7,6 +7,7 @@ const imageFile = /\.((png)|(jpg)|(svg)|(webp)|(gif))$/
77
export async function closeBundle() {
88
if (!this.resolvedConfig.build.ssr) {
99
const distDir = join(this.root, this.resolvedConfig.build.outDir)
10+
const indexHtml = readFileSync(join(distDir, 'index.html'), 'utf8')
1011
const pages = Object.fromEntries(
1112
Object.entries(this.resolvedBundle ?? {})
1213
.filter(([id, meta]) => {
@@ -34,7 +35,7 @@ export async function closeBundle() {
3435
jsPreloads += ` <link rel="modulepreload" crossorigin href="${this.resolvedConfig.base}${js}">\n`
3536
}
3637
const pageHtml = await appendHead(
37-
this.indexHtml,
38+
indexHtml,
3839
imagePreloads,
3940
cssPreloads,
4041
jsPreloads

0 commit comments

Comments
 (0)