mirror of https://github.com/vuejs/core.git
refactor: use shared isAttrRenderable logic between ssr and hydration
This commit is contained in:
parent
492a720fd0
commit
81d307a1e9
|
@ -21,8 +21,8 @@ import {
|
||||||
isBooleanAttr,
|
isBooleanAttr,
|
||||||
isKnownHtmlAttr,
|
isKnownHtmlAttr,
|
||||||
isKnownSvgAttr,
|
isKnownSvgAttr,
|
||||||
isObject,
|
|
||||||
isOn,
|
isOn,
|
||||||
|
isRenderableAttrValue,
|
||||||
isReservedProp,
|
isReservedProp,
|
||||||
isString,
|
isString,
|
||||||
normalizeClass,
|
normalizeClass,
|
||||||
|
@ -770,10 +770,9 @@ function propHasMismatch(
|
||||||
} else {
|
} else {
|
||||||
actual = false
|
actual = false
|
||||||
}
|
}
|
||||||
expected =
|
expected = isRenderableAttrValue(clientValue)
|
||||||
isObject(clientValue) || clientValue == null
|
? String(clientValue)
|
||||||
? false
|
: false
|
||||||
: String(clientValue)
|
|
||||||
}
|
}
|
||||||
if (actual !== expected) {
|
if (actual !== expected) {
|
||||||
mismatchType = `attribute`
|
mismatchType = `attribute`
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
import { escapeHtml, isSVGTag, stringifyStyle } from '@vue/shared'
|
import {
|
||||||
|
escapeHtml,
|
||||||
|
isRenderableAttrValue,
|
||||||
|
isSVGTag,
|
||||||
|
stringifyStyle,
|
||||||
|
} from '@vue/shared'
|
||||||
import {
|
import {
|
||||||
includeBooleanAttr,
|
includeBooleanAttr,
|
||||||
isBooleanAttr,
|
isBooleanAttr,
|
||||||
|
@ -47,7 +52,7 @@ export function ssrRenderDynamicAttr(
|
||||||
value: unknown,
|
value: unknown,
|
||||||
tag?: string,
|
tag?: string,
|
||||||
): string {
|
): string {
|
||||||
if (!isRenderableValue(value)) {
|
if (!isRenderableAttrValue(value)) {
|
||||||
return ``
|
return ``
|
||||||
}
|
}
|
||||||
const attrKey =
|
const attrKey =
|
||||||
|
@ -69,20 +74,12 @@ export function ssrRenderDynamicAttr(
|
||||||
// Render a v-bind attr with static key. The key is pre-processed at compile
|
// Render a v-bind attr with static key. The key is pre-processed at compile
|
||||||
// time and we only need to check and escape value.
|
// time and we only need to check and escape value.
|
||||||
export function ssrRenderAttr(key: string, value: unknown): string {
|
export function ssrRenderAttr(key: string, value: unknown): string {
|
||||||
if (!isRenderableValue(value)) {
|
if (!isRenderableAttrValue(value)) {
|
||||||
return ``
|
return ``
|
||||||
}
|
}
|
||||||
return ` ${key}="${escapeHtml(value)}"`
|
return ` ${key}="${escapeHtml(value)}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRenderableValue(value: unknown): boolean {
|
|
||||||
if (value == null) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
const type = typeof value
|
|
||||||
return type === 'string' || type === 'number' || type === 'boolean'
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ssrRenderClass(raw: unknown): string {
|
export function ssrRenderClass(raw: unknown): string {
|
||||||
return escapeHtml(normalizeClass(raw))
|
return escapeHtml(normalizeClass(raw))
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,3 +121,14 @@ export const isKnownSvgAttr = /*#__PURE__*/ makeMap(
|
||||||
`xlink:href,xlink:role,xlink:show,xlink:title,xlink:type,xmlns:xlink,xml:base,xml:lang,` +
|
`xlink:href,xlink:role,xlink:show,xlink:title,xlink:type,xmlns:xlink,xml:base,xml:lang,` +
|
||||||
`xml:space,y,y1,y2,yChannelSelector,z,zoomAndPan`,
|
`xml:space,y,y1,y2,yChannelSelector,z,zoomAndPan`,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared between server-renderer and runtime-core hydration logic
|
||||||
|
*/
|
||||||
|
export function isRenderableAttrValue(value: unknown): boolean {
|
||||||
|
if (value == null) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
const type = typeof value
|
||||||
|
return type === 'string' || type === 'number' || type === 'boolean'
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue