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): v-bind supports hydration #10250

Merged
merged 8 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,10 @@ export interface ComponentInternalInstance {
* For updating css vars on contained teleports
* @internal
*/
ut?: (vars?: Record<string, string>) => void
ut?: (
vars?: Record<string, string>,
hydration?: boolean,
) => void | Record<string, string>
}

const emptyAppContext = createAppContext()
Expand Down
15 changes: 14 additions & 1 deletion packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,16 @@ export function createHydrationFunctions(
!optimized ||
patchFlag & (PatchFlags.FULL_PROPS | PatchFlags.NEED_HYDRATION)
) {
const cssVars = parentComponent?.ut?.(undefined, true) as Record<
string,
string
>
for (const key in props) {
// check hydration mismatch
if (__DEV__ && propHasMismatch(el, key, props[key], vnode)) {
if (
__DEV__ &&
propHasMismatch(el, key, props[key], vnode, cssVars)
) {
hasMismatch = true
}
if (
Expand Down Expand Up @@ -718,6 +725,7 @@ function propHasMismatch(
key: string,
clientValue: any,
vnode: VNode,
cssVars?: Record<string, string>,
): boolean {
let mismatchType: string | undefined
let mismatchKey: string | undefined
Expand Down Expand Up @@ -748,6 +756,11 @@ function propHasMismatch(
}
}
}
if (cssVars) {
for (const key in cssVars) {
expectedMap.set(key, cssVars[key])
}
}
if (!isMapEqual(actualMap, expectedMap)) {
mismatchType = mismatchKey = 'style'
}
Expand Down
8 changes: 7 additions & 1 deletion packages/runtime-dom/src/helpers/useCssVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ export function useCssVars(getter: (ctx: any) => Record<string, string>) {
return
}

const updateTeleports = (instance.ut = (vars = getter(instance.proxy)) => {
const updateTeleports = (instance.ut = (
vars = getter(instance.proxy),
hydration = false,
yangxiuxiu1115 marked this conversation as resolved.
Show resolved Hide resolved
) => {
if (hydration) {
return vars
}
Array.from(
document.querySelectorAll(`[data-v-owner="${instance.uid}"]`),
).forEach(node => setVarsOnNode(node, vars))
Expand Down
Loading