Skip to content

perf(vapor): reduce template ref codegen size#14868

Merged
edison1105 merged 5 commits into
minorfrom
edison/template-ref-codegen-7cf03b6
May 21, 2026
Merged

perf(vapor): reduce template ref codegen size#14868
edison1105 merged 5 commits into
minorfrom
edison/template-ref-codegen-7cf03b6

Conversation

@edison1105
Copy link
Copy Markdown
Member

@edison1105 edison1105 commented May 21, 2026

Summary by CodeRabbit

  • New Features

    • Added setStaticTemplateRef and setTemplateRefBinding runtime APIs for enhanced template-ref management and binding.
  • Tests

    • Expanded test coverage for template-ref scenarios, including static refs, dynamic binding, slots, and async components.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 44baf1b3-a8b7-46d6-9456-464e7340cd13

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch edison/template-ref-codegen-7cf03b6

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 21, 2026

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@14868
npm i https://pkg.pr.new/@vue/compiler-core@14868
yarn add https://pkg.pr.new/@vue/compiler-core@14868.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@14868
npm i https://pkg.pr.new/@vue/compiler-dom@14868
yarn add https://pkg.pr.new/@vue/compiler-dom@14868.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@14868
npm i https://pkg.pr.new/@vue/compiler-sfc@14868
yarn add https://pkg.pr.new/@vue/compiler-sfc@14868.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@14868
npm i https://pkg.pr.new/@vue/compiler-ssr@14868
yarn add https://pkg.pr.new/@vue/compiler-ssr@14868.tgz

@vue/compiler-vapor

pnpm add https://pkg.pr.new/@vue/compiler-vapor@14868
npm i https://pkg.pr.new/@vue/compiler-vapor@14868
yarn add https://pkg.pr.new/@vue/compiler-vapor@14868.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@14868
npm i https://pkg.pr.new/@vue/reactivity@14868
yarn add https://pkg.pr.new/@vue/reactivity@14868.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@14868
npm i https://pkg.pr.new/@vue/runtime-core@14868
yarn add https://pkg.pr.new/@vue/runtime-core@14868.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@14868
npm i https://pkg.pr.new/@vue/runtime-dom@14868
yarn add https://pkg.pr.new/@vue/runtime-dom@14868.tgz

@vue/runtime-vapor

pnpm add https://pkg.pr.new/@vue/runtime-vapor@14868
npm i https://pkg.pr.new/@vue/runtime-vapor@14868
yarn add https://pkg.pr.new/@vue/runtime-vapor@14868.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@14868
npm i https://pkg.pr.new/@vue/server-renderer@14868
yarn add https://pkg.pr.new/@vue/server-renderer@14868.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@14868
npm i https://pkg.pr.new/@vue/shared@14868
yarn add https://pkg.pr.new/@vue/shared@14868.tgz

vue

pnpm add https://pkg.pr.new/vue@14868
npm i https://pkg.pr.new/vue@14868
yarn add https://pkg.pr.new/vue@14868.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@14868
npm i https://pkg.pr.new/@vue/compat@14868
yarn add https://pkg.pr.new/@vue/compat@14868.tgz

commit: e66c85d

@edison1105 edison1105 added the scope: vapor related to vapor mode label May 21, 2026
Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
packages/runtime-vapor/__tests__/dom/templateRef.spec.ts (1)

700-735: ⚡ Quick win

Cover 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 refName changes after mount. Please flip refName here 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

📥 Commits

Reviewing files that changed from the base of the PR and between b3d35ca and 628fab3.

⛔ Files ignored due to path filters (1)
  • packages/compiler-vapor/__tests__/transforms/__snapshots__/transformTemplateRef.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (8)
  • packages/compiler-vapor/__tests__/transforms/transformTemplateRef.spec.ts
  • packages/compiler-vapor/src/generate.ts
  • packages/compiler-vapor/src/generators/component.ts
  • packages/compiler-vapor/src/generators/operation.ts
  • packages/compiler-vapor/src/generators/templateRef.ts
  • packages/runtime-vapor/__tests__/dom/templateRef.spec.ts
  • packages/runtime-vapor/src/apiTemplateRef.ts
  • packages/runtime-vapor/src/index.ts

Copy link
Copy Markdown

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

📥 Commits

Reviewing files that changed from the base of the PR and between 628fab3 and 9b7cd9b.

⛔ Files ignored due to path filters (2)
  • packages/compiler-vapor/__tests__/__snapshots__/staticTemplate.spec.ts.snap is excluded by !**/*.snap
  • packages/compiler-vapor/__tests__/transforms/__snapshots__/transformTemplateRef.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (5)
  • packages/compiler-vapor/__tests__/transforms/transformTemplateRef.spec.ts
  • packages/compiler-vapor/src/generate.ts
  • packages/compiler-vapor/src/generators/templateRef.ts
  • packages/runtime-vapor/__tests__/dom/templateRef.spec.ts
  • packages/runtime-vapor/src/apiTemplateRef.ts

Comment thread packages/compiler-vapor/src/generators/templateRef.ts Outdated
Comment thread packages/runtime-vapor/src/apiTemplateRef.ts
@edison1105 edison1105 merged commit 6bb7d3d into minor May 21, 2026
16 of 17 checks passed
@edison1105 edison1105 deleted the edison/template-ref-codegen-7cf03b6 branch May 21, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: vapor related to vapor mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant