Skip to content

Conversation

@yangxiuxiu1115
Copy link
Contributor

@yangxiuxiu1115 yangxiuxiu1115 commented Mar 20, 2025

fix #13075

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of component updates within Suspense and KeepAlive wrappers during hot module replacement.
    • Enhanced accuracy of transition handling to prevent missed or incorrect updates in nested child components.
    • Resolved edge cases where subsequent reloads could fail to reflect the latest state in the DOM.
  • Tests

    • Added test coverage for multiple reloads of a child component wrapped in Suspense and KeepAlive, verifying correct state updates across reloads.

@github-actions
Copy link

github-actions bot commented Mar 20, 2025

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB (-7 B) 38.5 kB (-2 B) 34.6 kB (-17 B)
vue.global.prod.js 159 kB (-21 B) 58.6 kB 52.2 kB (+13 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.6 kB 18.2 kB (+6 B) 16.7 kB (+14 B)
createApp 54.6 kB 21.3 kB (+6 B) 19.4 kB (-2 B)
createSSRApp 58.9 kB 23 kB (+5 B) 21 kB (+11 B)
defineCustomElement 59.6 kB 22.9 kB (+10 B) 20.9 kB (-2 B)
overall 68.7 kB (-4 B) 26.5 kB 24.1 kB (+5 B)

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 20, 2025

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@13076

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@13076

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@13076

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@13076

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@13076

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@13076

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@13076

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@13076

@vue/shared

npm i https://pkg.pr.new/@vue/shared@13076

vue

npm i https://pkg.pr.new/vue@13076

@vue/compat

npm i https://pkg.pr.new/@vue/compat@13076

commit: d603c01

@yangxiuxiu1115
Copy link
Contributor Author

https://github.com/vuejs/core/blob/main/packages/runtime-core/src/vnode.ts#L391-L401
Perhaps there are other uses with the same problem

@edison1105
Copy link
Member

image
Only these four places are incorrect. n1 should be the old one and the n2 should be the new one.

@edison1105 edison1105 added need test The PR has missing test cases. scope: suspense 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Mar 20, 2025
@edison1105 edison1105 changed the title fix(suspence): fix newBranch shapeFlag not reset under hmr fix(Suspence): handle Suspense + KeepAlive HMR updating edge case Mar 21, 2025
@edison1105 edison1105 added ready to merge The PR is ready to be merged. and removed need test The PR has missing test cases. labels Mar 21, 2025
@coderabbitai
Copy link

coderabbitai bot commented Sep 2, 2025

Walkthrough

Adds an HMR regression test for a child component wrapped in Suspense and KeepAlive. Adjusts isSameVNodeType argument order in Suspense and BaseTransition to modify vnode type comparison paths. No public API changes.

Changes

Cohort / File(s) Summary
HMR Tests
packages/runtime-core/__tests__/hmr.spec.ts
Adds test "multi reload child wrapped in Suspense + KeepAlive" verifying DOM updates across successive HMR reloads for a child inside KeepAlive > Suspense.
Suspense vnode comparison
packages/runtime-core/src/components/Suspense.ts
Swaps argument order in three isSameVNodeType comparisons within patchSuspense for pending/active branch checks.
BaseTransition vnode comparison
packages/runtime-core/src/components/BaseTransition.ts
Swaps argument order in isSameVNodeType when detecting innerChild vs oldInnerChild differences.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Dev as Dev Server (HMR)
  participant App as App (KeepAlive > Suspense)
  participant Child as Child Component
  participant Renderer as Renderer

  Dev->>App: HMR update (Child v1)
  App->>Renderer: Mount Suspense + KeepAlive with Child
  Renderer-->>App: Initial DOM shows count=0

  Dev->>App: HMR reload (Child v2)
  App->>Renderer: Patch Child under Suspense/KeepAlive
  note over Renderer: Compare vnode types (updated checks)
  Renderer-->>App: DOM updates count=1

  Dev->>App: HMR reload (Child v3)
  App->>Renderer: Patch Child again
  Renderer-->>App: DOM updates count=2
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix HMR not updating after second modification with KeepAlive + Suspense (#13075)
Add regression coverage for HMR with KeepAlive + Suspense (#13075)

Suggested labels

scope: hmr

Suggested reviewers

  • Doctor-wu
  • LittleSound
  • KazariEX
  • baiwusanyu-c

Poem

I hop through code where branches rest,
In Suspense burrows, KeepAlive nest.
Two warm reloads, a carrot’s cheer—
Count hops to one, then two, so clear!
Vnodes greet, their types aligned,
HMR hums—no bug this time. 🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@edison1105
Copy link
Member

/ecosystem-ci run

Copy link

@coderabbitai coderabbitai bot left a 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 (3)
packages/runtime-core/src/components/BaseTransition.ts (1)

203-210: Correct arg order for isSameVNodeType (old, new) — fixes HMR with KeepAlive+Transition

Swapping to isSameVNodeType(oldInnerChild, innerChild) aligns with the function’s HMR guard which expects (oldVNode, newVNode). This prevents stale instances from being “kept alive” across HMR. Looks good.

Consider an inline comment to prevent future regressions:

-      if (
+      // HMR note: pass (old, new) to isSameVNodeType
+      if (
         oldInnerChild &&
         oldInnerChild.type !== Comment &&
         !isSameVNodeType(oldInnerChild, innerChild) &&
         recursiveGetSubtree(instance).type !== Comment
       ) {
packages/runtime-core/src/components/Suspense.ts (1)

236-244: All three comparisons now pass (old, new) into isSameVNodeType — matches HMR contract

  • pending vs new branch
  • active vs new branch (both pending and non-pending paths)

These swaps ensure the HMR dirty-instance check runs and the keep-alive flags are adjusted on the correct sides. Nice.

Add a short comment once to document the non-commutative intent:

-    if (isSameVNodeType(pendingBranch, newBranch)) {
+    // HMR note: isSameVNodeType expects (old, new)
+    if (isSameVNodeType(pendingBranch, newBranch)) {

Also applies to: 324-339, 358-372

packages/runtime-core/__tests__/hmr.spec.ts (1)

898-949: Good regression coverage for multi-reload with KeepAlive outside Suspense

The test reproduces the “second reload doesn’t update” edge case and validates both successive updates. LGTM.

For tighter determinism (no macro-task dependency), consider await nextTick() after each reload (this test is fully sync aside from HMR scheduling):

-    await timeout()
+    await nextTick()
...
-    await timeout()
+    await nextTick()

Optionally DRY the reload steps:

+    const reloadTo = (n: number) =>
+      reload(id, {
+        __hmrId: id,
+        setup() { return { count: ref(n) } },
+        render: compileToFunction(`<div>{{ count }}</div>`),
+      })
...
-    reload(id, { ...count: ref(1)... }); await nextTick()
+    reloadTo(1); await nextTick()
...
-    reload(id, { ...count: ref(2)... }); await nextTick()
+    reloadTo(2); await nextTick()
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 99d54b2 and d603c01.

📒 Files selected for processing (3)
  • packages/runtime-core/__tests__/hmr.spec.ts (1 hunks)
  • packages/runtime-core/src/components/BaseTransition.ts (1 hunks)
  • packages/runtime-core/src/components/Suspense.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/runtime-core/src/components/BaseTransition.ts (1)
packages/runtime-core/src/vnode.ts (1)
  • isSameVNodeType (391-404)
packages/runtime-core/src/components/Suspense.ts (1)
packages/runtime-core/src/vnode.ts (1)
  • isSameVNodeType (391-404)
packages/runtime-core/__tests__/hmr.spec.ts (2)
packages/runtime-test/src/serialize.ts (1)
  • serializeInner (22-33)
packages/vue/__tests__/e2e/e2eUtils.ts (1)
  • timeout (16-17)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test / unit-test-windows
🔇 Additional comments (2)
packages/runtime-core/src/components/BaseTransition.ts (1)

389-397: Keep argument order as is: in this branch leavingVNode is always an element VNode (its shapeFlag doesn’t include COMPONENT), so the HMR check inside isSameVNodeType (guarded by n2.shapeFlag & ShapeFlags.COMPONENT) never runs here—no swap needed.

packages/runtime-core/src/components/Suspense.ts (1)

235-243: Update sanity sweep to check for 5 call sites, not 4
There are three in Suspense.ts (lines 238, 324, 358) and two in BaseTransition.ts (lines 207, 393).

Likely an incorrect or invalid review comment.

@vue-bot
Copy link
Contributor

vue-bot commented Sep 2, 2025

📝 Ran ecosystem CI: Open

suite result latest scheduled
language-tools success success
primevue success success
pinia success success
nuxt success success
router success success
test-utils success success
quasar success success
vite-plugin-vue success success
radix-vue success success
vue-i18n success success
vitepress success success
vueuse success success
vue-simple-compiler success success
vue-macros failure failure
vuetify success success
vant success failure

@edison1105 edison1105 merged commit 5d75a17 into vuejs:main Sep 2, 2025
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. ready to merge The PR is ready to be merged. scope: suspense

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HMR fails when using keep-alive and Suspense.

3 participants