Repository navigation
feat: include the component instance in the dev __svelte_meta
#19286
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
Merged
+134
−11
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8cb4892
feat: include the component instance in the dev `__svelte_meta`
baseballyama 9830047
Apply suggestion from @teemingc
dummdidumm 37dce3d
rename test to not collide with other test
dummdidumm 04348be
Merge branch 'main' into feat/svelte-meta-component
dummdidumm 4711338
adjust tests
dummdidumm 2c1c788
Fix: Elements created by `{@html}`, `createRawSnippet`, and native cu…
vercel[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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': minor | ||
| --- | ||
|
|
||
| feat: include the `component` instance an element was rendered in in the dev `__svelte_meta` | ||
This file contains hidden or 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 hidden or 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
63 changes: 63 additions & 0 deletions
63
packages/svelte/tests/runtime-runes/samples/svelte-meta-component/_config.js
This file contains hidden or 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,63 @@ | ||
| import { flushSync } from 'svelte'; | ||
| import { test } from '../../test'; | ||
|
|
||
| export default test({ | ||
| mode: ['client', 'hydrate'], | ||
| compileOptions: { | ||
| dev: true | ||
| }, | ||
| html: ` | ||
| <p>main</p> | ||
| <button>toggle</button> | ||
| <p>main if</p> | ||
| <p>child</p> | ||
| <p>child each</p> | ||
| <p>child</p> | ||
| <p>child each</p> | ||
| <p>passthrough</p> | ||
| <p>main snippet</p> | ||
| <p>main dynamic</p> | ||
| `, | ||
|
|
||
| test({ target, assert }) { | ||
| /** @param {Element} element */ | ||
| const component = (element) => /** @type {any} */ (element).__svelte_meta.component; | ||
|
|
||
| const check = () => { | ||
| const [ | ||
| main, | ||
| main_if, | ||
| child1, | ||
| child1_each, | ||
| child2, | ||
| child2_each, | ||
| passthrough, | ||
| snippet, | ||
| dynamic | ||
| ] = target.querySelectorAll('p'); | ||
|
|
||
| assert.ok(component(main)); | ||
| // the instance that rendered the element, also inside blocks | ||
| assert.equal(component(main_if), component(main)); | ||
| assert.equal(component(dynamic), component(main)); | ||
|
|
||
| // each instance of a component is its own context | ||
| assert.ok(component(child1)); | ||
| assert.notEqual(component(child1), component(main)); | ||
| assert.notEqual(component(child1), component(child2)); | ||
| assert.equal(component(child1_each), component(child1)); | ||
| assert.equal(component(child2_each), component(child2)); | ||
|
|
||
| // a snippet is rendered in the component that renders it, like the `parent` stack | ||
| assert.equal(component(snippet), component(passthrough)); | ||
| }; | ||
|
|
||
| check(); | ||
|
|
||
| // re-created elements belong to the same instance | ||
| const button = /** @type {HTMLButtonElement} */ (target.querySelector('button')); | ||
| flushSync(() => button.click()); | ||
| flushSync(() => button.click()); | ||
| check(); | ||
| } | ||
| }); |
5 changes: 5 additions & 0 deletions
5
packages/svelte/tests/runtime-runes/samples/svelte-meta-component/child.svelte
This file contains hidden or 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 @@ | ||
| <p>child</p> | ||
|
|
||
| {#each [1]} | ||
| <p>child each</p> | ||
| {/each} |
22 changes: 22 additions & 0 deletions
22
packages/svelte/tests/runtime-runes/samples/svelte-meta-component/main.svelte
This file contains hidden or 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,22 @@ | ||
| <script lang="ts"> | ||
| import Child from './child.svelte'; | ||
| import Passthrough from './passthrough.svelte'; | ||
| let show = $state(true); | ||
| </script> | ||
|
|
||
| <p>main</p> | ||
| <button onclick={() => (show = !show)}>toggle</button> | ||
|
|
||
| {#if show} | ||
| <p>main if</p> | ||
| {/if} | ||
|
|
||
| <Child /> | ||
| <Child /> | ||
|
|
||
| <Passthrough> | ||
| <p>main snippet</p> | ||
| </Passthrough> | ||
|
|
||
| <svelte:element this={'p'}>main dynamic</svelte:element> |
6 changes: 6 additions & 0 deletions
6
packages/svelte/tests/runtime-runes/samples/svelte-meta-component/passthrough.svelte
This file contains hidden or 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,6 @@ | ||
| <script lang="ts"> | ||
| let { children } = $props(); | ||
| </script> | ||
|
|
||
| <p>passthrough</p> | ||
| {@render children()} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.