Skip to content

Commit

Permalink
fix(hydration): force hydrate custom element dynamic props
Browse files Browse the repository at this point in the history
close #7203
close #8038
  • Loading branch information
yyx990803 committed Aug 6, 2024
1 parent 63fd8b6 commit 7d473b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,26 @@ describe('SSR hydration', () => {
expect((container.firstChild!.firstChild as any)._value).toBe(true)
})

// #7203
test('force hydrate custom element with dynamic props', () => {
class MyElement extends HTMLElement {
foo = ''
constructor() {
super()
}
}
customElements.define('my-element-7203', MyElement)

const msg = ref('bar')
const container = document.createElement('div')
container.innerHTML = '<my-element-7203></my-element-7203>'
const app = createSSRApp({
render: () => h('my-element-7203', { foo: msg.value }),
})
app.mount(container)
expect((container.firstChild as any).foo).toBe(msg.value)
})

// #5728
test('empty text node in slot', () => {
const Comp = {
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ export function createHydrationFunctions(
!optimized ||
patchFlag & (PatchFlags.FULL_PROPS | PatchFlags.NEED_HYDRATION)
) {
const isCustomElement = el.tagName.includes('-')
for (const key in props) {
// check hydration mismatch
if (
Expand All @@ -463,7 +464,8 @@ export function createHydrationFunctions(
(key.endsWith('value') || key === 'indeterminate')) ||
(isOn(key) && !isReservedProp(key)) ||
// force hydrate v-bind with .prop modifiers
key[0] === '.'
key[0] === '.' ||
isCustomElement
) {
patchProp(el, key, null, props[key], undefined, parentComponent)
}
Expand Down

0 comments on commit 7d473b7

Please sign in to comment.