wip: attr coersion compat
This commit is contained in:
@@ -15,6 +15,10 @@ export function patchAttr(
|
||||
el.setAttributeNS(xlinkNS, key, value)
|
||||
}
|
||||
} else {
|
||||
if (__COMPAT__ && compatCoerceAttr(el, key, value)) {
|
||||
return
|
||||
}
|
||||
|
||||
// note we are only checking boolean attributes that don't have a
|
||||
// corresponding dom prop of the same name here.
|
||||
const isBoolean = isSpecialBooleanAttr(key)
|
||||
@@ -25,3 +29,46 @@ export function patchAttr(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2.x compat
|
||||
import { makeMap, NOOP } from '@vue/shared'
|
||||
import { compatUtils, DeprecationTypes } from '@vue/runtime-core'
|
||||
|
||||
const isEnumeratedAttr = __COMPAT__
|
||||
? /*#__PURE__*/ makeMap('contenteditable,draggable,spellcheck')
|
||||
: NOOP
|
||||
|
||||
export function compatCoerceAttr(
|
||||
el: Element,
|
||||
key: string,
|
||||
value: unknown
|
||||
): boolean {
|
||||
if (isEnumeratedAttr(key)) {
|
||||
const v2CocercedValue =
|
||||
value === null
|
||||
? 'false'
|
||||
: typeof value !== 'boolean' && value !== undefined
|
||||
? 'true'
|
||||
: null
|
||||
if (
|
||||
v2CocercedValue &&
|
||||
compatUtils.softAssertCompatEnabled(
|
||||
DeprecationTypes.ATTR_ENUMERATED_COERSION,
|
||||
key,
|
||||
value,
|
||||
v2CocercedValue
|
||||
)
|
||||
) {
|
||||
el.setAttribute(key, v2CocercedValue)
|
||||
return true
|
||||
}
|
||||
} else if (
|
||||
value === false &&
|
||||
!isSpecialBooleanAttr(key) &&
|
||||
compatUtils.softAssertCompatEnabled(DeprecationTypes.ATTR_FALSE_VALUE, key)
|
||||
) {
|
||||
el.removeAttribute(key)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user