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
6 changes: 6 additions & 0 deletions .changeset/gsplat-props-guard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@playcanvas/react": patch
---

Fixed GSplat component props re-application causing splat to disappear during React re-renders. Added equality guards for `instance` and `material` properties to prevent destructive setter calls when the value hasn't changed.

28 changes: 27 additions & 1 deletion packages/lib/src/components/GSplat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { FC } from "react";
import { useComponent } from "../hooks/index.ts";
import { Asset, Entity, GSplatComponent } from "playcanvas";
import { Asset, Entity, GSplatComponent, GSplatInstance, ShaderMaterial } from "playcanvas";
import { PublicProps } from "../utils/types-utils.ts";
import { validatePropsWithDefaults, createComponentDefinition, getStaticNullApplication } from "../utils/validation.ts";
/**
Expand Down Expand Up @@ -60,5 +60,31 @@ componentDefinition.schema = {
instance.unified = value;
instance.enabled = true;
}
},
material: {
validate: (val: unknown) => val === null || val instanceof ShaderMaterial,
errorMsg: (val: unknown) => `Invalid value for prop "material": "${val}". Expected a ShaderMaterial or null.`,
default: null,
apply: (instance: GSplatComponent, props: Record<string, unknown>, key: string) => {
const value = props[key] as ShaderMaterial | null;
if (instance.material === value) {
return;
}
if (value) {
instance.material = value;
}
}
},
instance: {
validate: (val: unknown) => val === null || val instanceof GSplatInstance,
errorMsg: (val: unknown) => `Invalid value for prop "instance": "${val}". Expected a GSplatInstance or null.`,
default: null,
apply: (instance: GSplatComponent, props: Record<string, unknown>, key: string) => {
const value = props[key] as GSplatInstance | null;
if (instance.instance === value) {
return;
}
instance.instance = value;
}
}
}
Loading