@react-three/fiber 8.0.27 → 8.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @react-three/fiber
2
2
 
3
+ ## 8.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 25e35a1: fix: prefer useLayoutEffect in react-native
8
+
9
+ ## 8.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 9770d7d: feat: expose ThreeElements interface for JSX elements
14
+
15
+ ## 8.1.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 8d0f708c: Expose position information in state.size
20
+
3
21
  ## 8.0.27
4
22
 
5
23
  ### Patch Changes
@@ -10,7 +10,7 @@ import { EventManager, ComputeFunction } from './events';
10
10
  import { dispose, getRootState, Camera } from './utils';
11
11
  declare const roots: Map<Element, Root>;
12
12
  declare const invalidate: (state?: RootState | undefined, frames?: number) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined, frame?: THREE.XRFrame | undefined) => void;
13
- declare const reconciler: import("react-reconciler").Reconciler<unknown, unknown, unknown, unknown, unknown>, applyProps: typeof import("./utils").applyProps;
13
+ declare const reconciler: import("react-reconciler").Reconciler<UseBoundStore<RootState, import("zustand").StoreApi<RootState>>, import("./renderer").Instance, never, import("./renderer").Instance, import("./renderer").Instance>, applyProps: typeof import("./utils").applyProps;
14
14
  declare type Properties<T> = Pick<T, {
15
15
  [K in keyof T]: T[K] extends (_: any) => any ? never : K;
16
16
  }[keyof T]>;
@@ -49,10 +49,7 @@ export declare type InjectState = Partial<Omit<RootState, PrivateKeys> & {
49
49
  compute?: ComputeFunction;
50
50
  connected?: any;
51
51
  };
52
- size?: {
53
- width: number;
54
- height: number;
55
- };
52
+ size?: Size;
56
53
  }>;
57
54
  declare function createPortal(children: React.ReactNode, container: THREE.Object3D, state?: InjectState): React.ReactNode;
58
55
  declare const act: any;
@@ -44,8 +44,8 @@ export declare type InstanceProps = {
44
44
  attach?: AttachType;
45
45
  };
46
46
  declare let extend: (objects: object) => void;
47
- declare function createRenderer<TCanvas>(roots: Map<TCanvas, Root>, getEventPriority?: () => any): {
48
- reconciler: Reconciler.Reconciler<unknown, unknown, unknown, unknown, unknown>;
47
+ declare function createRenderer<TCanvas>(_roots: Map<TCanvas, Root>, _getEventPriority?: () => any): {
48
+ reconciler: Reconciler.Reconciler<UseBoundStore<RootState, import("zustand").StoreApi<RootState>>, Instance, never, Instance, Instance>;
49
49
  applyProps: typeof applyProps;
50
50
  };
51
51
  export { prepare, createRenderer, extend };
@@ -17,6 +17,8 @@ export declare type Dpr = number | [min: number, max: number];
17
17
  export declare type Size = {
18
18
  width: number;
19
19
  height: number;
20
+ top: number;
21
+ left: number;
20
22
  updateStyle?: boolean;
21
23
  };
22
24
  export declare type Viewport = Size & {
@@ -81,7 +83,7 @@ export declare type RootState = {
81
83
  invalidate: (frames?: number) => void;
82
84
  advance: (timestamp: number, runGlobalEffects?: boolean) => void;
83
85
  setEvents: (events: Partial<EventManager<any>>) => void;
84
- setSize: (width: number, height: number, updateStyle?: boolean) => void;
86
+ setSize: (width: number, height: number, updateStyle?: boolean, top?: number, left?: number) => void;
85
87
  setDpr: (dpr: Dpr) => void;
86
88
  setFrameloop: (frameloop?: 'always' | 'demand' | 'never') => void;
87
89
  onPointerMissed?: (event: MouseEvent) => void;
@@ -4,7 +4,7 @@ import { AttachType, Instance, InstanceProps, LocalState } from './renderer';
4
4
  import { Dpr, RootState, Size } from './store';
5
5
  export declare type Camera = THREE.OrthographicCamera | THREE.PerspectiveCamera;
6
6
  export declare const isOrthographicCamera: (def: Camera) => def is THREE.OrthographicCamera;
7
- export declare const useIsomorphicLayoutEffect: typeof React.useEffect;
7
+ export declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
8
8
  export declare function useMutableCallback<T>(fn: T): React.MutableRefObject<T>;
9
9
  export declare type SetBlock = false | Promise<null> | null;
10
10
  export declare type UnblockProps = {
@@ -183,146 +183,148 @@ export declare type ColorProps = Node<THREE.Color, ColorArray>;
183
183
  export declare type FogProps = Node<THREE.Fog, typeof THREE.Fog>;
184
184
  export declare type FogExp2Props = Node<THREE.FogExp2, typeof THREE.FogExp2>;
185
185
  export declare type ShapeProps = Node<THREE.Shape, typeof THREE.Shape>;
186
+ export interface ThreeElements {
187
+ object3D: Object3DProps;
188
+ audioListener: AudioListenerProps;
189
+ positionalAudio: PositionalAudioProps;
190
+ mesh: MeshProps;
191
+ instancedMesh: InstancedMeshProps;
192
+ scene: SceneProps;
193
+ sprite: SpriteProps;
194
+ lOD: LODProps;
195
+ skinnedMesh: SkinnedMeshProps;
196
+ skeleton: SkeletonProps;
197
+ bone: BoneProps;
198
+ lineSegments: LineSegmentsProps;
199
+ lineLoop: LineLoopProps;
200
+ points: PointsProps;
201
+ group: GroupProps;
202
+ camera: CameraProps;
203
+ perspectiveCamera: PerspectiveCameraProps;
204
+ orthographicCamera: OrthographicCameraProps;
205
+ cubeCamera: CubeCameraProps;
206
+ arrayCamera: ArrayCameraProps;
207
+ instancedBufferGeometry: InstancedBufferGeometryProps;
208
+ bufferGeometry: BufferGeometryProps;
209
+ boxBufferGeometry: BoxBufferGeometryProps;
210
+ circleBufferGeometry: CircleBufferGeometryProps;
211
+ coneBufferGeometry: ConeBufferGeometryProps;
212
+ cylinderBufferGeometry: CylinderBufferGeometryProps;
213
+ dodecahedronBufferGeometry: DodecahedronBufferGeometryProps;
214
+ extrudeBufferGeometry: ExtrudeBufferGeometryProps;
215
+ icosahedronBufferGeometry: IcosahedronBufferGeometryProps;
216
+ latheBufferGeometry: LatheBufferGeometryProps;
217
+ octahedronBufferGeometry: OctahedronBufferGeometryProps;
218
+ planeBufferGeometry: PlaneBufferGeometryProps;
219
+ polyhedronBufferGeometry: PolyhedronBufferGeometryProps;
220
+ ringBufferGeometry: RingBufferGeometryProps;
221
+ shapeBufferGeometry: ShapeBufferGeometryProps;
222
+ sphereBufferGeometry: SphereBufferGeometryProps;
223
+ tetrahedronBufferGeometry: TetrahedronBufferGeometryProps;
224
+ torusBufferGeometry: TorusBufferGeometryProps;
225
+ torusKnotBufferGeometry: TorusKnotBufferGeometryProps;
226
+ tubeBufferGeometry: TubeBufferGeometryProps;
227
+ wireframeGeometry: WireframeGeometryProps;
228
+ tetrahedronGeometry: TetrahedronGeometryProps;
229
+ octahedronGeometry: OctahedronGeometryProps;
230
+ icosahedronGeometry: IcosahedronGeometryProps;
231
+ dodecahedronGeometry: DodecahedronGeometryProps;
232
+ polyhedronGeometry: PolyhedronGeometryProps;
233
+ tubeGeometry: TubeGeometryProps;
234
+ torusKnotGeometry: TorusKnotGeometryProps;
235
+ torusGeometry: TorusGeometryProps;
236
+ sphereGeometry: SphereGeometryProps;
237
+ ringGeometry: RingGeometryProps;
238
+ planeGeometry: PlaneGeometryProps;
239
+ latheGeometry: LatheGeometryProps;
240
+ shapeGeometry: ShapeGeometryProps;
241
+ extrudeGeometry: ExtrudeGeometryProps;
242
+ edgesGeometry: EdgesGeometryProps;
243
+ coneGeometry: ConeGeometryProps;
244
+ cylinderGeometry: CylinderGeometryProps;
245
+ circleGeometry: CircleGeometryProps;
246
+ boxGeometry: BoxGeometryProps;
247
+ capsuleGeometry: CapsuleGeometryProps;
248
+ material: MaterialProps;
249
+ shadowMaterial: ShadowMaterialProps;
250
+ spriteMaterial: SpriteMaterialProps;
251
+ rawShaderMaterial: RawShaderMaterialProps;
252
+ shaderMaterial: ShaderMaterialProps;
253
+ pointsMaterial: PointsMaterialProps;
254
+ meshPhysicalMaterial: MeshPhysicalMaterialProps;
255
+ meshStandardMaterial: MeshStandardMaterialProps;
256
+ meshPhongMaterial: MeshPhongMaterialProps;
257
+ meshToonMaterial: MeshToonMaterialProps;
258
+ meshNormalMaterial: MeshNormalMaterialProps;
259
+ meshLambertMaterial: MeshLambertMaterialProps;
260
+ meshDepthMaterial: MeshDepthMaterialProps;
261
+ meshDistanceMaterial: MeshDistanceMaterialProps;
262
+ meshBasicMaterial: MeshBasicMaterialProps;
263
+ meshMatcapMaterial: MeshMatcapMaterialProps;
264
+ lineDashedMaterial: LineDashedMaterialProps;
265
+ lineBasicMaterial: LineBasicMaterialProps;
266
+ primitive: PrimitiveProps;
267
+ light: LightProps;
268
+ spotLightShadow: SpotLightShadowProps;
269
+ spotLight: SpotLightProps;
270
+ pointLight: PointLightProps;
271
+ rectAreaLight: RectAreaLightProps;
272
+ hemisphereLight: HemisphereLightProps;
273
+ directionalLightShadow: DirectionalLightShadowProps;
274
+ directionalLight: DirectionalLightProps;
275
+ ambientLight: AmbientLightProps;
276
+ lightShadow: LightShadowProps;
277
+ ambientLightProbe: AmbientLightProbeProps;
278
+ hemisphereLightProbe: HemisphereLightProbeProps;
279
+ lightProbe: LightProbeProps;
280
+ spotLightHelper: SpotLightHelperProps;
281
+ skeletonHelper: SkeletonHelperProps;
282
+ pointLightHelper: PointLightHelperProps;
283
+ hemisphereLightHelper: HemisphereLightHelperProps;
284
+ gridHelper: GridHelperProps;
285
+ polarGridHelper: PolarGridHelperProps;
286
+ directionalLightHelper: DirectionalLightHelperProps;
287
+ cameraHelper: CameraHelperProps;
288
+ boxHelper: BoxHelperProps;
289
+ box3Helper: Box3HelperProps;
290
+ planeHelper: PlaneHelperProps;
291
+ arrowHelper: ArrowHelperProps;
292
+ axesHelper: AxesHelperProps;
293
+ texture: TextureProps;
294
+ videoTexture: VideoTextureProps;
295
+ dataTexture: DataTextureProps;
296
+ dataTexture3D: DataTexture3DProps;
297
+ compressedTexture: CompressedTextureProps;
298
+ cubeTexture: CubeTextureProps;
299
+ canvasTexture: CanvasTextureProps;
300
+ depthTexture: DepthTextureProps;
301
+ raycaster: RaycasterProps;
302
+ vector2: Vector2Props;
303
+ vector3: Vector3Props;
304
+ vector4: Vector4Props;
305
+ euler: EulerProps;
306
+ matrix3: Matrix3Props;
307
+ matrix4: Matrix4Props;
308
+ quaternion: QuaternionProps;
309
+ bufferAttribute: BufferAttributeProps;
310
+ float16BufferAttribute: Float16BufferAttributeProps;
311
+ float32BufferAttribute: Float32BufferAttributeProps;
312
+ float64BufferAttribute: Float64BufferAttributeProps;
313
+ int8BufferAttribute: Int8BufferAttributeProps;
314
+ int16BufferAttribute: Int16BufferAttributeProps;
315
+ int32BufferAttribute: Int32BufferAttributeProps;
316
+ uint8BufferAttribute: Uint8BufferAttributeProps;
317
+ uint16BufferAttribute: Uint16BufferAttributeProps;
318
+ uint32BufferAttribute: Uint32BufferAttributeProps;
319
+ instancedBufferAttribute: InstancedBufferAttributeProps;
320
+ color: ColorProps;
321
+ fog: FogProps;
322
+ fogExp2: FogExp2Props;
323
+ shape: ShapeProps;
324
+ }
186
325
  declare global {
187
326
  namespace JSX {
188
- interface IntrinsicElements {
189
- object3D: Object3DProps;
190
- audioListener: AudioListenerProps;
191
- positionalAudio: PositionalAudioProps;
192
- mesh: MeshProps;
193
- instancedMesh: InstancedMeshProps;
194
- scene: SceneProps;
195
- sprite: SpriteProps;
196
- lOD: LODProps;
197
- skinnedMesh: SkinnedMeshProps;
198
- skeleton: SkeletonProps;
199
- bone: BoneProps;
200
- lineSegments: LineSegmentsProps;
201
- lineLoop: LineLoopProps;
202
- points: PointsProps;
203
- group: GroupProps;
204
- camera: CameraProps;
205
- perspectiveCamera: PerspectiveCameraProps;
206
- orthographicCamera: OrthographicCameraProps;
207
- cubeCamera: CubeCameraProps;
208
- arrayCamera: ArrayCameraProps;
209
- instancedBufferGeometry: InstancedBufferGeometryProps;
210
- bufferGeometry: BufferGeometryProps;
211
- boxBufferGeometry: BoxBufferGeometryProps;
212
- circleBufferGeometry: CircleBufferGeometryProps;
213
- coneBufferGeometry: ConeBufferGeometryProps;
214
- cylinderBufferGeometry: CylinderBufferGeometryProps;
215
- dodecahedronBufferGeometry: DodecahedronBufferGeometryProps;
216
- extrudeBufferGeometry: ExtrudeBufferGeometryProps;
217
- icosahedronBufferGeometry: IcosahedronBufferGeometryProps;
218
- latheBufferGeometry: LatheBufferGeometryProps;
219
- octahedronBufferGeometry: OctahedronBufferGeometryProps;
220
- planeBufferGeometry: PlaneBufferGeometryProps;
221
- polyhedronBufferGeometry: PolyhedronBufferGeometryProps;
222
- ringBufferGeometry: RingBufferGeometryProps;
223
- shapeBufferGeometry: ShapeBufferGeometryProps;
224
- sphereBufferGeometry: SphereBufferGeometryProps;
225
- tetrahedronBufferGeometry: TetrahedronBufferGeometryProps;
226
- torusBufferGeometry: TorusBufferGeometryProps;
227
- torusKnotBufferGeometry: TorusKnotBufferGeometryProps;
228
- tubeBufferGeometry: TubeBufferGeometryProps;
229
- wireframeGeometry: WireframeGeometryProps;
230
- tetrahedronGeometry: TetrahedronGeometryProps;
231
- octahedronGeometry: OctahedronGeometryProps;
232
- icosahedronGeometry: IcosahedronGeometryProps;
233
- dodecahedronGeometry: DodecahedronGeometryProps;
234
- polyhedronGeometry: PolyhedronGeometryProps;
235
- tubeGeometry: TubeGeometryProps;
236
- torusKnotGeometry: TorusKnotGeometryProps;
237
- torusGeometry: TorusGeometryProps;
238
- sphereGeometry: SphereGeometryProps;
239
- ringGeometry: RingGeometryProps;
240
- planeGeometry: PlaneGeometryProps;
241
- latheGeometry: LatheGeometryProps;
242
- shapeGeometry: ShapeGeometryProps;
243
- extrudeGeometry: ExtrudeGeometryProps;
244
- edgesGeometry: EdgesGeometryProps;
245
- coneGeometry: ConeGeometryProps;
246
- cylinderGeometry: CylinderGeometryProps;
247
- circleGeometry: CircleGeometryProps;
248
- boxGeometry: BoxGeometryProps;
249
- capsuleGeometry: CapsuleGeometryProps;
250
- material: MaterialProps;
251
- shadowMaterial: ShadowMaterialProps;
252
- spriteMaterial: SpriteMaterialProps;
253
- rawShaderMaterial: RawShaderMaterialProps;
254
- shaderMaterial: ShaderMaterialProps;
255
- pointsMaterial: PointsMaterialProps;
256
- meshPhysicalMaterial: MeshPhysicalMaterialProps;
257
- meshStandardMaterial: MeshStandardMaterialProps;
258
- meshPhongMaterial: MeshPhongMaterialProps;
259
- meshToonMaterial: MeshToonMaterialProps;
260
- meshNormalMaterial: MeshNormalMaterialProps;
261
- meshLambertMaterial: MeshLambertMaterialProps;
262
- meshDepthMaterial: MeshDepthMaterialProps;
263
- meshDistanceMaterial: MeshDistanceMaterialProps;
264
- meshBasicMaterial: MeshBasicMaterialProps;
265
- meshMatcapMaterial: MeshMatcapMaterialProps;
266
- lineDashedMaterial: LineDashedMaterialProps;
267
- lineBasicMaterial: LineBasicMaterialProps;
268
- primitive: PrimitiveProps;
269
- light: LightProps;
270
- spotLightShadow: SpotLightShadowProps;
271
- spotLight: SpotLightProps;
272
- pointLight: PointLightProps;
273
- rectAreaLight: RectAreaLightProps;
274
- hemisphereLight: HemisphereLightProps;
275
- directionalLightShadow: DirectionalLightShadowProps;
276
- directionalLight: DirectionalLightProps;
277
- ambientLight: AmbientLightProps;
278
- lightShadow: LightShadowProps;
279
- ambientLightProbe: AmbientLightProbeProps;
280
- hemisphereLightProbe: HemisphereLightProbeProps;
281
- lightProbe: LightProbeProps;
282
- spotLightHelper: SpotLightHelperProps;
283
- skeletonHelper: SkeletonHelperProps;
284
- pointLightHelper: PointLightHelperProps;
285
- hemisphereLightHelper: HemisphereLightHelperProps;
286
- gridHelper: GridHelperProps;
287
- polarGridHelper: PolarGridHelperProps;
288
- directionalLightHelper: DirectionalLightHelperProps;
289
- cameraHelper: CameraHelperProps;
290
- boxHelper: BoxHelperProps;
291
- box3Helper: Box3HelperProps;
292
- planeHelper: PlaneHelperProps;
293
- arrowHelper: ArrowHelperProps;
294
- axesHelper: AxesHelperProps;
295
- texture: TextureProps;
296
- videoTexture: VideoTextureProps;
297
- dataTexture: DataTextureProps;
298
- dataTexture3D: DataTexture3DProps;
299
- compressedTexture: CompressedTextureProps;
300
- cubeTexture: CubeTextureProps;
301
- canvasTexture: CanvasTextureProps;
302
- depthTexture: DepthTextureProps;
303
- raycaster: RaycasterProps;
304
- vector2: Vector2Props;
305
- vector3: Vector3Props;
306
- vector4: Vector4Props;
307
- euler: EulerProps;
308
- matrix3: Matrix3Props;
309
- matrix4: Matrix4Props;
310
- quaternion: QuaternionProps;
311
- bufferAttribute: BufferAttributeProps;
312
- float16BufferAttribute: Float16BufferAttributeProps;
313
- float32BufferAttribute: Float32BufferAttributeProps;
314
- float64BufferAttribute: Float64BufferAttributeProps;
315
- int8BufferAttribute: Int8BufferAttributeProps;
316
- int16BufferAttribute: Int16BufferAttributeProps;
317
- int32BufferAttribute: Int32BufferAttributeProps;
318
- uint8BufferAttribute: Uint8BufferAttributeProps;
319
- uint16BufferAttribute: Uint16BufferAttributeProps;
320
- uint32BufferAttribute: Uint32BufferAttributeProps;
321
- instancedBufferAttribute: InstancedBufferAttributeProps;
322
- color: ColorProps;
323
- fog: FogProps;
324
- fogExp2: FogExp2Props;
325
- shape: ShapeProps;
327
+ interface IntrinsicElements extends ThreeElements {
326
328
  }
327
329
  }
328
330
  }
@@ -10,12 +10,19 @@ var threeTypes = /*#__PURE__*/Object.freeze({
10
10
  __proto__: null
11
11
  });
12
12
 
13
- const isOrthographicCamera = def => def && def.isOrthographicCamera; // React currently throws a warning when using useLayoutEffect on the server.
14
- // To get around it, we can conditionally useEffect on the server (no-op) and
15
- // useLayoutEffect on the client.
13
+ var _window$document, _window$navigator;
14
+ const isOrthographicCamera = def => def && def.isOrthographicCamera;
15
+ /**
16
+ * An SSR-friendly useLayoutEffect.
17
+ *
18
+ * React currently throws a warning when using useLayoutEffect on the server.
19
+ * To get around it, we can conditionally useEffect on the server (no-op) and
20
+ * useLayoutEffect elsewhere.
21
+ *
22
+ * @see https://github.com/facebook/react/issues/14927
23
+ */
16
24
 
17
- const isSSR = typeof window === 'undefined' || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
18
- const useIsomorphicLayoutEffect = isSSR ? React.useEffect : React.useLayoutEffect;
25
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' && ((_window$document = window.document) != null && _window$document.createElement || ((_window$navigator = window.navigator) == null ? void 0 : _window$navigator.product) === 'ReactNative') ? React.useLayoutEffect : React.useEffect;
19
26
  function useMutableCallback(fn) {
20
27
  const ref = React.useRef(fn);
21
28
  useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
@@ -828,7 +835,7 @@ let extend = objects => void (catalogue = { ...catalogue,
828
835
  ...objects
829
836
  });
830
837
 
831
- function createRenderer(roots, getEventPriority) {
838
+ function createRenderer(_roots, _getEventPriority) {
832
839
  function createInstance(type, {
833
840
  args = [],
834
841
  attach,
@@ -1044,10 +1051,10 @@ function createRenderer(roots, getEventPriority) {
1044
1051
  appendChild,
1045
1052
  appendInitialChild: appendChild,
1046
1053
  insertBefore,
1047
- supportsMicrotask: true,
1048
- warnsIfNotActing: true,
1049
1054
  supportsMutation: true,
1050
1055
  isPrimaryRenderer: false,
1056
+ supportsPersistence: false,
1057
+ supportsHydration: false,
1051
1058
  noTimeout: -1,
1052
1059
  appendChildToContainer: (container, child) => {
1053
1060
  const scene = container.getState().scene; // Link current root to the default scene
@@ -1066,10 +1073,10 @@ function createRenderer(roots, getEventPriority) {
1066
1073
  const localState = (_instance$__r3f2 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f2 : {}; // https://github.com/facebook/react/issues/20271
1067
1074
  // Returning true will trigger commitMount
1068
1075
 
1069
- return !!localState.handlers;
1076
+ return Boolean(localState.handlers);
1070
1077
  },
1071
1078
 
1072
- prepareUpdate(instance, type, oldProps, newProps) {
1079
+ prepareUpdate(instance, _type, oldProps, newProps) {
1073
1080
  // Create diff-sets
1074
1081
  if (instance.__r3f.primitive && newProps.object && newProps.object !== instance) {
1075
1082
  return [true];
@@ -1086,7 +1093,7 @@ function createRenderer(roots, getEventPriority) {
1086
1093
  ...restOld
1087
1094
  } = oldProps; // Throw if an object or literal was passed for args
1088
1095
 
1089
- if (!Array.isArray(argsNew)) throw 'The args prop must be an array!'; // If it has new props or arguments, then it needs to be re-instanciated
1096
+ if (!Array.isArray(argsNew)) throw 'The args prop must be an array!'; // If it has new props or arguments, then it needs to be re-instantiated
1090
1097
 
1091
1098
  if (argsNew.some((value, index) => value !== argsOld[index])) return [true]; // Create a diff-set, flag if there are any changes
1092
1099
 
@@ -1097,13 +1104,13 @@ function createRenderer(roots, getEventPriority) {
1097
1104
  }
1098
1105
  },
1099
1106
 
1100
- commitUpdate(instance, [reconstruct, diff], type, oldProps, newProps, fiber) {
1107
+ commitUpdate(instance, [reconstruct, diff], type, _oldProps, newProps, fiber) {
1101
1108
  // Reconstruct when args or <primitive object={...} have changes
1102
1109
  if (reconstruct) switchInstance(instance, type, newProps, fiber); // Otherwise just overwrite props
1103
1110
  else applyProps$1(instance, diff);
1104
1111
  },
1105
1112
 
1106
- commitMount(instance, type, props, int) {
1113
+ commitMount(instance, _type, _props, _int) {
1107
1114
  var _instance$__r3f3;
1108
1115
 
1109
1116
  // https://github.com/facebook/react/issues/20271
@@ -1116,13 +1123,11 @@ function createRenderer(roots, getEventPriority) {
1116
1123
  },
1117
1124
 
1118
1125
  getPublicInstance: instance => instance,
1119
- shouldDeprioritizeSubtree: () => false,
1120
1126
  prepareForCommit: () => null,
1121
1127
  preparePortalMount: container => prepare(container.getState().scene),
1122
1128
  resetAfterCommit: () => {},
1123
1129
  shouldSetTextContent: () => false,
1124
1130
  clearContainer: () => false,
1125
- detachDeletedInstance: () => {},
1126
1131
 
1127
1132
  hideInstance(instance) {
1128
1133
  var _instance$__r3f4;
@@ -1150,20 +1155,23 @@ function createRenderer(roots, getEventPriority) {
1150
1155
  invalidateInstance(instance);
1151
1156
  },
1152
1157
 
1153
- createTextInstance: () => {},
1158
+ createTextInstance: () => {
1159
+ throw new Error('Text is not allowed in the R3F tree! This could be stray whitespace or characters.');
1160
+ },
1154
1161
  hideTextInstance: () => {
1155
- throw new Error('Text is not allowed in the R3F tree.');
1162
+ throw new Error('Text is not allowed in the R3F tree! This could be stray whitespace or characters.');
1156
1163
  },
1157
1164
  unhideTextInstance: () => {},
1158
- getCurrentEventPriority: () => getEventPriority ? getEventPriority() : DefaultEventPriority,
1159
- // @ts-ignore
1160
- now: typeof performance !== 'undefined' && is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : undefined,
1165
+ // https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874
1161
1166
  // @ts-ignore
1167
+ getCurrentEventPriority: () => _getEventPriority ? _getEventPriority() : DefaultEventPriority,
1168
+ beforeActiveInstanceBlur: () => {},
1169
+ afterActiveInstanceBlur: () => {},
1170
+ detachDeletedInstance: () => {},
1171
+ now: typeof performance !== 'undefined' && is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : () => 0,
1172
+ // https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r920883503
1162
1173
  scheduleTimeout: is.fun(setTimeout) ? setTimeout : undefined,
1163
- // @ts-ignore
1164
- cancelTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
1165
- setTimeout: is.fun(setTimeout) ? setTimeout : undefined,
1166
- clearTimeout: is.fun(clearTimeout) ? clearTimeout : undefined
1174
+ cancelTimeout: is.fun(clearTimeout) ? clearTimeout : undefined
1167
1175
  });
1168
1176
  return {
1169
1177
  reconciler,
@@ -1184,7 +1192,9 @@ const createStore = (invalidate, advance) => {
1184
1192
  function getCurrentViewport(camera = get().camera, target = defaultTarget, size = get().size) {
1185
1193
  const {
1186
1194
  width,
1187
- height
1195
+ height,
1196
+ top,
1197
+ left
1188
1198
  } = size;
1189
1199
  const aspect = width / height;
1190
1200
  if (target instanceof THREE.Vector3) tempTarget.copy(target);else tempTarget.set(...target);
@@ -1194,6 +1204,8 @@ const createStore = (invalidate, advance) => {
1194
1204
  return {
1195
1205
  width: width / camera.zoom,
1196
1206
  height: height / camera.zoom,
1207
+ top,
1208
+ left,
1197
1209
  factor: 1,
1198
1210
  distance,
1199
1211
  aspect
@@ -1207,6 +1219,8 @@ const createStore = (invalidate, advance) => {
1207
1219
  return {
1208
1220
  width: w,
1209
1221
  height: h,
1222
+ top,
1223
+ left,
1210
1224
  factor: width / w,
1211
1225
  distance,
1212
1226
  aspect
@@ -1223,7 +1237,7 @@ const createStore = (invalidate, advance) => {
1223
1237
  }));
1224
1238
 
1225
1239
  const pointer = new THREE.Vector2();
1226
- return {
1240
+ const rootState = {
1227
1241
  set,
1228
1242
  get,
1229
1243
  // Mock objects that have to be configured
@@ -1266,6 +1280,8 @@ const createStore = (invalidate, advance) => {
1266
1280
  size: {
1267
1281
  width: 0,
1268
1282
  height: 0,
1283
+ top: 0,
1284
+ left: 0,
1269
1285
  updateStyle: false
1270
1286
  },
1271
1287
  viewport: {
@@ -1273,6 +1289,8 @@ const createStore = (invalidate, advance) => {
1273
1289
  dpr: 0,
1274
1290
  width: 0,
1275
1291
  height: 0,
1292
+ top: 0,
1293
+ left: 0,
1276
1294
  aspect: 0,
1277
1295
  distance: 0,
1278
1296
  factor: 0,
@@ -1283,11 +1301,13 @@ const createStore = (invalidate, advance) => {
1283
1301
  ...events
1284
1302
  }
1285
1303
  })),
1286
- setSize: (width, height, updateStyle) => {
1304
+ setSize: (width, height, updateStyle, top, left) => {
1287
1305
  const camera = get().camera;
1288
1306
  const size = {
1289
1307
  width,
1290
1308
  height,
1309
+ top: top || 0,
1310
+ left: left || 0,
1291
1311
  updateStyle
1292
1312
  };
1293
1313
  set(state => ({
@@ -1361,6 +1381,7 @@ const createStore = (invalidate, advance) => {
1361
1381
  }
1362
1382
  }
1363
1383
  };
1384
+ return rootState;
1364
1385
  });
1365
1386
  const state = rootState.getState();
1366
1387
  let oldSize = state.size;
@@ -1402,15 +1423,17 @@ const createStore = (invalidate, advance) => {
1402
1423
  };
1403
1424
 
1404
1425
  function createSubs(callback, subs) {
1405
- const index = subs.length;
1406
- subs.push(callback);
1407
- return () => void subs.splice(index, 1);
1426
+ const sub = {
1427
+ callback
1428
+ };
1429
+ subs.add(sub);
1430
+ return () => void subs.delete(sub);
1408
1431
  }
1409
1432
 
1410
1433
  let i;
1411
- let globalEffects = [];
1412
- let globalAfterEffects = [];
1413
- let globalTailEffects = [];
1434
+ let globalEffects = new Set();
1435
+ let globalAfterEffects = new Set();
1436
+ let globalTailEffects = new Set();
1414
1437
  /**
1415
1438
  * Adds a global render callback which is called each frame.
1416
1439
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
@@ -1431,7 +1454,9 @@ const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
1431
1454
  const addTail = callback => createSubs(callback, globalTailEffects);
1432
1455
 
1433
1456
  function run(effects, timestamp) {
1434
- for (i = 0; i < effects.length; i++) effects[i](timestamp);
1457
+ effects.forEach(({
1458
+ callback
1459
+ }) => callback(timestamp));
1435
1460
  }
1436
1461
 
1437
1462
  let subscribers;
@@ -1473,7 +1498,7 @@ function createLoop(roots) {
1473
1498
  running = true;
1474
1499
  repeat = 0; // Run effects
1475
1500
 
1476
- if (globalEffects.length) run(globalEffects, timestamp); // Render all roots
1501
+ if (globalEffects.size) run(globalEffects, timestamp); // Render all roots
1477
1502
 
1478
1503
  roots.forEach(root => {
1479
1504
  var _state$gl$xr;
@@ -1485,11 +1510,11 @@ function createLoop(roots) {
1485
1510
  }
1486
1511
  }); // Run after-effects
1487
1512
 
1488
- if (globalAfterEffects.length) run(globalAfterEffects, timestamp); // Stop the loop if nothing invalidates it
1513
+ if (globalAfterEffects.size) run(globalAfterEffects, timestamp); // Stop the loop if nothing invalidates it
1489
1514
 
1490
1515
  if (repeat === 0) {
1491
1516
  // Tail call effects, they are called when rendering stops
1492
- if (globalTailEffects.length) run(globalTailEffects, timestamp); // Flag end of operation
1517
+ if (globalTailEffects.size) run(globalTailEffects, timestamp); // Flag end of operation
1493
1518
 
1494
1519
  running = false;
1495
1520
  return cancelAnimationFrame(frame);
@@ -1668,8 +1693,6 @@ function createRoot(canvas) {
1668
1693
  let configured = false;
1669
1694
  return {
1670
1695
  configure(props = {}) {
1671
- var _canvas$parentElement, _canvas$parentElement2, _canvas$parentElement3, _canvas$parentElement4;
1672
-
1673
1696
  let {
1674
1697
  gl: glConfig,
1675
1698
  size,
@@ -1807,11 +1830,22 @@ function createRoot(canvas) {
1807
1830
 
1808
1831
  if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr); // Check size, allow it to take on container bounds initially
1809
1832
 
1810
- size = size || {
1811
- width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
1812
- height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
1813
- };
1814
- if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height, size.updateStyle); // Check frameloop
1833
+ size = size || (canvas.parentElement ? {
1834
+ width: canvas.parentElement.clientWidth,
1835
+ height: canvas.parentElement.clientHeight,
1836
+ top: canvas.parentElement.clientTop,
1837
+ left: canvas.parentElement.clientLeft
1838
+ } : {
1839
+ width: 0,
1840
+ height: 0,
1841
+ top: 0,
1842
+ left: 0
1843
+ });
1844
+
1845
+ if (!is.equ(size, state.size, shallowLoose)) {
1846
+ state.setSize(size.width, size.height, size.updateStyle, size.top, size.left);
1847
+ } // Check frameloop
1848
+
1815
1849
 
1816
1850
  if (state.frameloop !== frameloop) state.setFrameloop(frameloop); // Check pointer missed
1817
1851