Repository navigation
fix(runtime-vapor): defer slot content anchors during hydration - #15027
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/compiler-vapor
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/runtime-vapor
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
packages/runtime-vapor/__tests__/componentSlots.spec.ts (2)
865-880: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winPin the anchor’s position, not just its parent.
Line 880 only checks that the runtime anchor ended up under
host. This regression is about keeping the anchor on the correct side of the slot boundary, so the test should also assert its sibling position against the slot end marker.Suggested assertion
expect(frag.anchor.parentNode).toBe(host) + expect(frag.anchor.nextSibling).toBe(end)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/runtime-vapor/__tests__/componentSlots.spec.ts` around lines 865 - 880, The test in componentSlots.spec.ts only verifies that hydrateDynamicFragmentAnchor leaves the anchor under host, but it should also assert the anchor’s sibling position relative to the slot boundary marker. Update the expectation around frag/anchor in the DynamicFragment and hydrateDynamicFragmentAnchor flow to check that the anchor remains on the correct side of the slot end marker, not just that its parentNode is host.
752-758: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the outer pending state after the nested boundary exits.
This proves the inner boundary resets to
false, but not that unwind restores the outer pending flag beforefinish(true)runs. A restore bug inwithHydratingSlotBoundary()would still pass here.Suggested assertion
setCurrentHydrationNode(end) withHydratingSlotBoundary(() => { expect(getCurrentSlotEndAnchor()).toBe(end) expect(isPendingSlotContent()).toBe(false) }) + expect(isPendingSlotContent()).toBe(true) } finally { finish(true) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/runtime-vapor/__tests__/componentSlots.spec.ts` around lines 752 - 758, The current test around withHydratingSlotBoundary only checks the nested boundary’s pending state, so it can miss a restore bug during unwind. Update componentSlots.spec.ts to assert the outer pending state before and/or after the inner withHydratingSlotBoundary callback exits, using getCurrentSlotEndAnchor() and isPendingSlotContent() around the existing finally { finish(true) } flow, so the test verifies the outer flag is restored correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/runtime-vapor/__tests__/hydration.spec.ts`:
- Line 11558: The hydration test only suppresses one warning, so a regression to
the other mismatch warning would still pass. Update the assertion in the
hydration spec to guard both hydration mismatch warning variants by checking
that neither the Hydration node mismatch nor the Hydration children mismatch
warning is emitted in this scenario, using the existing warning matcher in the
same test block.
In `@packages/runtime-vapor/src/dom/hydrateFragment.ts`:
- Around line 306-314: The pending fragment path in hydrateFragment should not
keep reusing the captured next anchor when multiple empty slot-content fragments
are pending. Update the pending branch in hydrateFragment (and the corresponding
logic around the later callback handling in the same flow) so anchors are
adopted from the live hydration cursor/currentHydrationNode at the moment
content wins, rather than from plan.next captured earlier. This ensures each
pending fragment consumes its own SSR anchor and prevents later callbacks from
sharing the same anchor.
---
Nitpick comments:
In `@packages/runtime-vapor/__tests__/componentSlots.spec.ts`:
- Around line 865-880: The test in componentSlots.spec.ts only verifies that
hydrateDynamicFragmentAnchor leaves the anchor under host, but it should also
assert the anchor’s sibling position relative to the slot boundary marker.
Update the expectation around frag/anchor in the DynamicFragment and
hydrateDynamicFragmentAnchor flow to check that the anchor remains on the
correct side of the slot end marker, not just that its parentNode is host.
- Around line 752-758: The current test around withHydratingSlotBoundary only
checks the nested boundary’s pending state, so it can miss a restore bug during
unwind. Update componentSlots.spec.ts to assert the outer pending state before
and/or after the inner withHydratingSlotBoundary callback exits, using
getCurrentSlotEndAnchor() and isPendingSlotContent() around the existing finally
{ finish(true) } flow, so the test verifies the outer flag is restored
correctly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3a09d354-d529-42f4-93b5-44e0aace90b3
📒 Files selected for processing (9)
packages/runtime-vapor/__tests__/componentSlots.spec.tspackages/runtime-vapor/__tests__/dom/hydrateFragment.spec.tspackages/runtime-vapor/__tests__/hydration.spec.tspackages/runtime-vapor/src/apiCreateFor.tspackages/runtime-vapor/src/component.tspackages/runtime-vapor/src/dom/hydrateFragment.tspackages/runtime-vapor/src/dom/template.tspackages/runtime-vapor/src/fragment.tspackages/runtime-vapor/src/vdomInterop.ts
d94df98 to
bf3f82a
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/runtime-vapor/__tests__/hydration.spec.ts (1)
11587-11653: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExercise the interop fallback → slot handoff too.
This case only verifies fallback DOM updates while
showSlotstays false. The PR’s risky path is the later transition after fallback won, so please also flipdata.showSlot = trueand assert the DOM switches to slot content cleanly here. Otherwise regressions in the Vapor/VDOM ownership handoff can still slip through.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/runtime-vapor/__tests__/hydration.spec.ts` around lines 11587 - 11653, Extend the hydration test in the `hydrate interop vapor slot fallback leading empty branch` case so it also covers the fallback-to-slot handoff: after verifying the fallback DOM update, set `data.showSlot = true` and assert the rendered output switches from the `VdomChild` fallback branch to the slot content cleanly. Use the existing `VaporChild` and `VdomChild` setup in this test to confirm there are no hydration warnings and that ownership transfers correctly when the slot becomes available.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/runtime-vapor/__tests__/hydration.spec.ts`:
- Around line 11587-11653: Extend the hydration test in the `hydrate interop
vapor slot fallback leading empty branch` case so it also covers the
fallback-to-slot handoff: after verifying the fallback DOM update, set
`data.showSlot = true` and assert the rendered output switches from the
`VdomChild` fallback branch to the slot content cleanly. Use the existing
`VaporChild` and `VdomChild` setup in this test to confirm there are no
hydration warnings and that ownership transfers correctly when the slot becomes
available.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 10102fd6-9af1-47ff-8d81-9faf5dbc9547
📒 Files selected for processing (9)
packages/runtime-vapor/__tests__/componentSlots.spec.tspackages/runtime-vapor/__tests__/dom/hydrateFragment.spec.tspackages/runtime-vapor/__tests__/hydration.spec.tspackages/runtime-vapor/src/apiCreateFor.tspackages/runtime-vapor/src/component.tspackages/runtime-vapor/src/dom/hydrateFragment.tspackages/runtime-vapor/src/dom/template.tspackages/runtime-vapor/src/fragment.tspackages/runtime-vapor/src/vdomInterop.ts
🚧 Files skipped from review as they are similar to previous changes (7)
- packages/runtime-vapor/src/apiCreateFor.ts
- packages/runtime-vapor/src/dom/template.ts
- packages/runtime-vapor/tests/dom/hydrateFragment.spec.ts
- packages/runtime-vapor/src/component.ts
- packages/runtime-vapor/src/fragment.ts
- packages/runtime-vapor/tests/componentSlots.spec.ts
- packages/runtime-vapor/src/vdomInterop.ts
Slot content and slot fallback are both evaluated before hydration knows which branch should own the SSR DOM. Empty dynamic fragments inside slot content could therefore consume fallback-owned anchors too early, or miss the runtime anchor they still need after fallback wins. Track empty slot-content anchors as pending while the slot content validity is unresolved. If content wins, reuse the matching SSR anchor. If fallback wins, insert a real runtime anchor before the slot end so later content updates still have a stable insertion point without stealing fallback DOM.
7ddf8e0 to
5542963
Compare
Forwarded slots without local fallback should only restore their own content anchor during hydration. They should not resolve inherited fallbacks themselves; the receiver slot boundary owns that decision.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/runtime-vapor/src/apiCreateFor.ts (1)
527-555: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winInsert the detached runtime anchor when fallback wins.
This callback is currently wired to
onContent, whileonFallbackis empty. That contradicts the pending-slot contract described in the PR objective: when fallback is selected, the runtime anchor must be inserted before the slot end so later updates have a stable insertion point. OtherwiseparentAnchorstays detached after fallback wins. Based on the PR objective and the pending-anchor lifecycle inpackages/runtime-vapor/src/dom/hydrateFragment.ts:110-135.🐛 Proposed fix
- // own `<!--]-->` to reuse. Keep its runtime anchor detached if - // fallback wins; if content wins, insert it at the local slot-content - // boundary below. + // own `<!--]-->` to reuse. If fallback wins, insert a runtime anchor + // before the slot end so later updates have a stable insertion point. @@ - queuePendingSlotContentAnchor({ - onContent: () => { - queuePostFlushCb(() => { - const parentNode = anchor.parentNode - if (parentNode) parentNode.insertBefore(parentAnchor, anchor) - }) - }, - onFallback: () => {}, - }) + const insertRuntimeAnchor = () => { + queuePostFlushCb(() => { + const parentNode = anchor.parentNode + if (parentNode) parentNode.insertBefore(parentAnchor, anchor) + }) + } + queuePendingSlotContentAnchor({ + onContent: () => {}, + onFallback: insertRuntimeAnchor, + })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/runtime-vapor/src/apiCreateFor.ts` around lines 527 - 555, The pending slot anchor wiring in apiCreateFor should insert the detached runtime anchor when fallback wins, not when content wins. Update the queuePendingSlotContentAnchor callbacks so the parentAnchor insertion is triggered from onFallback (with the same anchor/parentNode logic currently in onContent), and leave onContent empty or content-specific as appropriate. Use the existing anchor, parentAnchor, and queuePendingSlotContentAnchor flow to keep the runtime anchor stable for later updates.
♻️ Duplicate comments (1)
packages/runtime-vapor/__tests__/hydration.spec.ts (1)
12102-12103: 🎯 Functional Correctness | 🟡 MinorAlso reject
Hydration children mismatchin this clean-hydration case.Line 12102 only guards
Hydration node mismatch, so a regression that starts warning via the children-mismatch path would still pass.Proposed fix
expect(`Hydration node mismatch`).not.toHaveBeenWarned() + expect(`Hydration children mismatch`).not.toHaveBeenWarned() expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(`🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/runtime-vapor/__tests__/hydration.spec.ts` around lines 12102 - 12103, Update the clean-hydration test in hydration.spec.ts so it also asserts that `Hydration children mismatch` is not warned, not just `Hydration node mismatch`. Extend the existing expectations around the container snapshot in the relevant hydration test case to cover both warning paths, using the same `toHaveBeenWarned()` assertion style already used for `Hydration node mismatch`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/runtime-vapor/src/dom/hydrateFragment.ts`:
- Around line 115-122: The pending-slot resolution in hydrateFragment’s
content-valid callback is draining state.pendingAnchors for the whole parent
queue, which lets nested invalid forwarded content trigger fallback too early.
Update the logic around resolvePendingSlotContentAnchors so it only processes
anchors created by the current nested render attempt (or defers draining until
the outer slot is decided), and keep the prevPending restoration in place
without clearing earlier siblings’ queued anchors.
---
Outside diff comments:
In `@packages/runtime-vapor/src/apiCreateFor.ts`:
- Around line 527-555: The pending slot anchor wiring in apiCreateFor should
insert the detached runtime anchor when fallback wins, not when content wins.
Update the queuePendingSlotContentAnchor callbacks so the parentAnchor insertion
is triggered from onFallback (with the same anchor/parentNode logic currently in
onContent), and leave onContent empty or content-specific as appropriate. Use
the existing anchor, parentAnchor, and queuePendingSlotContentAnchor flow to
keep the runtime anchor stable for later updates.
---
Duplicate comments:
In `@packages/runtime-vapor/__tests__/hydration.spec.ts`:
- Around line 12102-12103: Update the clean-hydration test in hydration.spec.ts
so it also asserts that `Hydration children mismatch` is not warned, not just
`Hydration node mismatch`. Extend the existing expectations around the container
snapshot in the relevant hydration test case to cover both warning paths, using
the same `toHaveBeenWarned()` assertion style already used for `Hydration node
mismatch`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d7db726c-07ee-4a5c-8a43-b39bec0bddc0
📒 Files selected for processing (9)
packages/runtime-vapor/__tests__/componentSlots.spec.tspackages/runtime-vapor/__tests__/dom/hydrateFragment.spec.tspackages/runtime-vapor/__tests__/hydration.spec.tspackages/runtime-vapor/src/apiCreateFor.tspackages/runtime-vapor/src/component.tspackages/runtime-vapor/src/dom/hydrateFragment.tspackages/runtime-vapor/src/dom/template.tspackages/runtime-vapor/src/fragment.tspackages/runtime-vapor/src/vdomInterop.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/runtime-vapor/src/component.ts
- packages/runtime-vapor/src/dom/template.ts
- packages/runtime-vapor/src/vdomInterop.ts
Slot content and slot fallback are both evaluated before hydration knows which branch should own the SSR DOM. Empty dynamic fragments inside slot content could therefore consume fallback-owned anchors too early, or miss the runtime anchor they still need after fallback wins.
Track empty slot-content anchors as pending while the slot content validity is unresolved. If content wins, reuse the matching SSR anchor. If fallback wins, insert a real runtime anchor before the slot end so later content updates still have a stable insertion point without stealing fallback DOM.
Summary by CodeRabbit
New Features
Bug Fixes