Skip to content

Commit 380d445

Browse files
authored
fix: relax slot prop validation on components (#11923)
If a component is not inside a slot context, having a slot property is fine and doesn't have any restrictions
1 parent 8c9d9a4 commit 380d445

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

.changeset/tame-goats-bow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: relax slot prop validation on components

packages/svelte/src/compiler/phases/2-analyze/validation.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function validate_component(node, context) {
8787
validate_attribute_name(attribute);
8888

8989
if (attribute.name === 'slot') {
90-
validate_slot_attribute(context, attribute);
90+
validate_slot_attribute(context, attribute, true);
9191
}
9292
}
9393
}
@@ -253,8 +253,9 @@ function validate_attribute_name(attribute) {
253253
/**
254254
* @param {import('zimmerframe').Context<import('#compiler').SvelteNode, import('./types.js').AnalysisState>} context
255255
* @param {import('#compiler').Attribute} attribute
256+
* @param {boolean} is_component
256257
*/
257-
function validate_slot_attribute(context, attribute) {
258+
function validate_slot_attribute(context, attribute, is_component = false) {
258259
let owner = undefined;
259260

260261
let i = context.path.length;
@@ -310,7 +311,7 @@ function validate_slot_attribute(context, attribute) {
310311
}
311312
}
312313
}
313-
} else {
314+
} else if (!is_component) {
314315
e.slot_attribute_invalid_placement(attribute);
315316
}
316317
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<Foo slot="foo">valid</Foo>
2+
<Foo slot={foo}>valid</Foo>

0 commit comments

Comments
 (0)