diff --git a/.changeset/wicked-dragons-draw.md b/.changeset/wicked-dragons-draw.md new file mode 100644 index 000000000000..d93036f11ff8 --- /dev/null +++ b/.changeset/wicked-dragons-draw.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Retain client scripts in content cache diff --git a/packages/astro/src/core/build/plugins/plugin-content.ts b/packages/astro/src/core/build/plugins/plugin-content.ts index ae6fff806796..1698eb2a0c78 100644 --- a/packages/astro/src/core/build/plugins/plugin-content.ts +++ b/packages/astro/src/core/build/plugins/plugin-content.ts @@ -255,6 +255,7 @@ function vitePluginContent( ...oldManifest.clientEntries, ...internals.discoveredHydratedComponents.keys(), ...internals.discoveredClientOnlyComponents.keys(), + ...internals.discoveredScripts ]); // Likewise, these are server modules that might not be referenced // once the cached items are excluded from the build process diff --git a/packages/astro/test/experimental-content-collections-render.test.js b/packages/astro/test/experimental-content-collections-render.test.js index ffe0a0290f40..e5d152f4101a 100644 --- a/packages/astro/test/experimental-content-collections-render.test.js +++ b/packages/astro/test/experimental-content-collections-render.test.js @@ -136,6 +136,21 @@ if (!isWindows) { const files = await fixture.readdir(''); assert.equal(files.includes('chunks'), false, 'chunks folder removed'); }); + + it('hoisted script is built', async () => { + const html = await fixture.readFile('/launch-week-component-scripts/index.html'); + const $ = cheerio.load(html); + + const allScripts = $('head > script[type="module"]'); + assert.ok(allScripts.length > 0); + + // Includes hoisted script + assert.notEqual( + [...allScripts].find((script) => $(script).attr('src')?.includes('/_astro/WithScripts')), + undefined, + 'hoisted script missing from head.' + ); + }); }); }); });