-
- Notifications
You must be signed in to change notification settings - Fork 8.7k
fix(runtime-core): ensure correct anchor el for unresolved async components #13560
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
base: main
Are you sure you want to change the base?
fix(runtime-core): ensure correct anchor el for unresolved async components #13560
Conversation
""" WalkthroughThe patch introduces tracking of placeholder DOM elements for unresolved async components inside Suspense by adding a Changes
Sequence Diagram(s)sequenceDiagram participant Renderer participant SuspenseBoundary participant AsyncComponent participant PlaceholderNode participant DOM Renderer->>SuspenseBoundary: Mount component with async dependency SuspenseBoundary->>PlaceholderNode: Create and insert placeholder comment node SuspenseBoundary->>Renderer: Assign placeholder to vnode AsyncComponent-->>SuspenseBoundary: Async component resolves SuspenseBoundary->>DOM: Replace placeholder with resolved component DOM Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes detected. Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (5)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File ( |
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/runtime-core/src/renderer.ts (1)
1982-1990
: Good fix for async component anchor determination, but consider additional safety checks.The logic correctly handles the case where an async component hasn't resolved yet by using
component.subTree.el
instead ofvnode.el
. This is important because for unresolved async components, the vnode'sel
property may not yet point to the correct DOM element.However, consider adding a null safety check for the
subTree
property:let anchor = parentAnchor if (nextIndex + 1 < l2) { const anchorVnode = c2[nextIndex + 1] as VNode - if (anchorVnode.component && !anchorVnode.component.asyncResolved) { + if (anchorVnode.component && !anchorVnode.component.asyncResolved && anchorVnode.component.subTree) { anchor = anchorVnode.component.subTree.el } else { anchor = anchorVnode.el } }This ensures that
subTree
exists before accessing itsel
property, which could be important during the component's lifecycle.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/runtime-core/src/renderer.ts
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/runtime-core/src/renderer.ts (1)
packages/runtime-core/src/vnode.ts (1)
VNode
(160-256)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Redirect rules
- GitHub Check: Header rules
- GitHub Check: Pages changed
- GitHub Check: test / e2e-test
…fork into fix-patch-keyed-children-w/-async-component
@@ -1226,6 +1226,7 @@ function baseCreateRenderer( | |||
if (!initialVNode.el) { | |||
const placeholder = (instance.subTree = createVNode(Comment)) | |||
processCommentNode(null, placeholder, container!, anchor) | |||
initialVNode.el = placeholder.el |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect, a component cannot have el
before mounting. If it has an el
, it would trigger hydration logic instead of mounting.
close #13559
When the asynchronous component is not resolved, Vue will use a placeholder to occupy the position of the rendering result. At this time, we need to get the actual placeholder el to ensure that the anchor point of the subsequent insertion operation is correct.
playground with this pr
Summary by CodeRabbit
Bug Fixes
Tests