onMounted,
ref,
renderSlot,
+ useCssVars,
vModelCheckbox,
vShow,
withDirectives,
)
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
})
+
+ test('should not warn css v-bind', () => {
+ const container = document.createElement('div')
+ container.innerHTML = `<div style="--foo:red;color:var(--foo);" />`
+ const app = createSSRApp({
+ setup() {
+ useCssVars(() => ({
+ foo: 'red',
+ }))
+ return () => h('div', { style: { color: 'var(--foo)' } })
+ },
+ })
+ app.mount(container)
+ expect(`Hydration style mismatch`).not.toHaveBeenWarned()
+ })
})
})
* @internal
*/
ut?: (vars?: Record<string, string>) => void
+
+ /**
+ * dev only. For style v-bind hydration mismatch checks
+ * @internal
+ */
+ getCssVars?: () => Record<string, string>
}
const emptyAppContext = createAppContext()
) {
for (const key in props) {
// check hydration mismatch
- if (__DEV__ && propHasMismatch(el, key, props[key], vnode)) {
+ if (
+ __DEV__ &&
+ propHasMismatch(el, key, props[key], vnode, parentComponent)
+ ) {
hasMismatch = true
}
if (
key: string,
clientValue: any,
vnode: VNode,
+ instance: ComponentInternalInstance | null,
): boolean {
let mismatchType: string | undefined
let mismatchKey: string | undefined
}
}
}
+
+ const cssVars = instance?.getCssVars?.()
+ for (const key in cssVars) {
+ expectedMap.set(`--${key}`, String(cssVars[key]))
+ }
+
if (!isMapEqual(actualMap, expectedMap)) {
mismatchType = mismatchKey = 'style'
}
).forEach(node => setVarsOnNode(node, vars))
})
+ if (__DEV__) {
+ instance.getCssVars = () => getter(instance.proxy)
+ }
+
const setVars = () => {
const vars = getter(instance.proxy)
setVarsOnVNode(instance.subTree, vars)