Skip to content

Commit 19cc7e2

Browse files
authored
fix(runtime-core): skip patching reserved props for custom elements (#14275)
close #14274
1 parent c2f5964 commit 19cc7e2

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,24 @@ describe('SSR hydration', () => {
15971597
expect((container.firstChild as any).foo).toBe(msg.value)
15981598
})
15991599

1600+
// #14274
1601+
test('should not render ref on custom element during hydration', () => {
1602+
const container = document.createElement('div')
1603+
container.innerHTML = '<my-element>hello</my-element>'
1604+
const root = ref()
1605+
const app = createSSRApp({
1606+
render: () =>
1607+
h('my-element', {
1608+
ref: root,
1609+
innerHTML: 'hello',
1610+
}),
1611+
})
1612+
app.mount(container)
1613+
expect(container.innerHTML).toBe('<my-element>hello</my-element>')
1614+
expect((container.firstChild as Element).hasAttribute('ref')).toBe(false)
1615+
expect(root.value).toBe(container.firstChild)
1616+
})
1617+
16001618
// #5728
16011619
test('empty text node in slot', () => {
16021620
const Comp = {

packages/runtime-core/src/hydration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ export function createHydrationFunctions(
507507
(isOn(key) && !isReservedProp(key)) ||
508508
// force hydrate v-bind with .prop modifiers
509509
key[0] === '.' ||
510-
isCustomElement
510+
(isCustomElement && !isReservedProp(key))
511511
) {
512512
patchProp(el, key, null, props[key], undefined, parentComponent)
513513
}

0 commit comments

Comments
 (0)