@react-three/fiber 7.0.25 → 7.0.28

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.
@@ -1,13 +1,13 @@
1
- import * as React from 'react';
2
- import { Options as ResizeOptions } from 'react-use-measure';
3
- import { RenderProps } from './index';
4
- import { UseStore } from 'zustand';
5
- import { RootState } from '../core/store';
6
- import { EventManager } from '../core/events';
7
- export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size' | 'events'>, React.HTMLAttributes<HTMLDivElement> {
8
- children: React.ReactNode;
9
- fallback?: React.ReactNode;
10
- resize?: ResizeOptions;
11
- events?: (store: UseStore<RootState>) => EventManager<any>;
12
- }
13
- export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
1
+ import * as React from 'react';
2
+ import { Options as ResizeOptions } from 'react-use-measure';
3
+ import { RenderProps } from './index';
4
+ import { UseBoundStore } from 'zustand';
5
+ import { RootState } from '../core/store';
6
+ import { EventManager } from '../core/events';
7
+ export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size' | 'events'>, React.HTMLAttributes<HTMLDivElement> {
8
+ children: React.ReactNode;
9
+ fallback?: React.ReactNode;
10
+ resize?: ResizeOptions;
11
+ events?: (store: UseBoundStore<RootState>) => EventManager<any>;
12
+ }
13
+ export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
@@ -1,4 +1,4 @@
1
- import { UseStore } from 'zustand';
2
- import { RootState } from '../core/store';
3
- import type { EventManager } from '../core/events';
4
- export declare function createPointerEvents(store: UseStore<RootState>): EventManager<HTMLElement>;
1
+ import { UseBoundStore } from 'zustand';
2
+ import { RootState } from '../core/store';
3
+ import type { EventManager } from '../core/events';
4
+ export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
@@ -1,36 +1,36 @@
1
- /// <reference types="react-reconciler" />
2
- import * as THREE from 'three';
3
- import * as React from 'react';
4
- import { UseStore } from 'zustand';
5
- import { Renderer, StoreProps, context, RootState, Size } from '../core/store';
6
- import { extend, Root } from '../core/renderer';
7
- import { addEffect, addAfterEffect, addTail } from '../core/loop';
8
- import { createPointerEvents as events } from './events';
9
- import { Canvas } from './Canvas';
10
- import { EventManager } from '../core/events';
11
- declare const roots: Map<Element, Root>;
12
- declare const modes: readonly ["legacy", "blocking", "concurrent"];
13
- declare const invalidate: (state?: RootState | undefined) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined) => void;
14
- declare const reconciler: import("react-reconciler").Reconciler<unknown, unknown, unknown, unknown, unknown>, applyProps: (instance: import("../core/renderer").Instance, data: import("../core/renderer").InstanceProps | import("../core/renderer").DiffSet) => import("../core/renderer").Instance;
15
- declare type Properties<T> = Pick<T, {
16
- [K in keyof T]: T[K] extends (_: any) => any ? never : K;
17
- }[keyof T]>;
18
- declare type GLProps = Renderer | ((canvas: HTMLCanvasElement) => Renderer) | Partial<Properties<THREE.WebGLRenderer> | THREE.WebGLRendererParameters> | undefined;
19
- export declare type RenderProps<TCanvas extends Element> = Omit<StoreProps, 'gl' | 'events' | 'size'> & {
20
- gl?: GLProps;
21
- events?: (store: UseStore<RootState>) => EventManager<TCanvas>;
22
- size?: Size;
23
- mode?: typeof modes[number];
24
- onCreated?: (state: RootState) => void;
25
- };
26
- declare function render<TCanvas extends Element>(element: React.ReactNode, canvas: TCanvas, { gl, size, mode, events, onCreated, ...props }?: RenderProps<TCanvas>): UseStore<RootState>;
27
- declare function unmountComponentAtNode<TElement extends Element>(canvas: TElement, callback?: (canvas: TElement) => void): void;
28
- declare function dispose<TObj extends {
29
- dispose?: () => void;
30
- type?: string;
31
- [key: string]: any;
32
- }>(obj: TObj): void;
33
- declare const act: (callback: () => import("react-reconciler").Thenable<unknown>) => import("react-reconciler").Thenable<void>;
34
- declare function createPortal(children: React.ReactNode, container: THREE.Object3D): React.ReactNode;
35
- export * from '../core/hooks';
36
- export { context, render, unmountComponentAtNode, createPortal, events, reconciler, applyProps, dispose, invalidate, advance, extend, addEffect, addAfterEffect, addTail, Canvas, act, roots as _roots, };
1
+ /// <reference types="react-reconciler" />
2
+ import * as THREE from 'three';
3
+ import * as React from 'react';
4
+ import { UseBoundStore } from 'zustand';
5
+ import { Renderer, StoreProps, context, RootState, Size } from '../core/store';
6
+ import { extend, Root } from '../core/renderer';
7
+ import { addEffect, addAfterEffect, addTail } from '../core/loop';
8
+ import { createPointerEvents as events } from './events';
9
+ import { Canvas } from './Canvas';
10
+ import { EventManager } from '../core/events';
11
+ declare const roots: Map<Element, Root>;
12
+ declare const modes: readonly ["legacy", "blocking", "concurrent"];
13
+ declare const invalidate: (state?: RootState | undefined) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined) => void;
14
+ declare const reconciler: import("react-reconciler").Reconciler<unknown, unknown, unknown, unknown, unknown>, applyProps: (instance: import("../core/renderer").Instance, data: import("../core/renderer").DiffSet | import("../core/renderer").InstanceProps) => import("../core/renderer").Instance;
15
+ declare type Properties<T> = Pick<T, {
16
+ [K in keyof T]: T[K] extends (_: any) => any ? never : K;
17
+ }[keyof T]>;
18
+ declare type GLProps = Renderer | ((canvas: HTMLCanvasElement) => Renderer) | Partial<Properties<THREE.WebGLRenderer> | THREE.WebGLRendererParameters> | undefined;
19
+ export declare type RenderProps<TCanvas extends Element> = Omit<StoreProps, 'gl' | 'events' | 'size'> & {
20
+ gl?: GLProps;
21
+ events?: (store: UseBoundStore<RootState>) => EventManager<TCanvas>;
22
+ size?: Size;
23
+ mode?: typeof modes[number];
24
+ onCreated?: (state: RootState) => void;
25
+ };
26
+ declare function render<TCanvas extends Element>(element: React.ReactNode, canvas: TCanvas, { gl, size, mode, events, onCreated, ...props }?: RenderProps<TCanvas>): UseBoundStore<RootState>;
27
+ declare function unmountComponentAtNode<TElement extends Element>(canvas: TElement, callback?: (canvas: TElement) => void): void;
28
+ declare function dispose<TObj extends {
29
+ dispose?: () => void;
30
+ type?: string;
31
+ [key: string]: any;
32
+ }>(obj: TObj): void;
33
+ declare const act: (callback: () => import("react-reconciler").Thenable<unknown>) => import("react-reconciler").Thenable<void>;
34
+ declare function createPortal(children: React.ReactNode, container: THREE.Object3D): React.ReactNode;
35
+ export * from '../core/hooks';
36
+ export { context, render, unmountComponentAtNode, createPortal, events, reconciler, applyProps, dispose, invalidate, advance, extend, addEffect, addAfterEffect, addTail, Canvas, act, roots as _roots, };
@@ -22,14 +22,12 @@ function _interopNamespace(e) {
22
22
  var d = Object.getOwnPropertyDescriptor(e, k);
23
23
  Object.defineProperty(n, k, d.get ? d : {
24
24
  enumerable: true,
25
- get: function () {
26
- return e[k];
27
- }
25
+ get: function () { return e[k]; }
28
26
  });
29
27
  }
30
28
  });
31
29
  }
32
- n['default'] = e;
30
+ n["default"] = e;
33
31
  return Object.freeze(n);
34
32
  }
35
33
 
@@ -114,7 +112,7 @@ function createEvents(store) {
114
112
  /** Sets up defaultRaycaster */
115
113
 
116
114
  function prepareRay(event) {
117
- var _raycaster$computeOff;
115
+ var _customOffsets$offset, _customOffsets$offset2, _customOffsets$width, _customOffsets$height;
118
116
 
119
117
  const state = store.getState();
120
118
  const {
@@ -125,14 +123,11 @@ function createEvents(store) {
125
123
  } = state; // https://github.com/pmndrs/react-three-fiber/pull/782
126
124
  // Events trigger outside of canvas when moved
127
125
 
128
- const {
129
- offsetX,
130
- offsetY
131
- } = (_raycaster$computeOff = raycaster.computeOffsets == null ? void 0 : raycaster.computeOffsets(event, state)) != null ? _raycaster$computeOff : event;
132
- const {
133
- width,
134
- height
135
- } = size;
126
+ const customOffsets = raycaster.computeOffsets == null ? void 0 : raycaster.computeOffsets(event, state);
127
+ const offsetX = (_customOffsets$offset = customOffsets == null ? void 0 : customOffsets.offsetX) != null ? _customOffsets$offset : event.offsetX;
128
+ const offsetY = (_customOffsets$offset2 = customOffsets == null ? void 0 : customOffsets.offsetY) != null ? _customOffsets$offset2 : event.offsetY;
129
+ const width = (_customOffsets$width = customOffsets == null ? void 0 : customOffsets.width) != null ? _customOffsets$width : size.width;
130
+ const height = (_customOffsets$height = customOffsets == null ? void 0 : customOffsets.height) != null ? _customOffsets$height : size.height;
136
131
  mouse.set(offsetX / width * 2 - 1, -(offsetY / height) * 2 + 1);
137
132
  raycaster.setFromCamera(mouse, camera);
138
133
  }
@@ -629,29 +624,29 @@ function createRenderer(roots) {
629
624
  localState.eventCount = Object.keys(localState.handlers).length;
630
625
  } // Special treatment for objects with support for set/copy, and layers
631
626
  else if (targetProp && targetProp.set && (targetProp.copy || targetProp instanceof THREE__namespace.Layers)) {
632
- // If value is an array
633
- if (Array.isArray(value)) {
634
- if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
635
- } // Test again target.copy(class) next ...
636
- else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) targetProp.copy(value); // If nothing else fits, just set the single value, ignore undefined
637
- // https://github.com/pmndrs/react-three-fiber/issues/274
638
- else if (value !== undefined) {
639
- const isColor = targetProp instanceof THREE__namespace.Color; // Allow setting array scalars
640
-
641
- if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
642
- else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
643
- else targetProp.set(value); // Auto-convert sRGB colors, for now ...
644
- // https://github.com/pmndrs/react-three-fiber/issues/344
645
-
646
- if (!isLinear && isColor) targetProp.convertSRGBToLinear();
647
- } // Else, just overwrite the value
648
-
649
- } else {
650
- currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
627
+ // If value is an array
628
+ if (Array.isArray(value)) {
629
+ if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
630
+ } // Test again target.copy(class) next ...
631
+ else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) targetProp.copy(value); // If nothing else fits, just set the single value, ignore undefined
632
+ // https://github.com/pmndrs/react-three-fiber/issues/274
633
+ else if (value !== undefined) {
634
+ const isColor = targetProp instanceof THREE__namespace.Color; // Allow setting array scalars
635
+
636
+ if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
637
+ else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
638
+ else targetProp.set(value); // Auto-convert sRGB colors, for now ...
651
639
  // https://github.com/pmndrs/react-three-fiber/issues/344
652
640
 
653
- if (!isLinear && currentInstance[key] instanceof THREE__namespace.Texture) currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
654
- }
641
+ if (!isLinear && isColor) targetProp.convertSRGBToLinear();
642
+ } // Else, just overwrite the value
643
+
644
+ } else {
645
+ currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
646
+ // https://github.com/pmndrs/react-three-fiber/issues/344
647
+
648
+ if (!isLinear && currentInstance[key] instanceof THREE__namespace.Texture) currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
649
+ }
655
650
 
656
651
  invalidateInstance(instance);
657
652
  });
@@ -792,8 +787,13 @@ function createRenderer(roots) {
792
787
 
793
788
  if (child) {
794
789
  if (child.attachArray) {
795
- const array = parentInstance[child.attachArray];
796
- if (!is.arr(array)) parentInstance[child.attachArray] = [];
790
+ let array = parentInstance[child.attachArray];
791
+
792
+ if (!is.arr(array)) {
793
+ parentInstance[child.attachArray] = [];
794
+ array = parentInstance[child.attachArray];
795
+ }
796
+
797
797
  array.splice(array.indexOf(beforeChild), 0, child);
798
798
  } else if (child.attachObject || child.attach && !is.fun(child.attach)) {
799
799
  // attach and attachObject don't have an order anyway, so just append
@@ -945,7 +945,7 @@ function createRenderer(roots) {
945
945
  });
946
946
  }
947
947
 
948
- const reconciler = Reconciler__default['default']({
948
+ const reconciler = Reconciler__default["default"]({
949
949
  now: scheduler.unstable_now,
950
950
  createInstance,
951
951
  removeChild,
@@ -1059,9 +1059,7 @@ function createRenderer(roots) {
1059
1059
  return !!localState.handlers;
1060
1060
  },
1061
1061
 
1062
- commitMount(instance)
1063
- /*, type, props*/
1064
- {
1062
+ commitMount(instance) {
1065
1063
  var _instance$__r3f8;
1066
1064
 
1067
1065
  // https://github.com/facebook/react/issues/20271
@@ -1139,7 +1137,7 @@ const createStore = (applyProps, invalidate, advance, props) => {
1139
1137
  clock.elapsedTime = 0;
1140
1138
  }
1141
1139
 
1142
- const rootState = create__default['default']((set, get) => {
1140
+ const rootState = create__default["default"]((set, get) => {
1143
1141
  // Create custom raycaster
1144
1142
  const raycaster = new THREE__namespace.Raycaster();
1145
1143
  const {
@@ -1573,10 +1571,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
1573
1571
  events,
1574
1572
  ...props
1575
1573
  }, forwardedRef) {
1574
+ const onPointerMissed = useMemoizedFn(props.onPointerMissed);
1576
1575
  const [containerRef, {
1577
1576
  width,
1578
1577
  height
1579
- }] = useMeasure__default['default']({
1578
+ }] = useMeasure__default["default"]({
1580
1579
  scroll: true,
1581
1580
  debounce: {
1582
1581
  scroll: 50,
@@ -1605,10 +1604,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
1605
1604
  width,
1606
1605
  height
1607
1606
  },
1607
+ onPointerMissed,
1608
1608
  events: events || createPointerEvents
1609
1609
  });
1610
1610
  }
1611
- }, [width, height, children]);
1611
+ }, [width, height, children, onPointerMissed]);
1612
1612
  useIsomorphicLayoutEffect(() => {
1613
1613
  const container = canvasRef.current;
1614
1614
  return () => unmountComponentAtNode(container);
@@ -1626,7 +1626,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
1626
1626
  ...style
1627
1627
  }
1628
1628
  }, /*#__PURE__*/React__namespace.createElement("canvas", {
1629
- ref: mergeRefs__default['default']([canvasRef, forwardedRef]),
1629
+ ref: mergeRefs__default["default"]([canvasRef, forwardedRef]),
1630
1630
  style: {
1631
1631
  display: 'block'
1632
1632
  }
@@ -1689,6 +1689,11 @@ function loadingFn(extensions, onProgress) {
1689
1689
  };
1690
1690
  }
1691
1691
 
1692
+ function useMemoizedFn(fn) {
1693
+ const fnRef = React__namespace.useRef(fn);
1694
+ React__namespace.useLayoutEffect(() => void (fnRef.current = fn), [fn]);
1695
+ return (...args) => fnRef.current == null ? void 0 : fnRef.current(...args);
1696
+ }
1692
1697
  function useLoader(Proto, input, extensions, onProgress) {
1693
1698
  // Use suspense to load async assets
1694
1699
  const keys = Array.isArray(input) ? input : [input];
@@ -1874,8 +1879,7 @@ function dispose(obj) {
1874
1879
  if (obj.dispose && obj.type !== 'Scene') obj.dispose();
1875
1880
 
1876
1881
  for (const p in obj) {
1877
- var _dispose, _ref;
1878
- (_dispose = (_ref = p).dispose) == null ? void 0 : _dispose.call(_ref);
1882
+ p.dispose == null ? void 0 : p.dispose();
1879
1883
  delete obj[p];
1880
1884
  }
1881
1885
  }
@@ -1913,5 +1917,6 @@ exports.unmountComponentAtNode = unmountComponentAtNode;
1913
1917
  exports.useFrame = useFrame;
1914
1918
  exports.useGraph = useGraph;
1915
1919
  exports.useLoader = useLoader;
1920
+ exports.useMemoizedFn = useMemoizedFn;
1916
1921
  exports.useStore = useStore;
1917
1922
  exports.useThree = useThree;
@@ -22,14 +22,12 @@ function _interopNamespace(e) {
22
22
  var d = Object.getOwnPropertyDescriptor(e, k);
23
23
  Object.defineProperty(n, k, d.get ? d : {
24
24
  enumerable: true,
25
- get: function () {
26
- return e[k];
27
- }
25
+ get: function () { return e[k]; }
28
26
  });
29
27
  }
30
28
  });
31
29
  }
32
- n['default'] = e;
30
+ n["default"] = e;
33
31
  return Object.freeze(n);
34
32
  }
35
33
 
@@ -114,7 +112,7 @@ function createEvents(store) {
114
112
  /** Sets up defaultRaycaster */
115
113
 
116
114
  function prepareRay(event) {
117
- var _raycaster$computeOff;
115
+ var _customOffsets$offset, _customOffsets$offset2, _customOffsets$width, _customOffsets$height;
118
116
 
119
117
  const state = store.getState();
120
118
  const {
@@ -125,14 +123,11 @@ function createEvents(store) {
125
123
  } = state; // https://github.com/pmndrs/react-three-fiber/pull/782
126
124
  // Events trigger outside of canvas when moved
127
125
 
128
- const {
129
- offsetX,
130
- offsetY
131
- } = (_raycaster$computeOff = raycaster.computeOffsets == null ? void 0 : raycaster.computeOffsets(event, state)) != null ? _raycaster$computeOff : event;
132
- const {
133
- width,
134
- height
135
- } = size;
126
+ const customOffsets = raycaster.computeOffsets == null ? void 0 : raycaster.computeOffsets(event, state);
127
+ const offsetX = (_customOffsets$offset = customOffsets == null ? void 0 : customOffsets.offsetX) != null ? _customOffsets$offset : event.offsetX;
128
+ const offsetY = (_customOffsets$offset2 = customOffsets == null ? void 0 : customOffsets.offsetY) != null ? _customOffsets$offset2 : event.offsetY;
129
+ const width = (_customOffsets$width = customOffsets == null ? void 0 : customOffsets.width) != null ? _customOffsets$width : size.width;
130
+ const height = (_customOffsets$height = customOffsets == null ? void 0 : customOffsets.height) != null ? _customOffsets$height : size.height;
136
131
  mouse.set(offsetX / width * 2 - 1, -(offsetY / height) * 2 + 1);
137
132
  raycaster.setFromCamera(mouse, camera);
138
133
  }
@@ -629,29 +624,29 @@ function createRenderer(roots) {
629
624
  localState.eventCount = Object.keys(localState.handlers).length;
630
625
  } // Special treatment for objects with support for set/copy, and layers
631
626
  else if (targetProp && targetProp.set && (targetProp.copy || targetProp instanceof THREE__namespace.Layers)) {
632
- // If value is an array
633
- if (Array.isArray(value)) {
634
- if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
635
- } // Test again target.copy(class) next ...
636
- else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) targetProp.copy(value); // If nothing else fits, just set the single value, ignore undefined
637
- // https://github.com/pmndrs/react-three-fiber/issues/274
638
- else if (value !== undefined) {
639
- const isColor = targetProp instanceof THREE__namespace.Color; // Allow setting array scalars
640
-
641
- if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
642
- else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
643
- else targetProp.set(value); // Auto-convert sRGB colors, for now ...
644
- // https://github.com/pmndrs/react-three-fiber/issues/344
645
-
646
- if (!isLinear && isColor) targetProp.convertSRGBToLinear();
647
- } // Else, just overwrite the value
648
-
649
- } else {
650
- currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
627
+ // If value is an array
628
+ if (Array.isArray(value)) {
629
+ if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
630
+ } // Test again target.copy(class) next ...
631
+ else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) targetProp.copy(value); // If nothing else fits, just set the single value, ignore undefined
632
+ // https://github.com/pmndrs/react-three-fiber/issues/274
633
+ else if (value !== undefined) {
634
+ const isColor = targetProp instanceof THREE__namespace.Color; // Allow setting array scalars
635
+
636
+ if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
637
+ else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
638
+ else targetProp.set(value); // Auto-convert sRGB colors, for now ...
651
639
  // https://github.com/pmndrs/react-three-fiber/issues/344
652
640
 
653
- if (!isLinear && currentInstance[key] instanceof THREE__namespace.Texture) currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
654
- }
641
+ if (!isLinear && isColor) targetProp.convertSRGBToLinear();
642
+ } // Else, just overwrite the value
643
+
644
+ } else {
645
+ currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
646
+ // https://github.com/pmndrs/react-three-fiber/issues/344
647
+
648
+ if (!isLinear && currentInstance[key] instanceof THREE__namespace.Texture) currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
649
+ }
655
650
 
656
651
  invalidateInstance(instance);
657
652
  });
@@ -792,8 +787,13 @@ function createRenderer(roots) {
792
787
 
793
788
  if (child) {
794
789
  if (child.attachArray) {
795
- const array = parentInstance[child.attachArray];
796
- if (!is.arr(array)) parentInstance[child.attachArray] = [];
790
+ let array = parentInstance[child.attachArray];
791
+
792
+ if (!is.arr(array)) {
793
+ parentInstance[child.attachArray] = [];
794
+ array = parentInstance[child.attachArray];
795
+ }
796
+
797
797
  array.splice(array.indexOf(beforeChild), 0, child);
798
798
  } else if (child.attachObject || child.attach && !is.fun(child.attach)) {
799
799
  // attach and attachObject don't have an order anyway, so just append
@@ -945,7 +945,7 @@ function createRenderer(roots) {
945
945
  });
946
946
  }
947
947
 
948
- const reconciler = Reconciler__default['default']({
948
+ const reconciler = Reconciler__default["default"]({
949
949
  now: scheduler.unstable_now,
950
950
  createInstance,
951
951
  removeChild,
@@ -1059,9 +1059,7 @@ function createRenderer(roots) {
1059
1059
  return !!localState.handlers;
1060
1060
  },
1061
1061
 
1062
- commitMount(instance)
1063
- /*, type, props*/
1064
- {
1062
+ commitMount(instance) {
1065
1063
  var _instance$__r3f8;
1066
1064
 
1067
1065
  // https://github.com/facebook/react/issues/20271
@@ -1139,7 +1137,7 @@ const createStore = (applyProps, invalidate, advance, props) => {
1139
1137
  clock.elapsedTime = 0;
1140
1138
  }
1141
1139
 
1142
- const rootState = create__default['default']((set, get) => {
1140
+ const rootState = create__default["default"]((set, get) => {
1143
1141
  // Create custom raycaster
1144
1142
  const raycaster = new THREE__namespace.Raycaster();
1145
1143
  const {
@@ -1573,10 +1571,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
1573
1571
  events,
1574
1572
  ...props
1575
1573
  }, forwardedRef) {
1574
+ const onPointerMissed = useMemoizedFn(props.onPointerMissed);
1576
1575
  const [containerRef, {
1577
1576
  width,
1578
1577
  height
1579
- }] = useMeasure__default['default']({
1578
+ }] = useMeasure__default["default"]({
1580
1579
  scroll: true,
1581
1580
  debounce: {
1582
1581
  scroll: 50,
@@ -1605,10 +1604,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
1605
1604
  width,
1606
1605
  height
1607
1606
  },
1607
+ onPointerMissed,
1608
1608
  events: events || createPointerEvents
1609
1609
  });
1610
1610
  }
1611
- }, [width, height, children]);
1611
+ }, [width, height, children, onPointerMissed]);
1612
1612
  useIsomorphicLayoutEffect(() => {
1613
1613
  const container = canvasRef.current;
1614
1614
  return () => unmountComponentAtNode(container);
@@ -1626,7 +1626,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
1626
1626
  ...style
1627
1627
  }
1628
1628
  }, /*#__PURE__*/React__namespace.createElement("canvas", {
1629
- ref: mergeRefs__default['default']([canvasRef, forwardedRef]),
1629
+ ref: mergeRefs__default["default"]([canvasRef, forwardedRef]),
1630
1630
  style: {
1631
1631
  display: 'block'
1632
1632
  }
@@ -1689,6 +1689,11 @@ function loadingFn(extensions, onProgress) {
1689
1689
  };
1690
1690
  }
1691
1691
 
1692
+ function useMemoizedFn(fn) {
1693
+ const fnRef = React__namespace.useRef(fn);
1694
+ React__namespace.useLayoutEffect(() => void (fnRef.current = fn), [fn]);
1695
+ return (...args) => fnRef.current == null ? void 0 : fnRef.current(...args);
1696
+ }
1692
1697
  function useLoader(Proto, input, extensions, onProgress) {
1693
1698
  // Use suspense to load async assets
1694
1699
  const keys = Array.isArray(input) ? input : [input];
@@ -1874,8 +1879,7 @@ function dispose(obj) {
1874
1879
  if (obj.dispose && obj.type !== 'Scene') obj.dispose();
1875
1880
 
1876
1881
  for (const p in obj) {
1877
- var _dispose, _ref;
1878
- (_dispose = (_ref = p).dispose) == null ? void 0 : _dispose.call(_ref);
1882
+ p.dispose == null ? void 0 : p.dispose();
1879
1883
  delete obj[p];
1880
1884
  }
1881
1885
  }
@@ -1913,5 +1917,6 @@ exports.unmountComponentAtNode = unmountComponentAtNode;
1913
1917
  exports.useFrame = useFrame;
1914
1918
  exports.useGraph = useGraph;
1915
1919
  exports.useLoader = useLoader;
1920
+ exports.useMemoizedFn = useMemoizedFn;
1916
1921
  exports.useStore = useStore;
1917
1922
  exports.useThree = useThree;