Skip to content

Commit b76c453

Browse files
committed
refactor: adjust absent prop casting logic
1 parent 0255be2 commit b76c453

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

packages/runtime-core/src/componentProps.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ export function updateProps(
226226
rawCurrentProps,
227227
camelizedKey,
228228
value,
229-
instance
229+
instance,
230+
false /* isAbsent */
230231
)
231232
}
232233
} else {
@@ -271,10 +272,11 @@ export function updateProps(
271272
) {
272273
props[key] = resolvePropValue(
273274
options,
274-
rawProps || EMPTY_OBJ,
275+
rawCurrentProps,
275276
key,
276277
undefined,
277-
instance
278+
instance,
279+
true /* isAbsent */
278280
)
279281
}
280282
} else {
@@ -363,14 +365,17 @@ function setFullProps(
363365
}
364366

365367
if (needCastKeys) {
368+
const rawCurrentProps = toRaw(props)
369+
const castValues = rawCastValues || EMPTY_OBJ
366370
for (let i = 0; i < needCastKeys.length; i++) {
367371
const key = needCastKeys[i]
368372
props[key] = resolvePropValue(
369373
options!,
370-
rawCastValues || EMPTY_OBJ,
374+
rawCurrentProps,
371375
key,
372-
rawCastValues && rawCastValues[key],
373-
instance
376+
castValues[key],
377+
instance,
378+
!hasOwn(castValues, key)
374379
)
375380
}
376381
}
@@ -383,7 +388,8 @@ function resolvePropValue(
383388
props: Data,
384389
key: string,
385390
value: unknown,
386-
instance: ComponentInternalInstance
391+
instance: ComponentInternalInstance,
392+
isAbsent: boolean
387393
) {
388394
const opt = options[key]
389395
if (opt != null) {
@@ -412,13 +418,13 @@ function resolvePropValue(
412418
}
413419
// boolean casting
414420
if (opt[BooleanFlags.shouldCast]) {
415-
if (
421+
if (isAbsent && !hasDefault) {
422+
value = false
423+
} else if (
416424
opt[BooleanFlags.shouldCastTrue] &&
417425
(value === '' || value === hyphenate(key))
418426
) {
419427
value = true
420-
} else if (!hasOwn(props, key) && !hasDefault) {
421-
value = false
422428
}
423429
}
424430
}

0 commit comments

Comments
 (0)