Skip to content

Commit

Permalink
fix(runtime): make isSameVnode return false on initial render in a hy…
Browse files Browse the repository at this point in the history
…dration case
  • Loading branch information
christian-bromann committed Jul 8, 2024
1 parent 23f2b47 commit fd87ad2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/runtime/vdom/test/vdom-render.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { isSameVnode } from '../vdom-render'

describe('isSameVnode', () => {
it('should detect objectively same nodes', () => {
const vnode1: any = {
$tag$: 'div',
$key$: '1',
}
const vnode2: any = {
$tag$: 'div',
$key$: '1',
}
expect(isSameVnode(vnode1, vnode2)).toBe(true)
})

it('should return false in case of hyration', () => {
const vnode1: any = {
$tag$: 'slot',
$key$: '1',
$nodeId$: 1,
}
const vnode2: any = {
$tag$: 'slot',
$key$: '1',
}
expect(isSameVnode(vnode1, vnode2, true)).toBe(false)
})
})
6 changes: 6 additions & 0 deletions src/runtime/vdom/vdom-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ export const isSameVnode = (leftVNode: d.VNode, rightVNode: d.VNode, isInitialRe
// compare if two vnode to see if they're "technically" the same
// need to have the same element tag, and same key to be the same
if (leftVNode.$tag$ === rightVNode.$tag$) {
// We can skip key comparison if this is the initial render of the vdom
// in the case of hydration
if ('$nodeId$' in leftVNode && isInitialRender) {
return false;
}

if (BUILD.slotRelocation && leftVNode.$tag$ === 'slot') {
return leftVNode.$name$ === rightVNode.$name$;
}
Expand Down

0 comments on commit fd87ad2

Please sign in to comment.