-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: guard contents updated before the guard itself #16930
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
+137
−7
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
36ccef8
test: guard effect regression samples
hmnd 7b029d5
fix: skip destroyed eager effects and execute in order of depth
hmnd 140ee11
add changeset
hmnd 73867b9
use bucket sort for better perf
hmnd e50d2b9
simplify
hmnd cd35096
instead of sorting, skip eager effects with eager ancestors in same f…
hmnd c67e58b
don't unlink skipped eager effects
hmnd 749a056
use set for less costly parent lookup
hmnd 891b54f
Merge branch 'main' into push-zkpzuqxyyknn
dummdidumm bed73ac
tidy
dummdidumm 3dac3e7
fix
dummdidumm 739b511
tweak test
dummdidumm a8a5b70
replace unshift with iterating ordered_effects in reverse
hmnd 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': patch | ||
| --- | ||
|
|
||
| fix: ensure guards (eg. if, each, key) run before their contents |
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
20 changes: 20 additions & 0 deletions
20
packages/svelte/tests/runtime-runes/samples/guard-else-effect/_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,20 @@ | ||
| import { test } from '../../test'; | ||
| import { flushSync } from 'svelte'; | ||
|
|
||
| export default test({ | ||
| mode: ['client'], | ||
| async test({ target, assert, logs }) { | ||
| const button = target.querySelector('button'); | ||
|
|
||
| button?.click(); | ||
| flushSync(); | ||
| button?.click(); | ||
| flushSync(); | ||
| button?.click(); | ||
| flushSync(); | ||
| button?.click(); | ||
| flushSync(); | ||
|
|
||
| assert.deepEqual(logs, ['two', 'one', 'two', 'one', 'two']); | ||
| } | ||
| }); |
18 changes: 18 additions & 0 deletions
18
packages/svelte/tests/runtime-runes/samples/guard-else-effect/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,18 @@ | ||
| <script lang="ts"> | ||
| let b = $state(false); | ||
| let v = $state("two"); | ||
| $effect(() => { | ||
| v = b ? "one" : "two"; | ||
| }) | ||
| </script> | ||
|
|
||
| <button onclick={() => b = !b}>Trigger</button> | ||
|
|
||
| {#if v === "one"} | ||
| <div>if1 matched! {console.log('one')}</div> | ||
| {:else if v === "two"} | ||
| <div>if2 matched! {console.log('two')}</div> | ||
| {:else} | ||
| <div>nothing matched {console.log('else')}</div> | ||
| {/if} |
13 changes: 13 additions & 0 deletions
13
packages/svelte/tests/runtime-runes/samples/guard-if-nested/_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,13 @@ | ||
| import { test } from '../../test'; | ||
| import { flushSync } from 'svelte'; | ||
|
|
||
| export default test({ | ||
| mode: ['client'], | ||
| async test({ target, assert }) { | ||
| const button = target.querySelector('button'); | ||
|
|
||
| flushSync(() => button?.click()); | ||
|
|
||
| assert.equal(target.textContent?.trim(), 'Trigger'); | ||
| } | ||
| }); |
18 changes: 18 additions & 0 deletions
18
packages/svelte/tests/runtime-runes/samples/guard-if-nested/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,18 @@ | ||
| <script> | ||
| let centerRow = $state({ nested: { optional: 2, required: 3 } }); | ||
| let someChange = $state(false); | ||
| $effect(() => { | ||
| if (someChange) centerRow = undefined; | ||
| }); | ||
| </script> | ||
|
|
||
| {#if centerRow?.nested} | ||
| {#if centerRow?.nested?.optional != undefined && centerRow.nested.optional > 0} | ||
| op: {centerRow.nested.optional}<br /> | ||
| {:else} | ||
| req: {centerRow.nested.required}<br /> | ||
| {/if} | ||
| {/if} | ||
|
|
||
| <button onclick={() => (someChange = true)}>Trigger</button> |
6 changes: 6 additions & 0 deletions
6
packages/svelte/tests/runtime-runes/samples/guard-nested-if-pre/Component.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> | ||
| let { p } = $props(); | ||
| $effect.pre(() => { | ||
| console.log('running ' + p) | ||
| }) | ||
| </script> |
13 changes: 13 additions & 0 deletions
13
packages/svelte/tests/runtime-runes/samples/guard-nested-if-pre/_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,13 @@ | ||
| import { flushSync } from 'svelte'; | ||
| import { test } from '../../test'; | ||
|
|
||
| export default test({ | ||
| mode: ['client'], | ||
| async test({ assert, target, logs }) { | ||
| const button = target.querySelector('button'); | ||
|
|
||
| button?.click(); | ||
| flushSync(); | ||
| assert.deepEqual(logs, ['pre', 'running b', 'pre', 'pre']); | ||
| } | ||
| }); |
18 changes: 18 additions & 0 deletions
18
packages/svelte/tests/runtime-runes/samples/guard-nested-if-pre/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,18 @@ | ||
| <script> | ||
| import Component from './Component.svelte'; | ||
|
|
||
| let p = $state('b'); | ||
|
|
||
| $effect.pre(() => { | ||
| console.log('pre') | ||
| if (p === 'a') p = null; | ||
| }) | ||
| </script> | ||
|
|
||
| {#if p || !p} | ||
| {#if p} | ||
| <Component {p} /> | ||
| {/if} | ||
| {/if} | ||
|
|
||
| <button onclick={() => p = 'a'}>a</button> |
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.