@@ -2,16 +2,8 @@ import * as React from 'react'
2
2
import * as THREE from 'three'
3
3
import useMeasure from 'react-use-measure'
4
4
import type { Options as ResizeOptions } from 'react-use-measure'
5
- import {
6
- isRef ,
7
- SetBlock ,
8
- Block ,
9
- ErrorBoundary ,
10
- useMutableCallback ,
11
- useIsomorphicLayoutEffect ,
12
- useContextBridge ,
13
- FiberProvider ,
14
- } from '../core/utils'
5
+ import { useContextBridge , FiberProvider } from 'its-fine'
6
+ import { isRef , SetBlock , Block , ErrorBoundary , useMutableCallback , useIsomorphicLayoutEffect } from '../core/utils'
15
7
import { ReconcilerRoot , extend , createRoot , unmountComponentAtNode , RenderProps } from '../core'
16
8
import { createPointerEvents } from './events'
17
9
import { DomEvent } from '../core/events'
@@ -33,11 +25,7 @@ export interface CanvasProps
33
25
eventPrefix ?: 'offset' | 'client' | 'page' | 'layer' | 'screen'
34
26
}
35
27
36
- /**
37
- * A DOM canvas which accepts threejs elements as children.
38
- * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
39
- */
40
- export const Canvas = /*#__PURE__*/ React . forwardRef < HTMLCanvasElement , CanvasProps > ( function Canvas (
28
+ const CanvasImpl = /*#__PURE__*/ React . forwardRef < HTMLCanvasElement , CanvasProps > ( function Canvas (
41
29
{
42
30
children,
43
31
fallback,
@@ -69,8 +57,7 @@ export const Canvas = /*#__PURE__*/ React.forwardRef<HTMLCanvasElement, CanvasPr
69
57
// their own elements by using the createRoot API instead
70
58
React . useMemo ( ( ) => extend ( THREE as any ) , [ ] )
71
59
72
- const [ fiber , setFiber ] = React . useState < any > ( null )
73
- const Bridge = useContextBridge ( fiber )
60
+ const Bridge = useContextBridge ( )
74
61
75
62
const [ containerRef , containerRect ] = useMeasure ( { scroll : true , debounce : { scroll : 50 , resize : 0 } , ...resize } )
76
63
const canvasRef = React . useRef < HTMLCanvasElement > ( null ! )
@@ -148,17 +135,27 @@ export const Canvas = /*#__PURE__*/ React.forwardRef<HTMLCanvasElement, CanvasPr
148
135
const pointerEvents = eventSource ? 'none' : 'auto'
149
136
150
137
return (
151
- < FiberProvider setFiber = { setFiber } >
152
- < div
153
- ref = { divRef }
154
- style = { { position : 'relative' , width : '100%' , height : '100%' , overflow : 'hidden' , pointerEvents, ...style } }
155
- { ...props } >
156
- < div ref = { containerRef } style = { { width : '100%' , height : '100%' } } >
157
- < canvas ref = { canvasRef } style = { { display : 'block' } } >
158
- { fallback }
159
- </ canvas >
160
- </ div >
138
+ < div
139
+ ref = { divRef }
140
+ style = { { position : 'relative' , width : '100%' , height : '100%' , overflow : 'hidden' , pointerEvents, ...style } }
141
+ { ...props } >
142
+ < div ref = { containerRef } style = { { width : '100%' , height : '100%' } } >
143
+ < canvas ref = { canvasRef } style = { { display : 'block' } } >
144
+ { fallback }
145
+ </ canvas >
161
146
</ div >
147
+ </ div >
148
+ )
149
+ } )
150
+
151
+ /**
152
+ * A DOM canvas which accepts threejs elements as children.
153
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
154
+ */
155
+ export const Canvas = React . forwardRef < HTMLCanvasElement , CanvasProps > ( function CanvasWrapper ( props , ref ) {
156
+ return (
157
+ < FiberProvider >
158
+ < CanvasImpl { ...props } ref = { ref } />
162
159
</ FiberProvider >
163
160
)
164
161
} )
0 commit comments