-
-
Couldn't load subscription status.
- Fork 4.7k
fix: on teardown, use the last known value for the signal before the set #15469
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
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
af747f6
fix: on teardown, use the last known value for the signal before the se
trueadm c637694
fix: on teardown, use the last known value for the signal before the se
trueadm 49d2424
fix: on teardown, use the last known value for the signal before the se
trueadm 5ced9be
fix: on teardown, use the last known value for the signal before the se
trueadm d04eddd
fix: on teardown, use the last known value for the signal before the se
trueadm 3990a6b
Update packages/svelte/src/internal/client/reactivity/props.js
trueadm 874f513
Update packages/svelte/src/internal/client/reactivity/props.js
trueadm 18e7262
Update packages/svelte/src/internal/client/reactivity/props.js
trueadm 7009ae7
lint
trueadm 167c551
lint
trueadm 03f6d5c
lint
trueadm d870436
Update .changeset/sharp-elephants-invite.md
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 | ||
| --- | ||
|
|
||
| fix: on teardown, use the last known value for the signal before the set | ||
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
11 changes: 11 additions & 0 deletions
11
packages/svelte/tests/runtime-legacy/samples/ondestroy-prop-access-2/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,11 @@ | ||
| <script> | ||
| import { onDestroy } from 'svelte'; | ||
|
|
||
| export let my_prop; | ||
|
|
||
| onDestroy(() => { | ||
| console.log(my_prop.foo); | ||
| }); | ||
| </script> | ||
|
|
||
| {my_prop.foo} |
14 changes: 14 additions & 0 deletions
14
packages/svelte/tests/runtime-legacy/samples/ondestroy-prop-access-2/_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,14 @@ | ||
| import { test } from '../../test'; | ||
| import { flushSync } from 'svelte'; | ||
|
|
||
| export default test({ | ||
| async test({ assert, target, logs }) { | ||
| const [btn1] = target.querySelectorAll('button'); | ||
|
|
||
| flushSync(() => { | ||
| btn1.click(); | ||
| }); | ||
|
|
||
| assert.deepEqual(logs, ['bar']); | ||
| } | ||
| }); |
15 changes: 15 additions & 0 deletions
15
packages/svelte/tests/runtime-legacy/samples/ondestroy-prop-access-2/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,15 @@ | ||
| <script> | ||
| import Component from './Component.svelte'; | ||
|
|
||
| let value = { foo: 'bar' }; | ||
| </script> | ||
|
|
||
| <button | ||
| onclick={() => { | ||
| value = undefined; | ||
| }}>Reset value</button | ||
| > | ||
|
|
||
| {#if value !== undefined} | ||
| <Component my_prop={value} /> | ||
| {/if} |
5 changes: 5 additions & 0 deletions
5
packages/svelte/tests/runtime-legacy/samples/ondestroy-prop-access-3/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,5 @@ | ||
| <script lang="ts"> | ||
| export let ref; | ||
| </script> | ||
|
|
||
| <input bind:this={ref} /> |
11 changes: 11 additions & 0 deletions
11
packages/svelte/tests/runtime-legacy/samples/ondestroy-prop-access-3/_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,11 @@ | ||
| import { test } from '../../test'; | ||
| import { flushSync } from 'svelte'; | ||
|
|
||
| export default test({ | ||
| async test({ target }) { | ||
| const [btn1] = target.querySelectorAll('button'); | ||
|
|
||
| btn1.click(); | ||
| flushSync(); | ||
| } | ||
| }); |
16 changes: 16 additions & 0 deletions
16
packages/svelte/tests/runtime-legacy/samples/ondestroy-prop-access-3/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,16 @@ | ||
| <script> | ||
| import Component from './Component.svelte'; | ||
| let state = { title: 'foo' }; | ||
| </script> | ||
|
|
||
| {#if state} | ||
| {@const attributes = { title: state.title }} | ||
| <Component {...attributes} /> | ||
| {/if} | ||
| <button | ||
| onclick={() => { | ||
| state = undefined; | ||
| }} | ||
| > | ||
| Del | ||
| </button> |
12 changes: 12 additions & 0 deletions
12
packages/svelte/tests/runtime-legacy/samples/ondestroy-prop-access/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,12 @@ | ||
| <script> | ||
| import { onDestroy } from "svelte"; | ||
| export let checked; | ||
| export let count; | ||
| onDestroy(() => { | ||
| console.log(count, checked); | ||
| }); | ||
| </script> | ||
|
|
||
| <p>{count}</p> | ||
|
|
||
| <button onclick={()=> count-- }></button> |
68 changes: 68 additions & 0 deletions
68
packages/svelte/tests/runtime-legacy/samples/ondestroy-prop-access/_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,68 @@ | ||
| import { test } from '../../test'; | ||
| import { flushSync } from 'svelte'; | ||
|
|
||
| export default test({ | ||
| async test({ assert, target, logs }) { | ||
| const [btn1, btn2, btn3] = target.querySelectorAll('button'); | ||
| let ps = [...target.querySelectorAll('p')]; | ||
|
|
||
| for (const p of ps) { | ||
| assert.equal(p.innerHTML, '0'); | ||
| } | ||
|
|
||
| flushSync(() => { | ||
| btn1.click(); | ||
| }); | ||
|
|
||
| // prop update normally if we are not unmounting | ||
| for (const p of ps) { | ||
| assert.equal(p.innerHTML, '1'); | ||
| } | ||
|
|
||
| flushSync(() => { | ||
| btn3.click(); | ||
| }); | ||
|
|
||
| // binding still works and update the value correctly | ||
| for (const p of ps) { | ||
| assert.equal(p.innerHTML, '0'); | ||
| } | ||
|
|
||
| flushSync(() => { | ||
| btn1.click(); | ||
| }); | ||
|
|
||
| flushSync(() => { | ||
| btn1.click(); | ||
| }); | ||
|
|
||
| console.warn(logs); | ||
|
|
||
| // the five components guarded by `count < 2` unmount and log | ||
| assert.deepEqual(logs, [1, true, 1, true, 1, true, 1, true, 1, true]); | ||
|
|
||
| flushSync(() => { | ||
| btn2.click(); | ||
| }); | ||
|
|
||
| // the three components guarded by `show` unmount and log | ||
| assert.deepEqual(logs, [ | ||
| 1, | ||
| true, | ||
| 1, | ||
| true, | ||
| 1, | ||
| true, | ||
| 1, | ||
| true, | ||
| 1, | ||
| true, | ||
| 2, | ||
| true, | ||
| 2, | ||
| true, | ||
| 2, | ||
| true | ||
| ]); | ||
| } | ||
| }); |
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.