mirror of https://github.com/vuejs/core.git
chore: avoid affecting the client's existing rendering behavior
Currently client-side rendering supports null and undefined, which prevents styles from being inherited from the parent node.
This commit is contained in:
parent
86de25311f
commit
e7ce2974d7
|
@ -904,7 +904,7 @@ function toStyleMap(str: string): Map<string, string> {
|
|||
let [key, value] = item.split(':')
|
||||
key = key.trim()
|
||||
value = value && value.trim()
|
||||
if (key && isRenderableAttrValue(value)) {
|
||||
if (key) {
|
||||
styleMap.set(key, value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -465,31 +465,4 @@ describe('useCssVars', () => {
|
|||
render(h(App), root)
|
||||
expect(colorInOnMount).toBe(`red`)
|
||||
})
|
||||
|
||||
test('filter non-string、non-boolean、non-number value', () => {
|
||||
const state = reactive<any>({
|
||||
color: 'red',
|
||||
size: {},
|
||||
width: false,
|
||||
height: 10,
|
||||
})
|
||||
const root = document.createElement('div')
|
||||
let style!: CSSStyleDeclaration
|
||||
|
||||
const App = {
|
||||
setup() {
|
||||
useCssVars(() => state)
|
||||
onMounted(() => {
|
||||
style = (root.children[0] as HTMLElement).style
|
||||
})
|
||||
return () => h('div')
|
||||
},
|
||||
}
|
||||
|
||||
render(h(App), root)
|
||||
expect(style.getPropertyValue(`--color`)).toBe(`red`)
|
||||
expect(style.getPropertyValue(`--size`)).toBe(``)
|
||||
expect(style.getPropertyValue(`--width`)).toBe(`false`)
|
||||
expect(style.getPropertyValue(`--height`)).toBe(`10`)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
warn,
|
||||
watch,
|
||||
} from '@vue/runtime-core'
|
||||
import { NOOP, ShapeFlags, isRenderableAttrValue } from '@vue/shared'
|
||||
import { NOOP, ShapeFlags } from '@vue/shared'
|
||||
|
||||
export const CSS_VAR_TEXT: unique symbol = Symbol(__DEV__ ? 'CSS_VAR_TEXT' : '')
|
||||
/**
|
||||
|
@ -99,12 +99,8 @@ function setVarsOnNode(el: Node, vars: Record<string, string>) {
|
|||
const style = (el as HTMLElement).style
|
||||
let cssText = ''
|
||||
for (const key in vars) {
|
||||
const value = vars[key]
|
||||
if (isRenderableAttrValue(value)) {
|
||||
const trimVal = String(value).trim()
|
||||
style.setProperty(`--${key}`, trimVal)
|
||||
cssText += `--${key}: ${trimVal};`
|
||||
}
|
||||
style.setProperty(`--${key}`, vars[key])
|
||||
cssText += `--${key}: ${vars[key]};`
|
||||
}
|
||||
;(style as any)[CSS_VAR_TEXT] = cssText
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue