-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
fix(compiler-dom): nodes with v-once shouldn't be stringified #13878
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
WalkthroughAdds early bailout in stringifyStatic to skip nodes with Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant T as Template
participant C as compileWithStringify
participant TS as stringifyStatic Transform
participant AN as analyzeNode
participant FD as findDir('once', true)
T->>C: Provide template with static content and v-once node
C->>TS: Run stringifyStatic transform
TS->>AN: analyzeNode(node)
AN->>FD: Check for v-once directive
alt v-once present
AN-->>TS: Bail out (do not include in static chunk)
TS->>C: Node rendered via normal path
else no v-once
AN-->>TS: Eligible for static stringification
TS->>C: Add to static stringified chunk
end
C-->>T: Generated render code
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks (3 passed)✅ Passed checks (3 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. ✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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: |
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: 0
🧹 Nitpick comments (2)
packages/compiler-dom/src/transforms/stringifyStatic.ts (1)
217-221
: Good early bail for v-once; also bail when v-once appears in descendants.Current check prevents stringifying the node that directly bears v-once. For robustness, also bail during the subtree walk so a parent isn’t stringified when any descendant has v-once (e.g., nested v-once inside an otherwise eligible wrapper).
Suggested change inside walk():
function walk(node: ElementNode): boolean { // Bail if this element (or any visited descendant) has v-once if (findDir(node, 'once', true)) { return bail() } const isOptionTag = node.tag === 'option' && node.ns === Namespaces.HTML // ... }Would you like me to add a focused test covering a nested v-once descendant to ensure we never stringify across it?
packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts (1)
529-537
: Nice regression test; consider asserting AST shape and add a nested v-once case.Snapshot is fine, but a small AST-level assertion will more precisely guarantee that only the span group is stringified and the v-once node remains a VNODE_CALL.
Example assertion (inline with this test):
// ensure first child (v-once) stays as VNODE_CALL and second becomes CREATE_STATIC expect(ast.cached).toMatchObject([ { type: NodeTypes.JS_CACHE_EXPRESSION, value: { type: NodeTypes.JS_ARRAY_EXPRESSION, elements: [ { codegenNode: { type: NodeTypes.VNODE_CALL } }, { type: NodeTypes.JS_CALL_EXPRESSION, callee: CREATE_STATIC } ] } } ])Optionally add a second test for a nested v-once descendant to guard against stringifying a wrapper that contains v-once.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap
is excluded by!**/*.snap
📒 Files selected for processing (2)
packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
(1 hunks)packages/compiler-dom/src/transforms/stringifyStatic.ts
(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/compiler-dom/src/transforms/stringifyStatic.ts (1)
packages/compiler-core/src/utils.ts (1)
findDir
(282-297)
⏰ 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). (3)
- GitHub Check: Redirect rules
- GitHub Check: Header rules
- GitHub Check: Pages changed
🔇 Additional comments (1)
packages/compiler-dom/src/transforms/stringifyStatic.ts (1)
20-22
: Import of findDir is correct and minimal.Brings in the exact utility needed for directive detection without expanding public surface. No further action.
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
This vnode with the
v-once
directive down here will be condensed into a "static vnode", so it causes a compile error.v-once
nodes should not be stringified. This PR is to fix it.See live demo
Summary by CodeRabbit
Bug Fixes
Tests