Skip to content

Commit a77b15e

Browse files
committed
fix: TypeError in CombinatorProperties.vue
**The Issue:** The `OneOfRenderer.spec.ts` test suite uses a minimal schema that only contains a `oneOf` property. When `CombinatorProperties.vue` mounts, it exctracts properties to generate a UI schema by omitting the combinator keyword (`omit(props.schema, props.combinatorKeyword)`), which in this test case results in an entirely empty object. **The Crash:** When this empty object is passed into `Generate.uiSchema()`, the generator finds no properties and returns a falsy value (null/undefined). The component's internal `isLayout` type guard then immediately executed `Object.prototype.hasOwnProperty.call(uischema, 'elements')`. Passing `null` to `hasOwnProperty` threw a hard `TypeError: Cannot convert undefined or null to object`, crashing the component mount phase. **The Fix:** In `CombinatorProperties.vue`, I explicitly typed the generator output to acknowledge it can return `null` and updated the `isLayout` type guard to safely accept `unknown` inputs. The guard now ensures `uischema !== null` and `typeof uischema === 'object'` before attempting to check for the `elements` property.
1 parent b67f804 commit a77b15e

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎packages/vue-vuetify/src/complex/components/CombinatorProperties.vue‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,26 @@ export default defineComponent({
5454
props.schema,
5555
props.combinatorKeyword,
5656
) as JsonSchema;
57-
const foundUISchema: UISchemaElement = Generate.uiSchema(
57+
58+
// 1. Explicitly acknowledge the generator can return null for empty schemas
59+
const foundUISchema = Generate.uiSchema(
5860
otherProps,
5961
'VerticalLayout',
6062
undefined,
6163
props.rootSchema,
62-
);
64+
) as UISchemaElement | null;
6365
64-
const isLayout = (uischema: UISchemaElement): uischema is Layout =>
65-
Object.prototype.hasOwnProperty.call(uischema, 'elements');
66+
// 2. Implement the bulletproof type guard
67+
const isLayout = (uischema: unknown): uischema is Layout =>
68+
uischema !== null &&
69+
typeof uischema === 'object' &&
70+
'elements' in uischema;
6671
72+
// 3. Address the null bug at the logical level before invoking the guard
6773
const isLayoutWithElements =
68-
isLayout(foundUISchema) && foundUISchema.elements.length > 0;
74+
foundUISchema !== null &&
75+
isLayout(foundUISchema) &&
76+
foundUISchema.elements.length > 0;
6977
7078
return {
7179
otherProps,

0 commit comments

Comments
 (0)