diff --git a/package.json b/package.json index 537147e75..64020deed 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,6 @@ "hls.js": "^1.5.17", "maath": "^0.10.8", "meshline": "^3.3.1", - "react-composer": "^5.0.3", "stats-gl": "^2.2.8", "stats.js": "^0.17.0", "suspend-react": "^0.1.3", @@ -65,6 +64,7 @@ "three-stdlib": "^2.34.0", "troika-three-text": "^0.52.0", "tunnel-rat": "^0.1.2", + "use-sync-external-store": "^1.4.0", "utility-types": "^3.11.0", "uuid": "^9.0.1", "zustand": "^5.0.1" diff --git a/src/core/Instances.tsx b/src/core/Instances.tsx index 194f8d8a3..5c0a19510 100644 --- a/src/core/Instances.tsx +++ b/src/core/Instances.tsx @@ -1,7 +1,6 @@ import * as THREE from 'three' import * as React from 'react' import { ThreeElement, ThreeElements, extend, useFrame } from '@react-three/fiber' -import Composer from 'react-composer' import { ForwardRefComponent } from '../helpers/ts-utils' import { setUpdateRange } from '../helpers/deprecated' @@ -224,32 +223,33 @@ export interface MergedProps extends InstancesProps { children: React.ReactNode } -export const Merged: ForwardRefComponent = /* @__PURE__ */ React.forwardRef( - function Merged({ meshes, children, ...props }, ref) { - const isArray = Array.isArray(meshes) - // Filter out meshes from collections, which may contain non-meshes - if (!isArray) for (const key of Object.keys(meshes)) if (!meshes[key].isMesh) delete meshes[key] - return ( - - ( - - ))} - > - {(args) => - isArray - ? children(...args) - : children( - Object.keys(meshes) - .filter((key) => meshes[key].isMesh) - .reduce((acc, key, i) => ({ ...acc, [key]: args[i] }), {}) - ) - } - - - ) +export const Merged: ForwardRefComponent = React.forwardRef(function Merged( + { meshes, children, ...rest }, + ref +) { + const instances: React.FC[] = [] + + if (Array.isArray(meshes)) { + for (const mesh of meshes) { + if (mesh?.isMesh) { + instances.push((props) => ( + + )) + } + } + } else if (meshes != null && typeof meshes === 'object') { + for (const key in meshes) { + const mesh = meshes[key] + if (mesh?.isMesh) { + instances.push((props) => ( + + )) + } + } } -) + + return {children(instances)} +}) /** Idea and implementation for global instances and instanced attributes by /* Matias Gonzalez Fernandez https://x.com/matiNotFound diff --git a/yarn.lock b/yarn.lock index 6673ffdac..a1a26b49c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6783,7 +6783,7 @@ promzard@^2.0.0: dependencies: read "^4.0.0" -prop-types@^15.6.0, prop-types@^15.8.1: +prop-types@^15.8.1: version "15.8.1" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5" integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg== @@ -6834,13 +6834,6 @@ rc@^1.0.1, rc@^1.1.6, rc@^1.2.8: minimist "^1.2.0" strip-json-comments "~2.0.1" -react-composer@^5.0.3: - version "5.0.3" - resolved "https://registry.yarnpkg.com/react-composer/-/react-composer-5.0.3.tgz#7beb9513da5e8687f4f434ea1333ef36a4f3091b" - integrity sha512-1uWd07EME6XZvMfapwZmc7NgCZqDemcvicRi3wMJzXsQLvZ3L7fTHVyPy1bZdnWXM4iPjYuNE+uJ41MLKeTtnA== - dependencies: - prop-types "^15.6.0" - react-confetti@^6.1.0: version "6.2.2" resolved "https://registry.yarnpkg.com/react-confetti/-/react-confetti-6.2.2.tgz#b72888889b10b6707a91adca919dd35c653f4bb2" @@ -8283,6 +8276,11 @@ use-sync-external-store@1.2.2: resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.2.tgz#c3b6390f3a30eba13200d2302dcdf1e7b57b2ef9" integrity sha512-PElTlVMwpblvbNqQ82d2n6RjStvdSoNe9FG28kNfz3WiXilJm4DdNkEzRhCZuIDwY8U08WVihhGR5iRqAwfDiw== +use-sync-external-store@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.4.0.tgz#adbc795d8eeb47029963016cefdf89dc799fcebc" + integrity sha512-9WXSPC5fMv61vaupRkCKCxsPxBocVnwakBEkMIHHpkTTg6icbJtg6jzgtLDm4bl3cSHAca52rYWih0k4K3PfHw== + util-deprecate@^1.0.2, util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"