-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
fix(runtime-core): guard prop validator against invalid types to avoid instanceof crash (fix #14041) #14042
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
WalkthroughThe prop validation logic was changed to guard instanceof checks by verifying the prop type is a function before using instanceof; null-type handling was moved to callers and validateProp now explicitly handles Changes
Sequence Diagram(s)sequenceDiagram
participant C as Component / caller
participant V as validateProp
participant A as assertType
C->>V: validateProp(propValue, propOptions)
V->>V: loop declared types (including null)
alt type === null
V-->>C: mark valid only if value === null
else type defined
V->>A: assertType(value, type)
A->>A: isFunction(type)?
alt true
A->>A: check instanceof / primitive checks
A-->>V: return validity + expectedType
else false
A-->>V: skip instanceof, perform primitive checks only
end
end
V-->>C: final validation result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested labels
Poem
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)packages/runtime-core/src/componentProps.ts (1)
⏰ 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)
🔇 Additional comments (1)
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 |
| // for primitive wrapper objects | ||
| if (!valid && t === 'object') { | ||
| valid = value instanceof (type as PropConstructor) | ||
| // Guard against invalid prop type definitions (e.g. 'object', {}, etc.) |
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.
The proper fix should be to avoid calling assertType if type is a null-lish value (at line:700)
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.
The proper fix should be to avoid calling
assertTypeif type is a null-lish value (at line:700)
Sorry, I misunderstood the meaning. I'll fix it right now
Move null type validation logic to the caller side (validateProp) before calling assertType, instead of handling it inside assertType. This provides: - Better separation of concerns - Avoids unnecessary function calls for null types - Clearer code flow and intent - Simplifies assertType and getType implementations All existing tests pass, including support for `type: [Function,null]`.
Problem Description
<test-comp :modelValue="{ type: 'js' }" />, the app throws "Right-hand side of 'instanceof' is not an object" during hot-reload/render in development modeRoot Cause
assertTypeusesvalue instanceof typeeven whentypeis not a constructor/function (e.g., user mistakenly declarestype: 'object',type: 'Object', or nested{ type: String })Change Summary
File: packages/runtime-core/src/componentProps.ts
warn(getInvalidTypeMessage(...))); do not crashBehavior After Change
Development Environment
Production Environment
Reproduction (Pre-fix)
<test-comp :modelValue="{ type: 'js' }" />type: 'object'ortype: { type: String })Validation
With the fix:
Scope and Risk
Related
Notes for App Authors
While the runtime now guards against crashes, component props should still be declared with valid constructors/PropType, e.g.:
with an optional validator.
Summary by CodeRabbit