Skip to content

fix(runtime-vapor): defer slot content anchors during hydration - #15027

Merged
edison1105 merged 6 commits into
minorfrom
edison/fix/slotFragmentHydrate
Jul 1, 2026
Merged

edison1105 merged 6 commits into
minorfrom
edison/fix/slotFragmentHydrate

Conversation

@edison1105

@edison1105 edison1105 commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

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

    • Improved hydration handling for slots and conditional content, especially in nested and forwarded-slot scenarios.
  • Bug Fixes

    • Fixed several edge cases where empty or fallback slot content could reuse the wrong anchor or leave DOM nodes in an inconsistent state.
    • Improved recovery when client-rendered slot content differs from SSR content, reducing hydration mismatches.
    • Updated interop behavior so slot fallback content hydrates more reliably across combined rendering paths.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ba238c78-4ecc-4208-994f-ec675476f0aa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch edison/fix/slotFragmentHydrate

Comment @coderabbitai help to get the list of available commands.

@edison1105 edison1105 added the scope: vapor related to vapor mode label Jun 29, 2026
@github-actions

github-actions Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
compiler-dom.global.prod.js 86.7 kB 30.3 kB 26.6 kB
runtime-dom.global.prod.js 113 kB 42.7 kB 38.3 kB
vue.global.prod.js 173 kB 62.5 kB 55.7 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 51.6 kB 20.2 kB 18.4 kB
createApp 60.7 kB 23.5 kB 21.4 kB
createApp + vaporInteropPlugin 115 kB (+243 B) 41.4 kB (+110 B) 37.3 kB (+168 B)
createVaporApp 28.5 kB 11 kB 10.2 kB
createSSRApp 65.2 kB 25.3 kB 22.9 kB
createVaporSSRApp 33.6 kB 12.9 kB 11.8 kB
defineCustomElement 67.3 kB 25.5 kB 23.1 kB
defineVaporCustomElement 44.2 kB 16.1 kB 14.8 kB
overall 76 kB 28.9 kB 26.2 kB

@pkg-pr-new

pkg-pr-new Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@15027
npm i https://pkg.pr.new/@vue/compiler-core@15027
yarn add https://pkg.pr.new/@vue/compiler-core@15027.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@15027
npm i https://pkg.pr.new/@vue/compiler-dom@15027
yarn add https://pkg.pr.new/@vue/compiler-dom@15027.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@15027
npm i https://pkg.pr.new/@vue/compiler-sfc@15027
yarn add https://pkg.pr.new/@vue/compiler-sfc@15027.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@15027
npm i https://pkg.pr.new/@vue/compiler-ssr@15027
yarn add https://pkg.pr.new/@vue/compiler-ssr@15027.tgz

@vue/compiler-vapor

pnpm add https://pkg.pr.new/@vue/compiler-vapor@15027
npm i https://pkg.pr.new/@vue/compiler-vapor@15027
yarn add https://pkg.pr.new/@vue/compiler-vapor@15027.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@15027
npm i https://pkg.pr.new/@vue/reactivity@15027
yarn add https://pkg.pr.new/@vue/reactivity@15027.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@15027
npm i https://pkg.pr.new/@vue/runtime-core@15027
yarn add https://pkg.pr.new/@vue/runtime-core@15027.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@15027
npm i https://pkg.pr.new/@vue/runtime-dom@15027
yarn add https://pkg.pr.new/@vue/runtime-dom@15027.tgz

@vue/runtime-vapor

pnpm add https://pkg.pr.new/@vue/runtime-vapor@15027
npm i https://pkg.pr.new/@vue/runtime-vapor@15027
yarn add https://pkg.pr.new/@vue/runtime-vapor@15027.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@15027
npm i https://pkg.pr.new/@vue/server-renderer@15027
yarn add https://pkg.pr.new/@vue/server-renderer@15027.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@15027
npm i https://pkg.pr.new/@vue/shared@15027
yarn add https://pkg.pr.new/@vue/shared@15027.tgz

vue

pnpm add https://pkg.pr.new/vue@15027
npm i https://pkg.pr.new/vue@15027
yarn add https://pkg.pr.new/vue@15027.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@15027
npm i https://pkg.pr.new/@vue/compat@15027
yarn add https://pkg.pr.new/@vue/compat@15027.tgz

commit: 7dd27cc

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
packages/runtime-vapor/__tests__/componentSlots.spec.ts (2)

865-880: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Pin 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 win

Assert 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 before finish(true) runs. A restore bug in withHydratingSlotBoundary() 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

📥 Commits

Reviewing files that changed from the base of the PR and between 704716f and d94df98.

📒 Files selected for processing (9)
  • packages/runtime-vapor/__tests__/componentSlots.spec.ts
  • packages/runtime-vapor/__tests__/dom/hydrateFragment.spec.ts
  • packages/runtime-vapor/__tests__/hydration.spec.ts
  • packages/runtime-vapor/src/apiCreateFor.ts
  • packages/runtime-vapor/src/component.ts
  • packages/runtime-vapor/src/dom/hydrateFragment.ts
  • packages/runtime-vapor/src/dom/template.ts
  • packages/runtime-vapor/src/fragment.ts
  • packages/runtime-vapor/src/vdomInterop.ts

@edison1105
edison1105 force-pushed the edison/fix/slotFragmentHydrate branch from d94df98 to bf3f82a Compare June 29, 2026 09:33

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/runtime-vapor/__tests__/hydration.spec.ts (1)

11587-11653: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Exercise the interop fallback → slot handoff too.

This case only verifies fallback DOM updates while showSlot stays false. The PR’s risky path is the later transition after fallback won, so please also flip data.showSlot = true and 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

📥 Commits

Reviewing files that changed from the base of the PR and between d94df98 and bf3f82a.

📒 Files selected for processing (9)
  • packages/runtime-vapor/__tests__/componentSlots.spec.ts
  • packages/runtime-vapor/__tests__/dom/hydrateFragment.spec.ts
  • packages/runtime-vapor/__tests__/hydration.spec.ts
  • packages/runtime-vapor/src/apiCreateFor.ts
  • packages/runtime-vapor/src/component.ts
  • packages/runtime-vapor/src/dom/hydrateFragment.ts
  • packages/runtime-vapor/src/dom/template.ts
  • packages/runtime-vapor/src/fragment.ts
  • packages/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.
@edison1105
edison1105 force-pushed the edison/fix/slotFragmentHydrate branch from 7ddf8e0 to 5542963 Compare June 30, 2026 03:18
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Insert the detached runtime anchor when fallback wins.

This callback is currently wired to onContent, while onFallback is 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. Otherwise parentAnchor stays detached after fallback wins. Based on the PR objective and the pending-anchor lifecycle in packages/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 | 🟡 Minor

Also reject Hydration children mismatch in 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

📥 Commits

Reviewing files that changed from the base of the PR and between bf3f82a and fbe1d0f.

📒 Files selected for processing (9)
  • packages/runtime-vapor/__tests__/componentSlots.spec.ts
  • packages/runtime-vapor/__tests__/dom/hydrateFragment.spec.ts
  • packages/runtime-vapor/__tests__/hydration.spec.ts
  • packages/runtime-vapor/src/apiCreateFor.ts
  • packages/runtime-vapor/src/component.ts
  • packages/runtime-vapor/src/dom/hydrateFragment.ts
  • packages/runtime-vapor/src/dom/template.ts
  • packages/runtime-vapor/src/fragment.ts
  • packages/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

@edison1105
edison1105 marked this pull request as ready for review July 1, 2026 01:21
@edison1105
edison1105 merged commit 4af4bf9 into minor Jul 1, 2026
14 checks passed
@edison1105
edison1105 deleted the edison/fix/slotFragmentHydrate branch July 1, 2026 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: vapor related to vapor mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant