fix(runtime-core): preserve nullish event handlers in mergeProps#14550
fix(runtime-core): preserve nullish event handlers in mergeProps#14550zhiyuanzmj wants to merge 2 commits intovuejs:mainfrom
Conversation
mergeProps Ensure event listeners that are explicitly null or undefined are preserved during prop merging instead of being dropped.
📝 WalkthroughWalkthroughAdded tests and a small runtime change: mergeProps now explicitly preserves falsy (including null) event handler values when both incoming and existing props are falsy; tests were added to verify onClick: undefined and onClick: null are preserved after merging. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/runtime-core/__tests__/vnode.spec.ts (1)
475-478: Good basic test coverage for the new functionality.The test correctly verifies that
mergeProps({ onClick: null })preservesonClick: nullin the result.Consider adding a few more edge case tests to strengthen coverage:
🧪 Optional: Additional test cases
expect(mergeProps({ onClick: null })).toMatchObject({ onClick: null, }) + // undefined is also preserved + expect(mergeProps({ onClick: undefined })).toMatchObject({ + onClick: undefined, + }) + // existing handler is preserved when merging with null + expect(mergeProps({ onClick: clickHandler1 }, { onClick: null })).toMatchObject({ + onClick: clickHandler1, + })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/runtime-core/__tests__/vnode.spec.ts` around lines 475 - 478, Add a few edge-case unit tests for mergeProps in packages/runtime-core/__tests__/vnode.spec.ts: cover merging event handlers (e.g., onClick functions concatenation/override behavior), merging when a prop is undefined versus null (ensure null is preserved and undefined skipped/merged correctly), merging array/value props (arrays are concatenated or replaced per implementation), and merging objects like style/class to verify deep merge semantics; create concise test cases that call mergeProps with these inputs and assert the expected outputs using expect(...).toMatchObject or toEqual, referencing mergeProps directly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/runtime-core/__tests__/vnode.spec.ts`:
- Around line 475-478: Add a few edge-case unit tests for mergeProps in
packages/runtime-core/__tests__/vnode.spec.ts: cover merging event handlers
(e.g., onClick functions concatenation/override behavior), merging when a prop
is undefined versus null (ensure null is preserved and undefined skipped/merged
correctly), merging array/value props (arrays are concatenated or replaced per
implementation), and merging objects like style/class to verify deep merge
semantics; create concise test cases that call mergeProps with these inputs and
assert the expected outputs using expect(...).toMatchObject or toEqual,
referencing mergeProps directly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7ea8780f-dcb5-47cb-91f7-249399eb4c0d
📒 Files selected for processing (2)
packages/runtime-core/__tests__/vnode.spec.tspackages/runtime-core/src/vnode.ts
There was a problem hiding this comment.
Pull request overview
This PR adjusts mergeProps in runtime-core to ensure event listener props that are explicitly set to null/undefined are retained in the merged output rather than being omitted, and adds a regression test in the vnode suite.
Changes:
- Update
mergePropsevent-handler merging to preserve explicitly falsy (nullish) incoming handlers when there is no existing handler. - Add a vnode unit test covering the
onClick: nullmerge behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/runtime-core/src/vnode.ts | Updates mergeProps handler merging behavior to keep nullish handlers from being dropped. |
| packages/runtime-core/tests/vnode.spec.ts | Adds a regression assertion for preserving onClick: null during merge. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/ecosystem-ci run |
|
📝 Ran ecosystem CI: Open
|
Ensure event listeners that are explicitly null or undefined are preserved during prop merging instead of being dropped.
Summary by CodeRabbit
Bug Fixes
Tests