You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(compiler-sfc): keep defineModel type for custom elements in prod - #16452
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.
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.
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: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🔨 p3-minor-bugPriority 3: this fixes a bug, but is an edge case that only affects very specific usage.ready to mergeThe PR is ready to be merged.scope: sfc
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In production, a typed
defineModel()drops its runtimetypeunless the type includesBoolean(orFunctionwith options). For a custom element this turns off number casting:defineModel<number>()in a.ce.vuegets"5"frommodel-value="5", whiledefineProps<{ step: number }>()in the same component gets2. Real example: upmind-ui's number field is exported viadefineCustomElement, so used from HTML its model receives a string aftervite build. Playground (PROD mode).#8989 fixed the same thing for
definePropsby keeping the inferred type when compiling a custom element. I added the samectx.isCEcheck togenModelProps. Output for regular components and for dev builds doesn't change.Summary by CodeRabbit