-
-
Notifications
You must be signed in to change notification settings - Fork 9k
fix(hmr): handle cached text node update #14134
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
Changes from all commits
c70913b
7e08418
6c11c4d
8bf4f30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -500,7 +500,27 @@ function baseCreateRenderer( | |
| } else { | ||
| const el = (n2.el = n1.el!) | ||
| if (n2.children !== n1.children) { | ||
| hostSetText(el, n2.children as string) | ||
| // We don't inherit el for cached text nodes in `traverseStaticChildren` | ||
| // to avoid retaining detached DOM nodes. However, the text node may be | ||
| // changed during HMR. In this case we need to replace the old text node | ||
| // with the new one. | ||
| if ( | ||
| __DEV__ && | ||
| isHmrUpdating && | ||
| n2.patchFlag === PatchFlags.CACHED && | ||
| '__elIndex' in n1 | ||
| ) { | ||
| const childNodes = __TEST__ | ||
| ? container.children | ||
| : container.childNodes | ||
| const newChild = hostCreateText(n2.children as string) | ||
| const oldChild = | ||
| childNodes[((n2 as any).__elIndex = (n1 as any).__elIndex)] | ||
| hostInsert(newChild, container, oldChild) | ||
| hostRemove(oldChild) | ||
edison1105 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| hostSetText(el, n2.children as string) | ||
| } | ||
|
Comment on lines
+503
to
+523
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Read the target code in renderer.ts around lines 503-523
head -n 530 packages/runtime-core/src/renderer.ts | tail -n 40Repository: vuejs/core Length of output: 1304 🏁 Script executed: #!/bin/bash
# Search for traverseStaticChildren function and __TEST__ usage with container.children
rg -n "traverseStaticChildren|container\.children" packages/runtime-core/src/renderer.ts -A 5 -B 2Repository: vuejs/core Length of output: 2469 🏁 Script executed: #!/bin/bash
# Search for processText function to see full context
rg -n "const processText" packages/runtime-core/src/renderer.ts -A 30Repository: vuejs/core Length of output: 1333 Critical: After creating Additionally, the 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| } | ||
|
|
@@ -2496,12 +2516,17 @@ export function traverseStaticChildren( | |
| traverseStaticChildren(c1, c2) | ||
| } | ||
| // #6852 also inherit for text nodes | ||
| if ( | ||
| c2.type === Text && | ||
| if (c2.type === Text) { | ||
| // avoid cached text nodes retaining detached dom nodes | ||
| c2.patchFlag !== PatchFlags.CACHED | ||
| ) { | ||
| c2.el = c1.el | ||
| if (c2.patchFlag !== PatchFlags.CACHED) { | ||
| c2.el = c1.el | ||
| } else { | ||
| // cache the child index for HMR updates | ||
| ;(c2 as any).__elIndex = | ||
| i + | ||
| // take fragment start anchor into account | ||
| (n1.type === Fragment ? 1 : 0) | ||
| } | ||
| } | ||
| // #2324 also inherit for comment nodes, but not placeholders (e.g. v-if which | ||
| // would have received .el during block patch) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.