-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
fix(runtime-core): disable tracking block in h function #8213
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?
Conversation
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
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: |
WalkthroughIntroduced 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
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)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changes(None) Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 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.
📒 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
// #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 | ||
} | ||
|
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.
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.
close #6913
Summary by CodeRabbit