diff --git a/.changeset/thirty-yaks-occur.md b/.changeset/thirty-yaks-occur.md new file mode 100644 index 00000000..73e5ef74 --- /dev/null +++ b/.changeset/thirty-yaks-occur.md @@ -0,0 +1,5 @@ +--- +"@playcanvas/react": patch +--- + +Ensure better prop validation for components that only have a setter. diff --git a/packages/lib/src/hooks/use-component.tsx b/packages/lib/src/hooks/use-component.tsx index a65922a1..22fb037a 100644 --- a/packages/lib/src/hooks/use-component.tsx +++ b/packages/lib/src/hooks/use-component.tsx @@ -33,7 +33,9 @@ export function useComponent( if (comp) { type SystemKeys = keyof typeof app.systems; - if (app.systems[ctype as SystemKeys]) parent.removeComponent(ctype); + if (app.systems[ctype as SystemKeys] && parent.c[ctype]) { + parent.removeComponent(ctype); + } } }; }, [app, parent, ctype]); diff --git a/packages/lib/src/utils/validation.ts b/packages/lib/src/utils/validation.ts index 27d39dc3..282ffcca 100644 --- a/packages/lib/src/utils/validation.ts +++ b/packages/lib/src/utils/validation.ts @@ -226,7 +226,11 @@ export function applyProps, InstanceType>(inst // Use type assertion to satisfy the type checker propDef.apply(instance, props, key as string); } else { - (instance as Record)[key] = value; + try { + (instance as Record)[key] = value; + } catch (error) { + console.error(`Error applying prop ${key}: ${error}`); + } } } } @@ -270,10 +274,12 @@ export function getPseudoPublicProps(container: Record): Record Object.entries(descriptors).forEach(([key, descriptor]) => { // Skip private properties and constructor if (key.startsWith('_') || key === 'constructor') return; - - // Check if this property has a setter - const hasSetter = descriptor.set !== undefined; - + + const hasGetter = typeof descriptor.get === 'function'; + const hasSetter = typeof descriptor.set === 'function'; + + if (hasSetter && !hasGetter) return; + // If it's a getter/setter property, try to get the value if (descriptor.get) { try {