diff options
-rw-r--r-- | .changeset/dull-olives-greet.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/build/plugins/plugin-internals.ts | 14 | ||||
-rw-r--r-- | packages/astro/test/alias.test.js | 11 | ||||
-rw-r--r-- | packages/astro/test/fixtures/alias/src/pages/two.astro | 25 |
4 files changed, 51 insertions, 4 deletions
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<string>, internals: BuildInternal async generateBundle(_options, bundle) { const promises = []; - const mapping = new Map<string, string>(); + const mapping = new Map<string, Set<string>>(); 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<string>([specifier])); + } } }) ); @@ -47,8 +51,10 @@ export function vitePluginInternals(input: Set<string>, 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' +--- +<html lang="en"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width" /> + <title>Svelte Client</title> + <style> + html, + body { + font-family: system-ui; + margin: 0; + } + body { + padding: 2rem; + } + </style> + </head> + <body> + <main> + <Client client:load /> + </main> + </body> +</html> |