fix(nuxt): ensure payload script executes before entry (#27506)

This commit is contained in:
Daniel Roe 2024-06-10 17:16:26 +01:00 committed by GitHub
parent c06a683e49
commit 22cd4770c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -455,6 +455,9 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
type: resource.module ? 'module' : null, type: resource.module ? 'module' : null,
src: renderer.rendererContext.buildAssetsURL(resource.file), src: renderer.rendererContext.buildAssetsURL(resource.file),
defer: resource.module ? null : true, defer: resource.module ? null : true,
// if we are rendering script tag payloads that import an async payload
// we need to ensure this resolves before executing the Nuxt entry
tagPosition: (_PAYLOAD_EXTRACTION && !process.env.NUXT_JSON_PAYLOADS) ? 'bodyClose' : 'head',
crossorigin: '', crossorigin: '',
})), })),
}, headEntryOptions) }, headEntryOptions)

View File

@ -32,7 +32,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
const serverDir = join(rootDir, '.output/server') const serverDir = join(rootDir, '.output/server')
const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"208k"`) expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"209k"`)
const modules = await analyzeSizes('node_modules/**/*', serverDir) const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot(`"1338k"`) expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot(`"1338k"`)