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(rumtime-core): custom dom props should be cloned when cloning a hoisted DOM #3080

Merged
merged 4 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 12 additions & 0 deletions packages/runtime-dom/__tests__/nodeOps.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { nodeOps } from '../src/nodeOps'

describe('nodeOps', () => {
test('the _value property should be cloned', () => {
const el = nodeOps.createElement('input') as HTMLDivElement & {
_value: any
}
el._value = 1
const cloned = nodeOps.cloneNode!(el) as HTMLDivElement & { _value: any }
expect(cloned._value).toBe(1)
})
})
12 changes: 11 additions & 1 deletion packages/runtime-dom/src/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = {
},

cloneNode(el) {
return el.cloneNode(true)
const cloned = el.cloneNode(true)
// #3072
// should clone the custom DOM props,
// in `patchDOMProp`, we store the actual value in the `el._value` property,
// but these elements may be hoisted, and the hoisted elements will be cloned in the prod env,
// so we should keep it when cloning, and in the future,
// we may clone more custom DOM props when necessary, not just `_value`.
if (cloned.nodeType === Node.ELEMENT_NODE) {
;(cloned as any)._value = (el as any)._value
}
return cloned
},

// __UNSAFE__
Expand Down