Skip to content

Commit c80b857

Browse files
committed
fix(runtime-core): should resolve value instead of delete for dynamic props with options
1 parent 0869443 commit c80b857

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,17 @@ describe('component props', () => {
175175
expect(proxy.foo).toBe(2)
176176
expect(proxy.bar).toEqual({ a: 1 })
177177

178-
render(h(Comp, { foo: undefined, bar: { b: 2 } }), root)
178+
render(h(Comp, { bar: { b: 2 } }), root)
179179
expect(proxy.foo).toBe(1)
180180
expect(proxy.bar).toEqual({ b: 2 })
181+
182+
render(h(Comp, { foo: 3, bar: { b: 3 } }), root)
183+
expect(proxy.foo).toBe(3)
184+
expect(proxy.bar).toEqual({ b: 3 })
185+
186+
render(h(Comp, { bar: { b: 4 } }), root)
187+
expect(proxy.foo).toBe(1)
188+
expect(proxy.bar).toEqual({ b: 4 })
181189
})
182190

183191
test('optimized props updates', async () => {

packages/runtime-core/src/componentProps.ts

+28-20
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,16 @@ export function updateProps(
186186
// and converted to camelCase (#955)
187187
((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))
188188
) {
189-
delete props[key]
189+
if (options) {
190+
props[key] = resolvePropValue(
191+
options,
192+
rawProps || EMPTY_OBJ,
193+
key,
194+
undefined
195+
)
196+
} else {
197+
delete props[key]
198+
}
190199
}
191200
}
192201
for (const key in attrs) {
@@ -250,25 +259,24 @@ function resolvePropValue(
250259
key: string,
251260
value: unknown
252261
) {
253-
let opt = options[key]
254-
if (opt == null) {
255-
return value
256-
}
257-
const hasDefault = hasOwn(opt, 'default')
258-
// default values
259-
if (hasDefault && value === undefined) {
260-
const defaultValue = opt.default
261-
value = isFunction(defaultValue) ? defaultValue() : defaultValue
262-
}
263-
// boolean casting
264-
if (opt[BooleanFlags.shouldCast]) {
265-
if (!hasOwn(props, key) && !hasDefault) {
266-
value = false
267-
} else if (
268-
opt[BooleanFlags.shouldCastTrue] &&
269-
(value === '' || value === hyphenate(key))
270-
) {
271-
value = true
262+
const opt = options[key]
263+
if (opt != null) {
264+
const hasDefault = hasOwn(opt, 'default')
265+
// default values
266+
if (hasDefault && value === undefined) {
267+
const defaultValue = opt.default
268+
value = isFunction(defaultValue) ? defaultValue() : defaultValue
269+
}
270+
// boolean casting
271+
if (opt[BooleanFlags.shouldCast]) {
272+
if (!hasOwn(props, key) && !hasDefault) {
273+
value = false
274+
} else if (
275+
opt[BooleanFlags.shouldCastTrue] &&
276+
(value === '' || value === hyphenate(key))
277+
) {
278+
value = true
279+
}
272280
}
273281
}
274282
return value

0 commit comments

Comments
 (0)