app.mount(container)
expect(`Hydration style mismatch`).not.toHaveBeenWarned()
})
+
+ // #11188
+ test('css vars support fallthrough', () => {
+ const container = document.createElement('div')
+ container.innerHTML = `<div style="padding: 4px;--foo:red;"></div>`
+ const app = createSSRApp({
+ setup() {
+ useCssVars(() => ({
+ foo: 'red',
+ }))
+ return () => h(Child)
+ },
+ })
+ const Child = {
+ setup() {
+ return () => h('div', { style: 'padding: 4px' })
+ },
+ }
+ app.mount(container)
+ expect(`Hydration style mismatch`).not.toHaveBeenWarned()
+ })
})
})
}
}
- // eslint-disable-next-line no-restricted-syntax
- const root = instance?.subTree
- if (
- vnode === root ||
- // eslint-disable-next-line no-restricted-syntax
- (root?.type === Fragment && (root.children as VNode[]).includes(vnode))
- ) {
- // eslint-disable-next-line no-restricted-syntax
- const cssVars = instance?.getCssVars?.()
- for (const key in cssVars) {
- expectedMap.set(`--${key}`, String(cssVars[key]))
- }
+ if (instance) {
+ resolveCssVars(instance, vnode, expectedMap)
}
if (!isMapEqual(actualMap, expectedMap)) {
const styleMap: Map<string, string> = new Map()
for (const item of str.split(';')) {
let [key, value] = item.split(':')
- // eslint-disable-next-line no-restricted-syntax
- key = key?.trim()
- // eslint-disable-next-line no-restricted-syntax
- value = value?.trim()
+ key = key.trim()
+ value = value && value.trim()
if (key && value) {
styleMap.set(key, value)
}
}
return true
}
+
+function resolveCssVars(
+ instance: ComponentInternalInstance,
+ vnode: VNode,
+ expectedMap: Map<string, string>,
+) {
+ const root = instance.subTree
+ if (
+ instance.getCssVars &&
+ (vnode === root ||
+ (root &&
+ root.type === Fragment &&
+ (root.children as VNode[]).includes(vnode)))
+ ) {
+ const cssVars = instance.getCssVars()
+ for (const key in cssVars) {
+ expectedMap.set(`--${key}`, String(cssVars[key]))
+ }
+ }
+ if (vnode === root && instance.parent) {
+ resolveCssVars(instance.parent, instance.vnode, expectedMap)
+ }
+}