Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/runtime-core/__tests__/rendererComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,4 +526,33 @@ describe('renderer: component', () => {
// expect Comp to not be re-rendered
expect(spy).toHaveBeenCalledTimes(1)
})

test('should update child component when a prop is replaced by a new undefined prop', async () => {
const props = ref<Record<string, any>>({ foo: 'foo' })

const Comp = {
props: ['foo', 'bar'],
render(this: any) {
return h('div', `${this.foo}-${this.bar}`)
},
}

const App = {
render() {
return h(Comp, props.value)
},
}

const root = nodeOps.createElement('div')
render(h(App), root)
expect(serializeInner(root)).toBe(`<div>foo-undefined</div>`)

props.value = { bar: undefined }
await nextTick()
expect(serializeInner(root)).toBe(`<div>undefined-undefined</div>`)

props.value = { bar: 'bar' }
await nextTick()
expect(serializeInner(root)).toBe(`<div>undefined-bar</div>`)
})
})
4 changes: 3 additions & 1 deletion packages/runtime-core/src/componentRenderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ErrorCodes, handleError } from './errorHandling'
import {
PatchFlags,
ShapeFlags,
hasOwn,
isModelListener,
isObject,
isOn,
Expand Down Expand Up @@ -450,7 +451,8 @@ function hasPropsChanged(
for (let i = 0; i < nextKeys.length; i++) {
const key = nextKeys[i]
if (
hasPropValueChanged(nextProps, prevProps, key) &&
(!hasOwn(prevProps, key) ||
hasPropValueChanged(nextProps, prevProps, key)) &&
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
!isEmitListener(emitsOptions, key)
) {
return true
Expand Down
Loading