Skip to content

Commit

Permalink
fix: only copy props if same constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Jan 10, 2025
1 parent f3f8914 commit df30468
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/fiber/src/core/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ const colorMaps = ['map', 'emissiveMap', 'sheenColorMap', 'specularColorMap', 'e

const EVENT_REGEX = /^on(Pointer|Click|DoubleClick|ContextMenu|Wheel)/

type ClassConstructor = { new (): void }

// This function applies a set of changes to the instance
export function applyProps<T = any>(object: Instance<T>['object'], props: Instance<T>['props']): Instance<T>['object'] {
const instance = object.__r3f
Expand All @@ -391,7 +393,11 @@ export function applyProps<T = any>(object: Instance<T>['object'], props: Instan
let { root, key, target } = resolve(object, prop)

// Copy if properties match signatures
if (typeof target?.copy === 'function' && target.copy === (value as any).copy) {
if (
target?.copy &&
(value as ClassConstructor | undefined)?.constructor &&
(target as ClassConstructor).constructor === (value as ClassConstructor).constructor
) {
target.copy(value)
}
// Layers have no copy function, we must therefore copy the mask property
Expand Down

0 comments on commit df30468

Please sign in to comment.