Add polyfill scripts to result.scripts (#1920)

* Add polyfill scripts to result.scripts

* These scripts are bundled together now

* Adds changeset
This commit is contained in:
Matthew Phillips 2021-11-19 14:06:05 -05:00 committed by GitHub
parent ae2cadd246
commit 2e0c790b3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix Lit renderer built

View file

@ -224,8 +224,12 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
// This is used to add polyfill scripts to the page, if the renderer needs them.
if (renderer?.polyfills?.length) {
let polyfillScripts = renderer.polyfills.map((src) => `<script type="module">import "${src}";</script>`).join('');
html = html + polyfillScripts;
for(const src of renderer.polyfills) {
result.scripts.add({
props: { type: 'module' },
children: `import "${src}";`,
});
}
}
if (!hydration) {

View file

@ -47,8 +47,8 @@ describe('Custom Elements', () => {
expect($('my-element template[shadowroot=open]')).to.have.lengthOf(1);
// Hydration
// test 3: Component and polyfill scripts included
expect($('script[type=module]')).to.have.lengthOf(2);
// test 3: Component and polyfill scripts bundled together
expect($('script[type=module]')).to.have.lengthOf(1);
});
it('Polyfills are added even if not hydrating', async () => {