Skip to content

Commit

Permalink
Prevent passing slot names as props (#8930)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
Co-authored-by: Nate Moore <7118177+natemoo-re@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 27, 2023
1 parent ca90b47 commit c77f55d
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/swift-suits-drum.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 3 additions & 1 deletion packages/integrations/vue/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
24 changes: 24 additions & 0 deletions packages/integrations/vue/test/basics.test.js
Original file line number Diff line number Diff line change
@@ -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;
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'astro/config';
import vue from '@astrojs/vue';

export default defineConfig({
integrations: [vue()],
})
9 changes: 9 additions & 0 deletions packages/integrations/vue/test/fixtures/basics/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/vue-basics",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*",
"@astrojs/vue": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<template>
<div id="foo">bar</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<section>
<header></header>
<footer><slot name="footer"></slot></footer>
</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
import Parent from '../components/Parent.astro';
import Bar from '../components/Foo.vue';
---
<html>
<head>
<title>Testing</title>
</head>
<body>
<Parent>
<Bar slot="footer" />
</Parent>
</body>
</html>
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c77f55d

Please sign in to comment.