WIP: Upgrade to THREE 155: Fix the double key error in r3f
This commit is contained in:
parent
3837e179bb
commit
872b2f741f
1 changed files with 18 additions and 5 deletions
|
@ -1,4 +1,4 @@
|
||||||
import type {VFC} from 'react'
|
import type {FC} from 'react'
|
||||||
import React, {useLayoutEffect, useMemo, useRef, useState} from 'react'
|
import React, {useLayoutEffect, useMemo, useRef, useState} from 'react'
|
||||||
import type {Editable} from '../../main/store'
|
import type {Editable} from '../../main/store'
|
||||||
import {createPortal} from '@react-three/fiber'
|
import {createPortal} from '@react-three/fiber'
|
||||||
|
@ -25,7 +25,7 @@ type IEditableProxy<T> = {
|
||||||
editable: Editable<T>
|
editable: Editable<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProxyManager: VFC<ProxyManagerProps> = ({orbitControlsRef}) => {
|
const ProxyManager: FC<ProxyManagerProps> = ({orbitControlsRef}) => {
|
||||||
const isBeingEdited = useRef(false)
|
const isBeingEdited = useRef(false)
|
||||||
const editorObject = getEditorSheetObject()
|
const editorObject = getEditorSheetObject()
|
||||||
const [sceneSnapshot, editables] = useExtensionStore(
|
const [sceneSnapshot, editables] = useExtensionStore(
|
||||||
|
@ -69,9 +69,18 @@ const ProxyManager: VFC<ProxyManagerProps> = ({orbitControlsRef}) => {
|
||||||
object.parent!.remove(object)
|
object.parent!.remove(object)
|
||||||
} else {
|
} else {
|
||||||
editableProxies[theatreKey] = {
|
editableProxies[theatreKey] = {
|
||||||
portal: createPortal(
|
portal: (
|
||||||
|
// we gotta wrap the portal because as of [this commit](https://github.com/pmndrs/react-three-fiber/commit/5d1652ce5b63397ad79c39d3dd100b26a465c41f)
|
||||||
|
// in react-three-fiber, portals use the uuid of their parent object as their own key. Since many of these objects are nested
|
||||||
|
// inside the same parent, they end up having the same react key. We avoid this issue by wrapping the portal in a component
|
||||||
|
// so that its react key is unique within its parent component.
|
||||||
|
<PortalWrapper
|
||||||
|
portal={createPortal(
|
||||||
<EditableProxy storeKey={theatreKey} object={object} />,
|
<EditableProxy storeKey={theatreKey} object={object} />,
|
||||||
object.parent!,
|
object.parent!,
|
||||||
|
)}
|
||||||
|
key={`portal-wrapper-${theatreKey}`}
|
||||||
|
/>
|
||||||
),
|
),
|
||||||
object: object,
|
object: object,
|
||||||
editable: editables[theatreKey]!,
|
editable: editables[theatreKey]!,
|
||||||
|
@ -246,4 +255,8 @@ const ProxyManager: VFC<ProxyManagerProps> = ({orbitControlsRef}) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PortalWrapper: React.FC<{portal: React.ReactNode}> = ({portal}) => {
|
||||||
|
return <>{portal}</>
|
||||||
|
}
|
||||||
|
|
||||||
export default ProxyManager
|
export default ProxyManager
|
||||||
|
|
Loading…
Reference in a new issue