Skip to content

Commit 7d473b7

Browse files
committed
fix(hydration): force hydrate custom element dynamic props
close #7203 close #8038
1 parent 63fd8b6 commit 7d473b7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/runtime-core/__tests__/hydration.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,26 @@ describe('SSR hydration', () => {
13401340
expect((container.firstChild!.firstChild as any)._value).toBe(true)
13411341
})
13421342

1343+
// #7203
1344+
test('force hydrate custom element with dynamic props', () => {
1345+
class MyElement extends HTMLElement {
1346+
foo = ''
1347+
constructor() {
1348+
super()
1349+
}
1350+
}
1351+
customElements.define('my-element-7203', MyElement)
1352+
1353+
const msg = ref('bar')
1354+
const container = document.createElement('div')
1355+
container.innerHTML = '<my-element-7203></my-element-7203>'
1356+
const app = createSSRApp({
1357+
render: () => h('my-element-7203', { foo: msg.value }),
1358+
})
1359+
app.mount(container)
1360+
expect((container.firstChild as any).foo).toBe(msg.value)
1361+
})
1362+
13431363
// #5728
13441364
test('empty text node in slot', () => {
13451365
const Comp = {

packages/runtime-core/src/hydration.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ export function createHydrationFunctions(
447447
!optimized ||
448448
patchFlag & (PatchFlags.FULL_PROPS | PatchFlags.NEED_HYDRATION)
449449
) {
450+
const isCustomElement = el.tagName.includes('-')
450451
for (const key in props) {
451452
// check hydration mismatch
452453
if (
@@ -463,7 +464,8 @@ export function createHydrationFunctions(
463464
(key.endsWith('value') || key === 'indeterminate')) ||
464465
(isOn(key) && !isReservedProp(key)) ||
465466
// force hydrate v-bind with .prop modifiers
466-
key[0] === '.'
467+
key[0] === '.' ||
468+
isCustomElement
467469
) {
468470
patchProp(el, key, null, props[key], undefined, parentComponent)
469471
}

0 commit comments

Comments
 (0)