Skip to content

fix(compiler-sfc): keep defineModel type for custom elements in prod - #16452

Merged
edison1105 merged 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/define-model-ce-prod-type
Dec 2, 2026
Merged

edison1105 merged 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/define-model-ce-prod-type

Conversation

@ValentinYoushkevich

@ValentinYoushkevich ValentinYoushkevich commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

In production, a typed defineModel() drops its runtime type unless the type includes Boolean (or Function with options). For a custom element this turns off number casting: defineModel<number>() in a .ce.vue gets "5" from model-value="5", while defineProps<{ step: number }>() in the same component gets 2. Real example: upmind-ui's number field is exported via defineCustomElement, so used from HTML its model receives a string after vite build. Playground (PROD mode).

#8989 fixed the same thing for defineProps by keeping the inferred type when compiling a custom element. I added the same ctx.isCE check to genModelProps. Output for regular components and for dev builds doesn't change.

Summary by CodeRabbit

  • Bug Fixes
    • Production builds of custom elements now preserve inferred types for model props, including numeric props with default values. This applies to both the default model and named models, keeping their prop options consistent with the declared model types.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Production compilation now retains inferred runtime types for model props when compiling custom elements. A compiler test checks numeric model props and the default value of a named model.

Changes: DefineModel custom-element compilation

Layer / File(s) Summary
Retain inferred model prop types
packages/compiler-sfc/src/script/defineModel.ts, packages/compiler-sfc/__tests__/compileScript/defineModel.spec.ts
Production compilation retains inferred runtime types for custom-element model props. The test checks numeric types and a named model’s default value.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: yyx990803

Merge Risk: Minimal · up to a2119 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change: defineModel type retention for custom elements in production builds. The raw summary shows genModelProps now keeps inferred runtime types when ctx.isCE is set in production…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: defineModel type retention for custom elements in production builds. The raw summary shows genModelProps now keeps inferred runtime types when ctx.isCE is set in production, and the added test checks prod custom-element output. The title matches the main change and is specific.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 759e355d-0678-4cb9-ad89-8c3d1e76149c
Commits

Reviewing files that changed from the base of the PR and between d690dee and a2119cd.

Files ignored due to path filters: 1

  • packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineModel.spec.ts.snap is excluded by !**/*.snap
Files selected for processing: 2

  • packages/compiler-sfc/__tests__/compileScript/defineModel.spec.ts
  • packages/compiler-sfc/src/script/defineModel.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@16452
npm i https://pkg.pr.new/@vue/compiler-core@16452
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@16452
npm i https://pkg.pr.new/@vue/compiler-dom@16452
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@16452
npm i https://pkg.pr.new/@vue/compiler-sfc@16452
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@16452
npm i https://pkg.pr.new/@vue/compiler-ssr@16452
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@16452
npm i https://pkg.pr.new/@vue/reactivity@16452
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@16452
npm i https://pkg.pr.new/@vue/runtime-core@16452
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@16452
npm i https://pkg.pr.new/@vue/runtime-dom@16452
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@16452
npm i https://pkg.pr.new/@vue/server-renderer@16452
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@16452
npm i https://pkg.pr.new/@vue/shared@16452
yarn add https://pkg.pr.new/@vue/[email protected]

vue

pnpm add https://pkg.pr.new/vue@16452
npm i https://pkg.pr.new/vue@16452
yarn add https://pkg.pr.new/[email protected]

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@16452
npm i https://pkg.pr.new/@vue/compat@16452
yarn add https://pkg.pr.new/@vue/[email protected]

commit: a2119cd

@github-actions

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 115 kB 43.1 kB 38.7 kB
vue.global.prod.js 174 kB 63.5 kB 56.4 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 52.9 kB 20.4 kB 18.7 kB
createApp 61.1 kB 23.5 kB 21.5 kB
createSSRApp 65.9 kB 25.5 kB 23.3 kB
defineCustomElement 67.4 kB 25.4 kB 23.2 kB
overall 77.2 kB 29.3 kB 26.6 kB

@edison1105 edison1105 added ready to merge The PR is ready to be merged. scope: sfc 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Nov 26, 2026
@edison1105
edison1105 merged commit 1fb9abe into vuejs:main Dec 2, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. ready to merge The PR is ready to be merged. scope: sfc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants