-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: recognize all custom element prop definitions (#14084)
We didn't account for the `$props` rune being writtin in a way that makes some props unknown, and they would only be visible through the `customElement.props` definition. This changes the iteration to account for that and also adds a note to the documentation that you need to list out the properties explicitly. fixes #13785
- Loading branch information
1 parent
6a2c28c
commit 7d11fa8
Showing
6 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: recognize all custom element prop definitions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ges/svelte/tests/runtime-browser/custom-elements-samples/props-rune-attributes/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { test } from '../../assert'; | ||
const tick = () => Promise.resolve(); | ||
|
||
export default test({ | ||
async test({ assert, target }) { | ||
target.innerHTML = '<custom-element foo-bar="1" bar="2" b-az="3"></custom-element>'; | ||
await tick(); | ||
|
||
/** @type {any} */ | ||
const el = target.querySelector('custom-element'); | ||
|
||
assert.htmlEqual( | ||
el.shadowRoot.innerHTML, | ||
` | ||
<p>1</p> | ||
<p>2</p> | ||
<p>3</p> | ||
` | ||
); | ||
} | ||
}); |
14 changes: 14 additions & 0 deletions
14
...es/svelte/tests/runtime-browser/custom-elements-samples/props-rune-attributes/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<svelte:options | ||
customElement={{ | ||
tag: "custom-element", | ||
props: { foo: { attribute: 'foo-bar' } }, | ||
}} | ||
/> | ||
|
||
<script> | ||
let { bar, 'b-az': baz, ...rest } = $props(); | ||
</script> | ||
|
||
<p>{rest.foo}</p> | ||
<p>{bar}</p> | ||
<p>{baz}</p> |
14 changes: 14 additions & 0 deletions
14
...elte/tests/runtime-browser/custom-elements-samples/props-rune-attributes/my-widget.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<svelte:options | ||
customElement={{ | ||
tag: "my-widget", | ||
props: { foo: { attribute: 'foo-bar' } }, | ||
}} | ||
/> | ||
|
||
<script> | ||
let { bar, 'b-az': baz, ...rest } = $props(); | ||
</script> | ||
|
||
<p>{rest.foo}</p> | ||
<p>{bar}</p> | ||
<p>{baz}</p> |