-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
test(v-model): mutating an array or set checkbox value #13974
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
test(v-model): mutating an array or set checkbox value #13974
Conversation
WalkthroughAdds a new unit test in runtime-dom directive tests to verify vModelCheckbox correctly handles Array and Set bindings, ensuring checkbox state remains in sync after mutations (push, index replacement, and Set add/delete). Updates imports to include vModelCheckbox for directive-based checkbox binding. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant C as Checkbox (DOM)
participant D as vModelCheckbox (Directive)
participant M as Model (Array/Set)
participant R as Renderer
Note over C,D: Initial bind
D->>M: Read current value (Array/Set)
D->>C: Set checked based on membership
U->>C: Toggle click
C->>D: change event
D->>M: Add/Remove value in Array/Set
M-->>D: Updated collection
D->>C: Reflect checked state
Note over M,R: External mutation
U->>M: push/replace / add/delete
M-->>R: Trigger reactive update
R->>D: Patch with new value
D->>C: Recompute checked from membership
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)packages/runtime-dom/__tests__/directives/vModel.spec.ts (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
The PRs #8639 and #13637 both attempted similar fixes that would have introduced regressions. But the existing tests didn't catch those regressions.
This PR introduces an extra test for that case.
Specifically, when an array or set is used for the
value
of an<input type="checkbox">
, mutating the array or set should lead to thechecked
state being updated accordingly. It isn't enough to use an===
check to compare the old and new values, as a mutated array/set won't pass that check.This PR could also be seen as a test case for 2937530, though that wasn't my initial intention.
Also note that the fix in 2937530 only works when
vModelCheckbox
orvModelSelect
are used directly, not when they're wrapped withvModelDynamic
. The tests invModel.spec.ts
do generally usevModelDynamic
, but as it's missing thedeep: true
it won't trigger rendering updates. I haven't attempted to fix that here (it isn't immediately clear to me whether it's safe to adddeep: true
tovModelDynamic
), but I've usedvModelCheckbox
directly in my test case to dodge that problem. In practice, usingvModelCheckbox
more accurately reflects real usage anyway.Summary by CodeRabbit