diff --git a/.changeset/dull-olives-greet.md b/.changeset/dull-olives-greet.md new file mode 100644 index 000000000..5e8bf3e20 --- /dev/null +++ b/.changeset/dull-olives-greet.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix mixed usage of aliases and relative for client hydration diff --git a/packages/astro/src/core/build/plugins/plugin-internals.ts b/packages/astro/src/core/build/plugins/plugin-internals.ts index 982d958c3..c06018221 100644 --- a/packages/astro/src/core/build/plugins/plugin-internals.ts +++ b/packages/astro/src/core/build/plugins/plugin-internals.ts @@ -34,12 +34,16 @@ export function vitePluginInternals(input: Set, internals: BuildInternal async generateBundle(_options, bundle) { const promises = []; - const mapping = new Map(); + const mapping = new Map>(); for (const specifier of input) { promises.push( this.resolve(specifier).then((result) => { if (result) { - mapping.set(result.id, specifier); + if(mapping.has(result.id)) { + mapping.get(result.id)!.add(specifier); + } else { + mapping.set(result.id, new Set([specifier])); + } } }) ); @@ -47,8 +51,10 @@ export function vitePluginInternals(input: Set, internals: BuildInternal await Promise.all(promises); for (const [, chunk] of Object.entries(bundle)) { if (chunk.type === 'chunk' && chunk.facadeModuleId) { - const specifier = mapping.get(chunk.facadeModuleId) || chunk.facadeModuleId; - internals.entrySpecifierToBundleMap.set(specifier, chunk.fileName); + const specifiers = mapping.get(chunk.facadeModuleId) || new Set([chunk.facadeModuleId]); + for(const specifier of specifiers) { + internals.entrySpecifierToBundleMap.set(specifier, chunk.fileName); + } } else if (chunk.type === 'chunk') { for (const id of Object.keys(chunk.modules)) { const pageData = internals.pagesByViteID.get(id); diff --git a/packages/astro/test/alias.test.js b/packages/astro/test/alias.test.js index 20a213111..109d600ca 100644 --- a/packages/astro/test/alias.test.js +++ b/packages/astro/test/alias.test.js @@ -51,5 +51,16 @@ describe('Aliases', () => { const scripts = $('script').toArray(); expect(scripts.length).to.be.greaterThan(0); }); + + it('can use aliases and relative in same project', async () => { + const html = await fixture.readFile('/two/index.html'); + const $ = cheerio.load(html); + + // Should render aliased element + expect($('#client').text()).to.equal('test'); + + const scripts = $('script').toArray(); + expect(scripts.length).to.be.greaterThan(0); + }); }); }); diff --git a/packages/astro/test/fixtures/alias/src/pages/two.astro b/packages/astro/test/fixtures/alias/src/pages/two.astro new file mode 100644 index 000000000..6e450e5a4 --- /dev/null +++ b/packages/astro/test/fixtures/alias/src/pages/two.astro @@ -0,0 +1,25 @@ +--- +import Client from '../components/Client.svelte' +--- + + + + + Svelte Client + + + +
+ +
+ +