Skip to content

Conversation

edison1105
Copy link
Member

@edison1105 edison1105 commented May 2, 2023

close #6913

Summary by CodeRabbit

  • Bug Fixes
    • Resolved edge cases where programmatically created virtual nodes could be incorrectly tracked, preventing unexpected rendering behaviors.
  • Performance
    • Improved render tracking during virtual node creation to reduce unnecessary work and enhance runtime stability.
  • Documentation
    • Added clarifying comments to aid understanding of render tracking behavior related to virtual node creation.

@edison1105 edison1105 changed the title fix(runtime-core): disabled tracking block in h function fix(runtime-core): disable tracking block in h function May 2, 2023
@edison1105
Copy link
Member Author

/ecosystem-ci run

@vue-bot
Copy link
Contributor

vue-bot commented May 2, 2023

📝 Ran ecosystem CI: Open

suite result
naive-ui ❌ failure
nuxt ❌ failure
pinia ✅ success
router ✅ success
test-utils ✅ success
vant ✅ success
vite-plugin-vue ✅ success
vitepress ✅ success
vue-macros ✅ success
vuetify ✅ success
vueuse ✅ success

@github-actions
Copy link

github-actions bot commented Oct 20, 2023

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB (+47 B) 38.4 kB (+20 B) 34.6 kB (+10 B)
vue.global.prod.js 159 kB (+47 B) 58.6 kB (+19 B) 52.2 kB (-12 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.5 kB 18.2 kB 16.7 kB
createApp 54.5 kB 21.2 kB 19.4 kB
createSSRApp 58.7 kB 22.9 kB 20.9 kB
defineCustomElement 59.5 kB 22.8 kB 20.8 kB
overall 68.6 kB (+47 B) 26.4 kB (+20 B) 24 kB (+17 B)

Copy link

pkg-pr-new bot commented Oct 16, 2024

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: 124e158

@edison1105 edison1105 added ready to merge The PR is ready to be merged. 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. labels Oct 16, 2024
Copy link

coderabbitai bot commented Sep 1, 2025

Walkthrough

Introduced block tracking control in h() by wrapping createVNode with setBlockTracking(-1/1) to suspend and restore block tracking during vnode creation. Replaced direct createVNode calls with the wrapper across all h() code paths. Added a comment referencing issue #6913.

Changes

Cohort / File(s) Summary
h() block tracking wrapper
packages/runtime-core/src/h.ts
Import setBlockTracking; add doCreateVNode wrapper calling setBlockTracking(-1) before and setBlockTracking(1) after createVNode; replace all internal createVNode invocations in h() with doCreateVNode; add reference comment to #6913.

Sequence Diagram(s)

sequenceDiagram
  actor C as Caller
  participant H as h()
  participant W as doCreateVNode
  participant BT as setBlockTracking
  participant CV as createVNode

  C->>H: h(type, props?, children?)
  H->>W: doCreateVNode(type, props, children)
  W->>BT: setBlockTracking(-1)
  W->>CV: createVNode(type, props, children)
  CV-->>W: vnode
  W->>BT: setBlockTracking(1)
  W-->>H: vnode
  H-->>C: vnode
  note over W,BT: Temporarily disable block tracking during vnode creation (per #6913)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Prevent unintended rerender/disappearance when using computed with h() by adjusting block tracking during vnode creation (#6913)

Assessment against linked issues: Out-of-scope changes

(None)

Suggested labels

:hammer: p3-minor-bug

Suggested reviewers

  • Doctor-wu

Poem

I paused the blocks, then hopped along,
A tiny tweak to make views strong.
With -1, +1, I flip and glide,
No arrows vanish, none misapplied.
Carrots compiled, the render’s right—
A happy bunny, frames in sight! 🥕✨

✨ 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.

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: 1

🧹 Nitpick comments (1)
packages/runtime-core/src/h.ts (1)

205-206: Optional: hoist helper to module scope to avoid per-call allocation.

Defining doCreateVNode outside h() avoids creating a new closure on every call. Impact is minor since h() isn’t used by compiled templates, but it’s a cheap win.

If you prefer, lift the helper above the h() overloads and keep the same signature.

📜 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 24fccb4 and 124e158.

📒 Files selected for processing (1)
  • packages/runtime-core/src/h.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/runtime-core/src/h.ts (2)
packages/runtime-core/src/index.ts (3)
  • setBlockTracking (368-368)
  • createVNode (111-111)
  • isVNode (111-111)
packages/shared/src/general.ts (2)
  • isObject (53-54)
  • isArray (39-39)
⏰ 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). (4)
  • GitHub Check: Redirect rules
  • GitHub Check: Header rules
  • GitHub Check: Pages changed
  • GitHub Check: test / e2e-test
🔇 Additional comments (2)
packages/runtime-core/src/h.ts (2)

10-11: Import looks correct.

Pulling in setBlockTracking from './vnode' is appropriate for this usage.


218-218: Consistent usage of the helper across all code paths.

All createVNode calls are replaced with doCreateVNode, ensuring tracking is disabled consistently. LGTM.

Please add/confirm a regression test covering the computed + h() repro from issue #6913 (including nested h(), array children, and slot functions) to ensure no dynamicChildren/block tracking regressions.

Also applies to: 221-221, 224-224, 232-232

Comment on lines +205 to +212
// #6913 disable tracking block in h function
const doCreateVNode = (type: any, props?: any, children?: any) => {
setBlockTracking(-1)
const vnode = createVNode(type, props, children)
setBlockTracking(1)
return vnode
}

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Prevent leaked block-tracking state on exceptions (use try/finally).

If createVNode throws, setBlockTracking(1) won't run and tracking stays disabled globally, leading to hard-to-debug rendering issues.

Apply this diff to guarantee restoration and add an explicit return type and clearer comment:

-  // #6913 disable tracking block in h function
-  const doCreateVNode = (type: any, props?: any, children?: any) => {
-    setBlockTracking(-1)
-    const vnode = createVNode(type, props, children)
-    setBlockTracking(1)
-    return vnode
-  }
+  // #6913: disable block tracking inside h() so manually created VNodes
+  // are not collected into the current block
+  const doCreateVNode = (type: any, props?: any, children?: any): VNode => {
+    setBlockTracking(-1)
+    try {
+      return createVNode(type, props, children)
+    } finally {
+      setBlockTracking(1)
+    }
+  }
🤖 Prompt for AI Agents
In packages/runtime-core/src/h.ts around lines 205 to 212, the doCreateVNode
function disables block tracking then calls createVNode but restores tracking
with a hard-coded setBlockTracking(1) which will be skipped if createVNode
throws; wrap the createVNode call in a try/finally so setBlockTracking is always
executed and restore the previous tracking state (capture the result of
setBlockTracking before disabling and call it in finally rather than hard-coding
1), add an explicit return type for doCreateVNode (e.g., VNode or appropriate
type) and replace the comment with a clearer note that block tracking is
temporarily disabled and always restored even on errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. ready to merge The PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

werid render when using computed and h function
2 participants