Skip to content

Commit 952c517

Browse files
committed
fix(runtime-core): handle null props in component FULL_PROPS patch
1 parent d0253a0 commit 952c517

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,25 @@ describe('renderer: optimized mode', () => {
221221
)
222222
})
223223

224+
test('component PatchFlags: PatchFlags.FULL_PROPS w/ null props', () => {
225+
const Comp = defineComponent({
226+
setup() {
227+
return () => createVNode('p')
228+
},
229+
})
230+
231+
renderWithBlock(() => [createVNode(Comp, null, '', PatchFlags.FULL_PROPS)])
232+
expect(inner(root)).toBe('<div><p></p></div>')
233+
234+
renderWithBlock(() => [
235+
createVNode(Comp, { foo: 'true' }, '', PatchFlags.FULL_PROPS),
236+
])
237+
expect(inner(root)).toBe('<div><p foo="true"></p></div>')
238+
239+
renderWithBlock(() => [createVNode(Comp, null, '', PatchFlags.FULL_PROPS)])
240+
expect(inner(root)).toBe('<div><p></p></div>')
241+
})
242+
224243
// the order and length of the list will not change
225244
test('PatchFlags: PatchFlags.STABLE_FRAGMENT', async () => {
226245
let list = ['foo', 'bar']

packages/runtime-core/src/componentRenderUtils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ export function shouldUpdateComponent(
392392
if (!prevProps) {
393393
return !!nextProps
394394
}
395+
if (!nextProps) {
396+
return !!prevProps
397+
}
398+
395399
// presence of this flag indicates props are always non-null
396400
return hasPropsChanged(prevProps, nextProps!, emits)
397401
} else if (patchFlag & PatchFlags.PROPS) {

0 commit comments

Comments
 (0)