-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: compare array contents for equality mismatch detections, not the…
… arrays themselves (#14738)
- Loading branch information
1 parent
d7e4bd2
commit 36a437c
Showing
4 changed files
with
84 additions
and
18 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: compare array contents for equality mismatch detections, not the arrays themselves |
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
41 changes: 41 additions & 0 deletions
41
packages/svelte/tests/runtime-runes/samples/state-proxy-equality-mismatch/_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,41 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
compileOptions: { | ||
dev: true | ||
}, | ||
|
||
async test({ assert, target, warnings }) { | ||
const [btn1, btn2, btn3, btn4, btn5, btn6, clear] = target.querySelectorAll('button'); | ||
|
||
flushSync(() => { | ||
btn1.click(); | ||
btn2.click(); | ||
btn3.click(); | ||
btn4.click(); | ||
btn5.click(); | ||
btn6.click(); | ||
}); | ||
|
||
assert.deepEqual(warnings, [ | ||
'Reactive `$state(...)` proxies and the values they proxy have different identities. Because of this, comparisons with `array.includes(...)` will produce unexpected results', | ||
'Reactive `$state(...)` proxies and the values they proxy have different identities. Because of this, comparisons with `array.indexOf(...)` will produce unexpected results', | ||
'Reactive `$state(...)` proxies and the values they proxy have different identities. Because of this, comparisons with `array.lastIndexOf(...)` will produce unexpected results' | ||
]); | ||
|
||
flushSync(() => clear.click()); | ||
warnings.length = 0; | ||
|
||
flushSync(() => { | ||
btn1.click(); | ||
btn2.click(); | ||
btn3.click(); | ||
btn4.click(); | ||
btn5.click(); | ||
btn6.click(); | ||
}); | ||
|
||
assert.deepEqual(warnings, []); | ||
} | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/svelte/tests/runtime-runes/samples/state-proxy-equality-mismatch/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,23 @@ | ||
<script> | ||
let primitive = 'foo'; | ||
let object = {}; | ||
let array = $state([primitive, object]); | ||
</script> | ||
|
||
<button onclick={() => array.includes(primitive)}>array.includes(primitive)</button> | ||
<button onclick={() => array.includes(object)}>array.includes(object)</button> | ||
|
||
<hr /> | ||
|
||
<button onclick={() => array.indexOf(primitive)}>array.indexOf(primitive)</button> | ||
<button onclick={() => array.indexOf(object)}>array.indexOf(object)</button> | ||
|
||
<hr /> | ||
|
||
<button onclick={() => array.lastIndexOf(primitive)}>array.lastIndexOf(primitive)</button> | ||
<button onclick={() => array.lastIndexOf(object)}>array.lastIndexOf(object)</button> | ||
|
||
<hr /> | ||
|
||
<button onclick={() => (array.length = 0)}>clear</button> |