Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hydration): avoid hydration mismatch on style variables with falsy values #12442

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,29 @@ describe('SSR hydration', () => {
app.mount(container)
expect(`Hydration style mismatch`).not.toHaveBeenWarned()
})

test('should not warn on css v-bind non-string & non-number & empty string value', () => {
const container = document.createElement('div')
container.innerHTML = `<div style="padding: 4px;"></div>`
const app = createSSRApp({
setup() {
const value1 = ref<any>(null)
const value2 = ref('')
useCssVars(() => ({
foo: value1.value,
bar: value2.value,
}))
return () => h(Child)
},
})
const Child = {
setup() {
return () => h('div', { style: 'padding: 4px' })
},
}
app.mount(container)
expect(`Hydration style mismatch`).not.toHaveBeenWarned()
})
})

describe('data-allow-mismatch', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,10 @@ function resolveCssVars(
) {
const cssVars = instance.getCssVars()
for (const key in cssVars) {
expectedMap.set(
`--${getEscapedCssVarName(key, false)}`,
String(cssVars[key]),
)
const value = cssVars[key]
if ((isString(value) && value.trim()) || typeof value === 'number') {
yangxiuxiu1115 marked this conversation as resolved.
Show resolved Hide resolved
expectedMap.set(`--${getEscapedCssVarName(key, false)}`, String(value))
}
}
}
if (vnode === root && instance.parent) {
Expand Down