-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: Add uidPrefix option to render
#15403
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
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
bf9e411
Add `prefix` option to `render`
Hugos68 f2ab74a
rename to `uidPrefix`
Hugos68 7d988c8
chore: add `uid_prefix` to config for test suites
paoloricciuti d079e83
fix: lint
paoloricciuti aad86eb
Add (currently failing) test
Hugos68 689ba17
chore: `uid_prefix` in `runtime-runes` and `runtime-legacy`
paoloricciuti bf47d64
Fix prefix test
Hugos68 d1906a5
Added `uidPrefix` to `hydrate` and `mount`
Hugos68 5471700
Apply suggestions from code review
dummdidumm 34d84fc
fix naming inconsistency
Hugos68 fb05aaf
chore: add `uidPrefix` to `createClassComponent`
paoloricciuti 740a191
make prefix a prefix
Rich-Harris 7194bb8
rename to idPrefix
Rich-Harris 2079217
set prefix globally, rather than adding a property to component context
Rich-Harris ee92e96
update changeset
Rich-Harris 04dd8e1
unused
Rich-Harris 247f586
do work once rather than n times
Rich-Harris 4538613
unused
Rich-Harris 396575d
fix whitespace
Rich-Harris e549829
revert
Rich-Harris 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: Add `idPrefix` option in `render`/`mount`/`hydrate` functions |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -398,7 +398,13 @@ export function client_component(analysis, options) { | |
|
|
||
| // we want the cleanup function for the stores to run as the very last thing | ||
| // so that it can effectively clean up the store subscription even after the user effects runs | ||
| // if we have $props.id `should_inject_context` will always be true | ||
| if (should_inject_context) { | ||
| // we need to put the `$props.id` after the `$.push` because the `component_context` will be properly initialized | ||
| if (analysis.props_id) { | ||
| // need to be placed on first line of the component for hydration | ||
| component_block.body.unshift(b.const(analysis.props_id, b.call('$.props_id'))); | ||
| } | ||
|
Comment on lines
+403
to
+407
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we don't use context we can revert this change too |
||
| component_block.body.unshift(b.stmt(b.call('$.push', ...push_args))); | ||
|
|
||
| let to_push; | ||
|
|
@@ -562,11 +568,6 @@ export function client_component(analysis, options) { | |
| component_block.body.unshift(b.stmt(b.call('$.check_target', b.id('new.target')))); | ||
| } | ||
|
|
||
| if (analysis.props_id) { | ||
| // need to be placed on first line of the component for hydration | ||
| component_block.body.unshift(b.const(analysis.props_id, b.call('$.props_id'))); | ||
| } | ||
|
|
||
| if (state.events.size > 0) { | ||
| body.push( | ||
| b.stmt(b.call('$.delegate', b.array(Array.from(state.events).map((name) => b.literal(name))))) | ||
|
|
||
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
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
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
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
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
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
5 changes: 5 additions & 0 deletions
5
packages/svelte/tests/runtime-runes/samples/props-id-prefix/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 @@ | ||
| <script> | ||
| let id = $props.id(); | ||
| </script> | ||
|
|
||
| <p>{id}</p> |
60 changes: 60 additions & 0 deletions
60
packages/svelte/tests/runtime-runes/samples/props-id-prefix/_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,60 @@ | ||
| import { flushSync } from 'svelte'; | ||
| import { test } from '../../test'; | ||
|
|
||
| export default test({ | ||
| id_prefix: 'myPrefix', | ||
| test({ assert, target, variant }) { | ||
| if (variant === 'dom') { | ||
| assert.htmlEqual( | ||
| target.innerHTML, | ||
| ` | ||
| <button>toggle</button> | ||
| <h1>myPrefix-c1</h1> | ||
| <p>myPrefix-c2</p> | ||
| <p>myPrefix-c3</p> | ||
| <p>myPrefix-c4</p> | ||
| ` | ||
| ); | ||
| } else { | ||
| assert.htmlEqual( | ||
| target.innerHTML, | ||
| ` | ||
| <button>toggle</button> | ||
| <h1>myPrefix-s1</h1> | ||
| <p>myPrefix-s2</p> | ||
| <p>myPrefix-s3</p> | ||
| <p>myPrefix-s4</p> | ||
| ` | ||
| ); | ||
| } | ||
|
|
||
| let button = target.querySelector('button'); | ||
| flushSync(() => button?.click()); | ||
|
|
||
| if (variant === 'dom') { | ||
| assert.htmlEqual( | ||
| target.innerHTML, | ||
| ` | ||
| <button>toggle</button> | ||
| <h1>myPrefix-c1</h1> | ||
| <p>myPrefix-c2</p> | ||
| <p>myPrefix-c3</p> | ||
| <p>myPrefix-c4</p> | ||
| <p>myPrefix-c5</p> | ||
| ` | ||
| ); | ||
| } else { | ||
| assert.htmlEqual( | ||
| target.innerHTML, | ||
| ` | ||
| <button>toggle</button> | ||
| <h1>myPrefix-s1</h1> | ||
| <p>myPrefix-s2</p> | ||
| <p>myPrefix-s3</p> | ||
| <p>myPrefix-s4</p> | ||
| <p>myPrefix-c1</p> | ||
| ` | ||
| ); | ||
| } | ||
| } | ||
| }); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also revert this if we don't use context anymore