perf(vapor): reduce template ref codegen size#14868
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/compiler-vapor
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/runtime-vapor
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/runtime-vapor/__tests__/dom/templateRef.spec.ts (1)
700-735: ⚡ Quick winCover the slot-binding update path, not just initial mount.
This case proves the owner setter is threaded correctly on mount, but the regression-prone part of this change is rebinding when
refNamechanges after mount. Please fliprefNamehere and assert the old parent ref is cleared while the new one is assigned.🤖 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__/dom/templateRef.spec.ts` around lines 700 - 735, Update the test to exercise the rebinding path by changing refName.value after the initial render and re-rendering, then assert the old ref is cleared and the new ref is assigned: after the existing render() and initial expectations, set refName.value = 'bar' (or another distinct name), call render() again (to trigger the update), then assert that the original parent ref (foo -> r) has been cleared (r.value is undefined or childInstance.refs.foo is undefined) and that the new binding has been created on the new owner (check the appropriate refs map or new ref variable). Use the same symbols from this diff (refName, setTemplateRefBinding, createTemplateRefSetter, render, r, childInstance) to locate and implement the assertions.
🤖 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__/dom/templateRef.spec.ts`:
- Around line 700-735: Update the test to exercise the rebinding path by
changing refName.value after the initial render and re-rendering, then assert
the old ref is cleared and the new ref is assigned: after the existing render()
and initial expectations, set refName.value = 'bar' (or another distinct name),
call render() again (to trigger the update), then assert that the original
parent ref (foo -> r) has been cleared (r.value is undefined or
childInstance.refs.foo is undefined) and that the new binding has been created
on the new owner (check the appropriate refs map or new ref variable). Use the
same symbols from this diff (refName, setTemplateRefBinding,
createTemplateRefSetter, render, r, childInstance) to locate and implement the
assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 798eca5a-b0c6-48ca-b3c3-010f71230b0b
⛔ Files ignored due to path filters (1)
packages/compiler-vapor/__tests__/transforms/__snapshots__/transformTemplateRef.spec.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (8)
packages/compiler-vapor/__tests__/transforms/transformTemplateRef.spec.tspackages/compiler-vapor/src/generate.tspackages/compiler-vapor/src/generators/component.tspackages/compiler-vapor/src/generators/operation.tspackages/compiler-vapor/src/generators/templateRef.tspackages/runtime-vapor/__tests__/dom/templateRef.spec.tspackages/runtime-vapor/src/apiTemplateRef.tspackages/runtime-vapor/src/index.ts
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/compiler-vapor/src/generators/templateRef.ts`:
- Around line 72-78: The getter wrapper logic in shouldWrapGetterBody fails to
parenthesize SequenceExpression ASTs, causing genSetTemplateRefBinding to emit
"() => _ctx.foo, _ctx.bar" which parses incorrectly; update shouldWrapGetterBody
to detect SequenceExpression as well (i.e.,
getExpressionReplacement(value).ast.type === 'SequenceExpression' or
ObjectExpression) so genSetTemplateRefBinding will wrap the getter body in
parentheses for comma/sequence expressions; ensure you reference the same ast
retrieval used now (context.getExpressionReplacement(value).ast) when adding the
additional type check.
In `@packages/runtime-vapor/src/apiTemplateRef.ts`:
- Around line 120-127: The onUpdated closure is appended unconditionally causing
duplicate callbacks; mirror createTemplateRefSetter()'s behavior by
deduplicating/removing any previously-registered fragment callback before
pushing the new one. Locate the fragment via getTemplateRefUpdateFragment(el)
and either keep the callback as a stable named function (so you can check
frag.onUpdated.includes(cb) or call frag.onUpdated = frag.onUpdated.filter(fn =>
fn !== prevCb) before push), or remove the prior registration recorded on the
element/instance and then push the new callback that calls isVaporComponent(el)
check and setRef(instance, el, ref, oldRef, refFor, refKey).
🪄 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: 267b2d4f-a3f7-4c0b-bc2a-ba118f4b8ed8
⛔ Files ignored due to path filters (2)
packages/compiler-vapor/__tests__/__snapshots__/staticTemplate.spec.ts.snapis excluded by!**/*.snappackages/compiler-vapor/__tests__/transforms/__snapshots__/transformTemplateRef.spec.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (5)
packages/compiler-vapor/__tests__/transforms/transformTemplateRef.spec.tspackages/compiler-vapor/src/generate.tspackages/compiler-vapor/src/generators/templateRef.tspackages/runtime-vapor/__tests__/dom/templateRef.spec.tspackages/runtime-vapor/src/apiTemplateRef.ts
Summary by CodeRabbit
New Features
setStaticTemplateRefandsetTemplateRefBindingruntime APIs for enhanced template-ref management and binding.Tests