-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
fix: compare array contents for equality mismatch detections, not the arrays themselves #14738
Merged
Merged
Changes from all commits
Commits
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 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> |
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.
can this check as the others that use it be only done in DEV? Seems kind of wasteful to do in production if an item legitimately doesn't exist.
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.
it is only done in dev
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.
nice! oops, sorry, missed that this is all inside
init_array_prototype_warnings
🤦♂️ which is only called in DEV