Skip to content

Commit c77f55d

Browse files
matthewpsarah11918natemoo-re
authored
Prevent passing slot names as props (#8930)
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> Co-authored-by: Nate Moore <7118177+natemoo-re@users.noreply.github.com>
1 parent ca90b47 commit c77f55d

File tree

9 files changed

+78
-1
lines changed

9 files changed

+78
-1
lines changed

.changeset/swift-suits-drum.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/vue': patch
3+
---
4+
5+
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.

packages/integrations/vue/server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ function check(Component) {
77
return !!Component['ssrRender'] || !!Component['__ssrInlineRender'];
88
}
99

10-
async function renderToStaticMarkup(Component, props, slotted, metadata) {
10+
async function renderToStaticMarkup(Component, inputProps, slotted, metadata) {
1111
const slots = {};
12+
const props = { ...inputProps };
13+
delete props.slot;
1214
for (const [key, value] of Object.entries(slotted)) {
1315
slots[key] = () =>
1416
h(StaticHtml, {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { loadFixture } from './test-utils.js';
2+
import { expect } from 'chai';
3+
import { parseHTML } from 'linkedom';
4+
describe('Basics', () => {
5+
/** @type {import('./test-utils').Fixture} */
6+
let fixture;
7+
8+
before(async () => {
9+
fixture = await loadFixture({
10+
root: './fixtures/basics/',
11+
});
12+
await fixture.build();
13+
});
14+
15+
it('Slots are added without the slot attribute', async () => {
16+
const data = await fixture.readFile('/index.html');
17+
const { document } = parseHTML(data);
18+
const bar = document.querySelector('#foo');
19+
20+
expect(bar).not.to.be.undefined;
21+
expect(bar.getAttribute('slot')).to.be.null;
22+
});
23+
24+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from 'astro/config';
2+
import vue from '@astrojs/vue';
3+
4+
export default defineConfig({
5+
integrations: [vue()],
6+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@test/vue-basics",
3+
"version": "0.0.0",
4+
"private": true,
5+
"dependencies": {
6+
"astro": "workspace:*",
7+
"@astrojs/vue": "workspace:*"
8+
}
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
<template>
3+
<div id="foo">bar</div>
4+
</template>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<section>
2+
<header></header>
3+
<footer><slot name="footer"></slot></footer>
4+
</section>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
import Parent from '../components/Parent.astro';
3+
import Bar from '../components/Foo.vue';
4+
---
5+
<html>
6+
<head>
7+
<title>Testing</title>
8+
</head>
9+
<body>
10+
<Parent>
11+
<Bar slot="footer" />
12+
</Parent>
13+
</body>
14+
</html>

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)