Skip to content

Commit 131b07d

Browse files
authored
Exclude incompatible Application props from component schema (#279)
* refactor: update component definition API to use options object - Changed the component definition function to accept an options object, allowing for exclusion of specific props and defining an API name. - Updated multiple components to utilize the new options structure for better clarity and maintainability. - Adjusted the applyProps function to accept a more generic props type. * refactor: expand excluded props in Application component - Added 'gamepads', 'scene', 'scripts', and 'assets' to the list of excluded props in the Application component. - Updated the corresponding exclude array to reflect these changes for improved prop management. * changeset
1 parent 86f01de commit 131b07d

File tree

13 files changed

+45
-18
lines changed

13 files changed

+45
-18
lines changed

.changeset/bitter-tips-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@playcanvas/react": patch
3+
---
4+
5+
Fixing issue with Application schema validation

packages/lib/src/Application.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export const ApplicationWithoutCanvas: FC<ApplicationWithoutCanvasProps> = (prop
189189
// These app properties can be updated without re-rendering
190190
useLayoutEffect(() => {
191191
if (!app) return;
192-
applyProps(app, componentDefinition.schema, otherProps as Record<keyof PlayCanvasApplication, unknown>);
192+
applyProps(app, componentDefinition.schema, otherProps as Record<string, unknown>);
193193
});
194194

195195
if (!app) return null;
@@ -220,7 +220,11 @@ type CanvasProps = {
220220
*/
221221
style?: Record<string, unknown>
222222
}
223-
interface ApplicationProps extends Partial<PublicProps<PlayCanvasApplication>>, CanvasProps {
223+
224+
// These props are excluded from the <Application/> component props.
225+
type ExcludedApplicationProps = 'mouse' | 'touch' | 'keyboard' | 'gamepads' | 'scene' | 'scripts' | 'assets';
226+
227+
interface ApplicationProps extends Omit<Partial<PublicProps<PlayCanvasApplication>>, ExcludedApplicationProps>, CanvasProps {
224228

225229
/**
226230
* Controls how the canvas fills the window and resizes when the window changes.
@@ -265,10 +269,13 @@ interface ApplicationWithoutCanvasProps extends ApplicationProps {
265269
canvasRef: React.RefObject<HTMLCanvasElement | null>;
266270
}
267271

272+
const exclude: ExcludedApplicationProps[] = ['mouse', 'touch', 'keyboard', 'gamepads', 'scene', 'scripts', 'assets'];
273+
268274
const componentDefinition = createComponentDefinition(
269275
"Application",
270276
() => getNullApplication(),
271-
(app) => app.destroy()
277+
(app) => app.destroy(),
278+
{ exclude }
272279
)
273280

274281
componentDefinition.schema = {

packages/lib/src/components/Camera.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ const componentDefinition = createComponentDefinition<CameraProps, CameraCompone
3232
"Camera",
3333
() => new Entity("mock-camera", getStaticNullApplication()).addComponent('camera') as CameraComponent,
3434
(component) => (component as CameraComponent).system.destroy(),
35-
"CameraComponent"
35+
{ apiName: "CameraComponent" }
3636
)

packages/lib/src/components/Collision.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const componentDefinition = createComponentDefinition(
7979
"Collision",
8080
() => new Entity("mock-collision", getStaticNullApplication()).addComponent('collision') as CollisionComponent,
8181
(component) => (component as CollisionComponent).system.destroy(),
82-
"CollisionComponent"
82+
{ apiName: "CollisionComponent" }
8383
)
8484

8585
componentDefinition.schema = {

packages/lib/src/components/Element.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const componentDefinition = createComponentDefinition<ElementProps, ElementCompo
3333
"Element",
3434
() => new Entity("mock-element", getStaticNullApplication()).addComponent("element") as ElementComponent,
3535
(component) => (component as ElementComponent).system.destroy(),
36-
"ElementComponent"
36+
{ apiName: "ElementComponent" }
3737
);
3838

3939

packages/lib/src/components/GSplat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const componentDefinition = createComponentDefinition(
2727
"GSplat",
2828
() => new Entity("mock-gsplat", getStaticNullApplication()).addComponent('gsplat') as GSplatComponent,
2929
(component) => (component as GSplatComponent).system.destroy(),
30-
"GSplatComponent"
30+
{ apiName: "GSplatComponent" }
3131
)
3232

3333
componentDefinition.schema = {

packages/lib/src/components/Light.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const componentDefinition = createComponentDefinition<LightProps, LightComponent
3737
"Light",
3838
() => new Entity('mock-light', getStaticNullApplication()).addComponent('light') as LightComponent,
3939
(component) => (component as LightComponent).system.destroy(),
40-
"LightComponent"
40+
{ apiName: "LightComponent" }
4141
)
4242

4343
componentDefinition.schema = {

packages/lib/src/components/Render.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const componentDefinition = createComponentDefinition<RenderProps, PcRenderCompo
7373
"Render",
7474
() => new Entity('mock-render', getStaticNullApplication()).addComponent('render') as PcRenderComponent,
7575
(component) => (component as PcRenderComponent).system.destroy(),
76-
"RenderComponent"
76+
{ apiName: "RenderComponent" }
7777
)
7878

7979
componentDefinition.schema = {

packages/lib/src/components/RigidBody.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const componentDefinition = createComponentDefinition(
7474
"RigidBody",
7575
() => new Entity("mock-rigidbody", getStaticNullApplication()).addComponent('rigidbody') as RigidBodyComponent,
7676
(component) => (component as RigidBodyComponent).system.destroy(),
77-
"RigidBodyComponent"
77+
{ apiName: "RigidBodyComponent" }
7878
)
7979

8080

packages/lib/src/components/Screen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const componentDefinition = createComponentDefinition<ScreenProps, ScreenCompone
4747
"Screen",
4848
() => new Entity("mock-screen", getStaticNullApplication()).addComponent("screen") as ScreenComponent,
4949
(component) => (component as ScreenComponent).system.destroy(),
50-
"ScreenComponent"
50+
{ apiName: "ScreenComponent" }
5151
);
5252

5353
componentDefinition.schema = {

0 commit comments

Comments
 (0)