0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00

Retain client scripts in content cache (#11170)

* Retain client scripts in content cache

* Add test
This commit is contained in:
Matthew Phillips 2024-06-04 10:52:48 -04:00 committed by GitHub
parent ff8004f6a7
commit ba20c718a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Retain client scripts in content cache

View file

@ -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

View file

@ -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.'
);
});
});
});
});