Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent passing slot names as props #8930

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading