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(':')
|
let [key, value] = item.split(':')
|
||||||
key = key.trim()
|
key = key.trim()
|
||||||
value = value && value.trim()
|
value = value && value.trim()
|
||||||
if (key && isRenderableAttrValue(value)) {
|
if (key) {
|
||||||
styleMap.set(key, value)
|
styleMap.set(key, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -465,31 +465,4 @@ describe('useCssVars', () => {
|
||||||
render(h(App), root)
|
render(h(App), root)
|
||||||
expect(colorInOnMount).toBe(`red`)
|
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,
|
warn,
|
||||||
watch,
|
watch,
|
||||||
} from '@vue/runtime-core'
|
} 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' : '')
|
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
|
const style = (el as HTMLElement).style
|
||||||
let cssText = ''
|
let cssText = ''
|
||||||
for (const key in vars) {
|
for (const key in vars) {
|
||||||
const value = vars[key]
|
style.setProperty(`--${key}`, vars[key])
|
||||||
if (isRenderableAttrValue(value)) {
|
cssText += `--${key}: ${vars[key]};`
|
||||||
const trimVal = String(value).trim()
|
|
||||||
style.setProperty(`--${key}`, trimVal)
|
|
||||||
cssText += `--${key}: ${trimVal};`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
;(style as any)[CSS_VAR_TEXT] = cssText
|
;(style as any)[CSS_VAR_TEXT] = cssText
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue