diff --git a/.changeset/swift-suits-drum.md b/.changeset/swift-suits-drum.md new file mode 100644 index 0000000000000..664541c44d7c1 --- /dev/null +++ b/.changeset/swift-suits-drum.md @@ -0,0 +1,5 @@ +--- +'@astrojs/vue': patch +--- + +Fixes an issue where Astro slot names were being rendered as attributes in components. Astro slot names will no longer be sent as props to framework components. diff --git a/packages/integrations/vue/server.js b/packages/integrations/vue/server.js index 4e06baa5f671a..4bcf0490373c7 100644 --- a/packages/integrations/vue/server.js +++ b/packages/integrations/vue/server.js @@ -7,8 +7,10 @@ function check(Component) { return !!Component['ssrRender'] || !!Component['__ssrInlineRender']; } -async function renderToStaticMarkup(Component, props, slotted, metadata) { +async function renderToStaticMarkup(Component, inputProps, slotted, metadata) { const slots = {}; + const props = { ...inputProps }; + delete props.slot; for (const [key, value] of Object.entries(slotted)) { slots[key] = () => h(StaticHtml, { diff --git a/packages/integrations/vue/test/basics.test.js b/packages/integrations/vue/test/basics.test.js new file mode 100644 index 0000000000000..a4bdc7f873fb6 --- /dev/null +++ b/packages/integrations/vue/test/basics.test.js @@ -0,0 +1,24 @@ +import { loadFixture } from './test-utils.js'; +import { expect } from 'chai'; +import { parseHTML } from 'linkedom'; +describe('Basics', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/basics/', + }); + await fixture.build(); + }); + + it('Slots are added without the slot attribute', async () => { + const data = await fixture.readFile('/index.html'); + const { document } = parseHTML(data); + const bar = document.querySelector('#foo'); + + expect(bar).not.to.be.undefined; + expect(bar.getAttribute('slot')).to.be.null; + }); + +}); diff --git a/packages/integrations/vue/test/fixtures/basics/astro.config.mjs b/packages/integrations/vue/test/fixtures/basics/astro.config.mjs new file mode 100644 index 0000000000000..afd8fbca69d4c --- /dev/null +++ b/packages/integrations/vue/test/fixtures/basics/astro.config.mjs @@ -0,0 +1,6 @@ +import { defineConfig } from 'astro/config'; +import vue from '@astrojs/vue'; + +export default defineConfig({ + integrations: [vue()], +}) diff --git a/packages/integrations/vue/test/fixtures/basics/package.json b/packages/integrations/vue/test/fixtures/basics/package.json new file mode 100644 index 0000000000000..9cae3999cef28 --- /dev/null +++ b/packages/integrations/vue/test/fixtures/basics/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/vue-basics", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*", + "@astrojs/vue": "workspace:*" + } +} diff --git a/packages/integrations/vue/test/fixtures/basics/src/components/Foo.vue b/packages/integrations/vue/test/fixtures/basics/src/components/Foo.vue new file mode 100644 index 0000000000000..29db411cdec4b --- /dev/null +++ b/packages/integrations/vue/test/fixtures/basics/src/components/Foo.vue @@ -0,0 +1,4 @@ + + diff --git a/packages/integrations/vue/test/fixtures/basics/src/components/Parent.astro b/packages/integrations/vue/test/fixtures/basics/src/components/Parent.astro new file mode 100644 index 0000000000000..25c5749982615 --- /dev/null +++ b/packages/integrations/vue/test/fixtures/basics/src/components/Parent.astro @@ -0,0 +1,4 @@ +
+
+ +
diff --git a/packages/integrations/vue/test/fixtures/basics/src/pages/index.astro b/packages/integrations/vue/test/fixtures/basics/src/pages/index.astro new file mode 100644 index 0000000000000..e17de6edf9f83 --- /dev/null +++ b/packages/integrations/vue/test/fixtures/basics/src/pages/index.astro @@ -0,0 +1,14 @@ +--- +import Parent from '../components/Parent.astro'; +import Bar from '../components/Foo.vue'; +--- + + + Testing + + + + + + + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7e65279237631..660f40655185a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4795,6 +4795,15 @@ importers: specifier: 4.0.0 version: 4.0.0 + packages/integrations/vue/test/fixtures/basics: + dependencies: + '@astrojs/vue': + specifier: workspace:* + version: link:../../.. + astro: + specifier: workspace:* + version: link:../../../../../astro + packages/internal-helpers: devDependencies: astro-scripts: