Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thirty-yaks-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@playcanvas/react": patch
---

Ensure better prop validation for components that only have a setter.
4 changes: 3 additions & 1 deletion packages/lib/src/hooks/use-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export function useComponent<T, InstanceType>(

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]);
Expand Down
16 changes: 11 additions & 5 deletions packages/lib/src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ export function applyProps<T extends Record<string, unknown>, InstanceType>(inst
// Use type assertion to satisfy the type checker
propDef.apply(instance, props, key as string);
} else {
(instance as Record<string, unknown>)[key] = value;
try {
(instance as Record<string, unknown>)[key] = value;
} catch (error) {
console.error(`Error applying prop ${key}: ${error}`);
}
}
}
}
Expand Down Expand Up @@ -270,10 +274,12 @@ export function getPseudoPublicProps(container: Record<string, unknown>): 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 {
Expand Down
Loading