From a36eb05895155e9c3178f06d81369e03b13d4b27 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 31 May 2024 08:56:30 -0400 Subject: [PATCH 1/2] Retain client scripts in content cache --- .changeset/wicked-dragons-draw.md | 5 +++++ packages/astro/src/core/build/plugins/plugin-content.ts | 1 + 2 files changed, 6 insertions(+) create mode 100644 .changeset/wicked-dragons-draw.md 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 From e38edeb5dc54641eb923f9eeb6e94e74187af1e8 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 31 May 2024 10:03:47 -0400 Subject: [PATCH 2/2] Add test --- ...xperimental-content-collections-render.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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.' + ); + }); }); }); });