@react-three/fiber 8.15.12 → 8.15.14

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.
Files changed (28) hide show
  1. package/CHANGELOG.md +919 -907
  2. package/dist/declarations/src/core/events.d.ts +93 -93
  3. package/dist/declarations/src/core/hooks.d.ts +57 -57
  4. package/dist/declarations/src/core/index.d.ts +87 -87
  5. package/dist/declarations/src/core/loop.d.ts +33 -33
  6. package/dist/declarations/src/core/renderer.d.ts +58 -58
  7. package/dist/declarations/src/core/store.d.ts +137 -137
  8. package/dist/declarations/src/core/utils.d.ts +130 -125
  9. package/dist/declarations/src/index.d.ts +12 -12
  10. package/dist/declarations/src/native/Canvas.d.ts +14 -14
  11. package/dist/declarations/src/native/events.d.ts +5 -5
  12. package/dist/declarations/src/native/polyfills.d.ts +1 -1
  13. package/dist/declarations/src/native.d.ts +12 -12
  14. package/dist/declarations/src/three-types.d.ts +392 -392
  15. package/dist/declarations/src/web/Canvas.d.ts +24 -24
  16. package/dist/declarations/src/web/events.d.ts +5 -5
  17. package/dist/{index-5bde93f1.esm.js → index-29b7121b.esm.js} +97 -85
  18. package/dist/{index-e9909912.cjs.dev.js → index-54c0bb16.cjs.dev.js} +97 -85
  19. package/dist/{index-710e63a4.cjs.prod.js → index-8eb7ac4a.cjs.prod.js} +97 -85
  20. package/dist/react-three-fiber.cjs.dev.js +4 -4
  21. package/dist/react-three-fiber.cjs.prod.js +4 -4
  22. package/dist/react-three-fiber.esm.js +5 -5
  23. package/native/dist/react-three-fiber-native.cjs.dev.js +15 -9
  24. package/native/dist/react-three-fiber-native.cjs.prod.js +15 -9
  25. package/native/dist/react-three-fiber-native.esm.js +16 -10
  26. package/native/package.json +5 -5
  27. package/package.json +1 -1
  28. package/readme.md +253 -253
@@ -150,9 +150,10 @@ function createRenderer(_roots, _getEventPriority) {
150
150
  } else if (child.isObject3D && parentInstance.isObject3D) {
151
151
  var _child$__r3f4;
152
152
  parentInstance.remove(child);
153
- // Remove interactivity
153
+ // @ts-ignore
154
+ // Remove interactivity on the initial root
154
155
  if ((_child$__r3f4 = child.__r3f) != null && _child$__r3f4.root) {
155
- removeInteractivity(child.__r3f.root, child);
156
+ removeInteractivity(findInitialRoot(child), child);
156
157
  }
157
158
  }
158
159
 
@@ -224,9 +225,9 @@ function createRenderer(_roots, _getEventPriority) {
224
225
  }
225
226
  appendChild(parent, newInstance);
226
227
 
227
- // Re-bind event handlers
228
+ // Re-bind event handlers on the initial root
228
229
  if (newInstance.raycast && newInstance.__r3f.eventCount) {
229
- const rootState = newInstance.__r3f.root.getState();
230
+ const rootState = findInitialRoot(newInstance).getState();
230
231
  rootState.internal.interaction.push(newInstance);
231
232
  }
232
233
  [fiber, fiber.alternate].forEach(fiber => {
@@ -326,10 +327,10 @@ function createRenderer(_roots, _getEventPriority) {
326
327
  commitMount(instance, _type, _props, _int) {
327
328
  var _instance$__r3f4;
328
329
  // https://github.com/facebook/react/issues/20271
329
- // This will make sure events are only added once to the central container
330
+ // This will make sure events are only added once to the central container on the initial root
330
331
  const localState = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
331
332
  if (instance.raycast && localState.handlers && localState.eventCount) {
332
- instance.__r3f.root.getState().internal.interaction.push(instance);
333
+ findInitialRoot(instance).getState().internal.interaction.push(instance);
333
334
  }
334
335
  },
335
336
  getPublicInstance: instance => instance,
@@ -381,12 +382,12 @@ function createRenderer(_roots, _getEventPriority) {
381
382
  }
382
383
 
383
384
  var _window$document, _window$navigator;
384
- /**
385
- * Returns `true` with correct TS type inference if an object has a configurable color space (since r152).
385
+ /**
386
+ * Returns `true` with correct TS type inference if an object has a configurable color space (since r152).
386
387
  */
387
388
  const hasColorSpace = object => 'colorSpace' in object || 'outputColorSpace' in object;
388
- /**
389
- * The current THREE.ColorManagement instance, if present.
389
+ /**
390
+ * The current THREE.ColorManagement instance, if present.
390
391
  */
391
392
  const getColorManagement = () => {
392
393
  var _ColorManagement;
@@ -395,14 +396,14 @@ const getColorManagement = () => {
395
396
  const isOrthographicCamera = def => def && def.isOrthographicCamera;
396
397
  const isRef = obj => obj && obj.hasOwnProperty('current');
397
398
 
398
- /**
399
- * An SSR-friendly useLayoutEffect.
400
- *
401
- * React currently throws a warning when using useLayoutEffect on the server.
402
- * To get around it, we can conditionally useEffect on the server (no-op) and
403
- * useLayoutEffect elsewhere.
404
- *
405
- * @see https://github.com/facebook/react/issues/14927
399
+ /**
400
+ * An SSR-friendly useLayoutEffect.
401
+ *
402
+ * React currently throws a warning when using useLayoutEffect on the server.
403
+ * To get around it, we can conditionally useEffect on the server (no-op) and
404
+ * useLayoutEffect elsewhere.
405
+ *
406
+ * @see https://github.com/facebook/react/issues/14927
406
407
  */
407
408
  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__namespace.useLayoutEffect : React__namespace.useEffect;
408
409
  function useMutableCallback(fn) {
@@ -447,13 +448,22 @@ function calculateDpr(dpr) {
447
448
  return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
448
449
  }
449
450
 
450
- /**
451
- * Returns instance root state
451
+ /**
452
+ * Returns instance root state
452
453
  */
453
454
  const getRootState = obj => {
454
455
  var _r3f;
455
456
  return (_r3f = obj.__r3f) == null ? void 0 : _r3f.root.getState();
456
457
  };
458
+
459
+ /**
460
+ * Returns the instances initial (outmost) root
461
+ */
462
+ function findInitialRoot(child) {
463
+ let root = child.__r3f.root;
464
+ while (root.getState().previousRoot) root = root.getState().previousRoot;
465
+ return root;
466
+ }
457
467
  // A collection of compare functions
458
468
  const is = {
459
469
  obj: a => a === Object(a) && !is.arr(a) && typeof a !== 'function',
@@ -504,8 +514,8 @@ const is = {
504
514
  }
505
515
  };
506
516
 
507
- /**
508
- * Collects nodes and materials from a THREE.Object3D.
517
+ /**
518
+ * Collects nodes and materials from a THREE.Object3D.
509
519
  */
510
520
  function buildGraph(object) {
511
521
  const data = {
@@ -771,12 +781,14 @@ function applyProps$1(instance, data) {
771
781
  }
772
782
  invalidateInstance(instance);
773
783
  }
774
- if (localState.parent && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
784
+ if (localState.parent && instance.raycast && prevHandlers !== localState.eventCount) {
785
+ // Get the initial root state's internals
786
+ const internal = findInitialRoot(instance).getState().internal;
775
787
  // Pre-emptively remove the instance from the interaction manager
776
- const index = rootState.internal.interaction.indexOf(instance);
777
- if (index > -1) rootState.internal.interaction.splice(index, 1);
788
+ const index = internal.interaction.indexOf(instance);
789
+ if (index > -1) internal.interaction.splice(index, 1);
778
790
  // Add the instance to the interaction manager only when it has handlers
779
- if (localState.eventCount) rootState.internal.interaction.push(instance);
791
+ if (localState.eventCount) internal.interaction.push(instance);
780
792
  }
781
793
 
782
794
  // Call the update lifecycle when it is being updated, but only when it is part of the scene.
@@ -845,9 +857,9 @@ function getEventPriority() {
845
857
  }
846
858
  }
847
859
 
848
- /**
849
- * Release pointer captures.
850
- * This is called by releasePointerCapture in the API, and when an object is removed.
860
+ /**
861
+ * Release pointer captures.
862
+ * This is called by releasePointerCapture in the API, and when an object is removed.
851
863
  */
852
864
  function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
853
865
  const captureData = captures.get(obj);
@@ -1182,19 +1194,19 @@ function createEvents(store) {
1182
1194
  // Check presence of handlers
1183
1195
  if (!(instance != null && instance.eventCount)) return;
1184
1196
 
1185
- /*
1186
- MAYBE TODO, DELETE IF NOT:
1187
- Check if the object is captured, captured events should not have intersects running in parallel
1188
- But wouldn't it be better to just replace capturedMap with a single entry?
1189
- Also, are we OK with straight up making picking up multiple objects impossible?
1190
-
1191
- const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
1192
- if (pointerId !== undefined) {
1193
- const capturedMeshSet = internal.capturedMap.get(pointerId)
1194
- if (capturedMeshSet) {
1195
- const captured = capturedMeshSet.get(eventObject)
1196
- if (captured && captured.localState.stopped) return
1197
- }
1197
+ /*
1198
+ MAYBE TODO, DELETE IF NOT:
1199
+ Check if the object is captured, captured events should not have intersects running in parallel
1200
+ But wouldn't it be better to just replace capturedMap with a single entry?
1201
+ Also, are we OK with straight up making picking up multiple objects impossible?
1202
+
1203
+ const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
1204
+ if (pointerId !== undefined) {
1205
+ const capturedMeshSet = internal.capturedMap.get(pointerId)
1206
+ if (capturedMeshSet) {
1207
+ const captured = capturedMeshSet.get(eventObject)
1208
+ if (captured && captured.localState.stopped) return
1209
+ }
1198
1210
  }*/
1199
1211
 
1200
1212
  if (isPointerMove) {
@@ -1500,21 +1512,21 @@ let globalEffects = new Set();
1500
1512
  let globalAfterEffects = new Set();
1501
1513
  let globalTailEffects = new Set();
1502
1514
 
1503
- /**
1504
- * Adds a global render callback which is called each frame.
1505
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
1515
+ /**
1516
+ * Adds a global render callback which is called each frame.
1517
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
1506
1518
  */
1507
1519
  const addEffect = callback => createSubs(callback, globalEffects);
1508
1520
 
1509
- /**
1510
- * Adds a global after-render callback which is called each frame.
1511
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
1521
+ /**
1522
+ * Adds a global after-render callback which is called each frame.
1523
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
1512
1524
  */
1513
1525
  const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
1514
1526
 
1515
- /**
1516
- * Adds a global callback which is called when rendering stops.
1517
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
1527
+ /**
1528
+ * Adds a global callback which is called when rendering stops.
1529
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
1518
1530
  */
1519
1531
  const addTail = callback => createSubs(callback, globalTailEffects);
1520
1532
  function run(effects, timestamp) {
@@ -1613,24 +1625,24 @@ function createLoop(roots) {
1613
1625
  }
1614
1626
  return {
1615
1627
  loop,
1616
- /**
1617
- * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
1618
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
1628
+ /**
1629
+ * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
1630
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
1619
1631
  */
1620
1632
  invalidate,
1621
- /**
1622
- * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
1623
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
1633
+ /**
1634
+ * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
1635
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
1624
1636
  */
1625
1637
  advance
1626
1638
  };
1627
1639
  }
1628
1640
 
1629
- /**
1630
- * Exposes an object's {@link LocalState}.
1631
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1632
- *
1633
- * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1641
+ /**
1642
+ * Exposes an object's {@link LocalState}.
1643
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1644
+ *
1645
+ * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1634
1646
  */
1635
1647
  function useInstanceHandle(ref) {
1636
1648
  const instance = React__namespace.useRef(null);
@@ -1643,18 +1655,18 @@ function useStore() {
1643
1655
  return store;
1644
1656
  }
1645
1657
 
1646
- /**
1647
- * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1648
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1658
+ /**
1659
+ * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1660
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1649
1661
  */
1650
1662
  function useThree(selector = state => state, equalityFn) {
1651
1663
  return useStore()(selector, equalityFn);
1652
1664
  }
1653
1665
 
1654
- /**
1655
- * Executes a callback before render in a shared frame loop.
1656
- * Can order effects with render priority or manually render with a positive priority.
1657
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1666
+ /**
1667
+ * Executes a callback before render in a shared frame loop.
1668
+ * Can order effects with render priority or manually render with a positive priority.
1669
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1658
1670
  */
1659
1671
  function useFrame(callback, renderPriority = 0) {
1660
1672
  const store = useStore();
@@ -1666,9 +1678,9 @@ function useFrame(callback, renderPriority = 0) {
1666
1678
  return null;
1667
1679
  }
1668
1680
 
1669
- /**
1670
- * Returns a node graph of an object with named nodes & materials.
1671
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1681
+ /**
1682
+ * Returns a node graph of an object with named nodes & materials.
1683
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1672
1684
  */
1673
1685
  function useGraph(object) {
1674
1686
  return React__namespace.useMemo(() => buildGraph(object), [object]);
@@ -1690,11 +1702,11 @@ function loadingFn(extensions, onProgress) {
1690
1702
  }, onProgress, error => reject(new Error(`Could not load ${input}: ${error == null ? void 0 : error.message}`)))))).finally(() => loader.dispose == null ? void 0 : loader.dispose());
1691
1703
  };
1692
1704
  }
1693
- /**
1694
- * Synchronously loads and caches assets with a three loader.
1695
- *
1696
- * Note: this hook's caller must be wrapped with `React.Suspense`
1697
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1705
+ /**
1706
+ * Synchronously loads and caches assets with a three loader.
1707
+ *
1708
+ * Note: this hook's caller must be wrapped with `React.Suspense`
1709
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1698
1710
  */
1699
1711
  function useLoader(Proto, input, extensions, onProgress) {
1700
1712
  // Use suspense to load async assets
@@ -1706,16 +1718,16 @@ function useLoader(Proto, input, extensions, onProgress) {
1706
1718
  return Array.isArray(input) ? results : results[0];
1707
1719
  }
1708
1720
 
1709
- /**
1710
- * Preloads an asset into cache as a side-effect.
1721
+ /**
1722
+ * Preloads an asset into cache as a side-effect.
1711
1723
  */
1712
1724
  useLoader.preload = function (Proto, input, extensions) {
1713
1725
  const keys = Array.isArray(input) ? input : [input];
1714
1726
  return suspendReact.preload(loadingFn(extensions), [Proto, ...keys]);
1715
1727
  };
1716
1728
 
1717
- /**
1718
- * Removes a loaded asset from cache.
1729
+ /**
1730
+ * Removes a loaded asset from cache.
1719
1731
  */
1720
1732
  useLoader.clear = function (Proto, input) {
1721
1733
  const keys = Array.isArray(input) ? input : [input];
@@ -2111,10 +2123,10 @@ function Portal({
2111
2123
  children,
2112
2124
  container
2113
2125
  }) {
2114
- /** This has to be a component because it would not be able to call useThree/useStore otherwise since
2115
- * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
2116
- * the "R3F hooks can only be used within the Canvas component!" warning:
2117
- * <Canvas>
2126
+ /** This has to be a component because it would not be able to call useThree/useStore otherwise since
2127
+ * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
2128
+ * the "R3F hooks can only be used within the Canvas component!" warning:
2129
+ * <Canvas>
2118
2130
  * {createPortal(...)} */
2119
2131
  const {
2120
2132
  events,
@@ -150,9 +150,10 @@ function createRenderer(_roots, _getEventPriority) {
150
150
  } else if (child.isObject3D && parentInstance.isObject3D) {
151
151
  var _child$__r3f4;
152
152
  parentInstance.remove(child);
153
- // Remove interactivity
153
+ // @ts-ignore
154
+ // Remove interactivity on the initial root
154
155
  if ((_child$__r3f4 = child.__r3f) != null && _child$__r3f4.root) {
155
- removeInteractivity(child.__r3f.root, child);
156
+ removeInteractivity(findInitialRoot(child), child);
156
157
  }
157
158
  }
158
159
 
@@ -224,9 +225,9 @@ function createRenderer(_roots, _getEventPriority) {
224
225
  }
225
226
  appendChild(parent, newInstance);
226
227
 
227
- // Re-bind event handlers
228
+ // Re-bind event handlers on the initial root
228
229
  if (newInstance.raycast && newInstance.__r3f.eventCount) {
229
- const rootState = newInstance.__r3f.root.getState();
230
+ const rootState = findInitialRoot(newInstance).getState();
230
231
  rootState.internal.interaction.push(newInstance);
231
232
  }
232
233
  [fiber, fiber.alternate].forEach(fiber => {
@@ -326,10 +327,10 @@ function createRenderer(_roots, _getEventPriority) {
326
327
  commitMount(instance, _type, _props, _int) {
327
328
  var _instance$__r3f4;
328
329
  // https://github.com/facebook/react/issues/20271
329
- // This will make sure events are only added once to the central container
330
+ // This will make sure events are only added once to the central container on the initial root
330
331
  const localState = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
331
332
  if (instance.raycast && localState.handlers && localState.eventCount) {
332
- instance.__r3f.root.getState().internal.interaction.push(instance);
333
+ findInitialRoot(instance).getState().internal.interaction.push(instance);
333
334
  }
334
335
  },
335
336
  getPublicInstance: instance => instance,
@@ -381,12 +382,12 @@ function createRenderer(_roots, _getEventPriority) {
381
382
  }
382
383
 
383
384
  var _window$document, _window$navigator;
384
- /**
385
- * Returns `true` with correct TS type inference if an object has a configurable color space (since r152).
385
+ /**
386
+ * Returns `true` with correct TS type inference if an object has a configurable color space (since r152).
386
387
  */
387
388
  const hasColorSpace = object => 'colorSpace' in object || 'outputColorSpace' in object;
388
- /**
389
- * The current THREE.ColorManagement instance, if present.
389
+ /**
390
+ * The current THREE.ColorManagement instance, if present.
390
391
  */
391
392
  const getColorManagement = () => {
392
393
  var _ColorManagement;
@@ -395,14 +396,14 @@ const getColorManagement = () => {
395
396
  const isOrthographicCamera = def => def && def.isOrthographicCamera;
396
397
  const isRef = obj => obj && obj.hasOwnProperty('current');
397
398
 
398
- /**
399
- * An SSR-friendly useLayoutEffect.
400
- *
401
- * React currently throws a warning when using useLayoutEffect on the server.
402
- * To get around it, we can conditionally useEffect on the server (no-op) and
403
- * useLayoutEffect elsewhere.
404
- *
405
- * @see https://github.com/facebook/react/issues/14927
399
+ /**
400
+ * An SSR-friendly useLayoutEffect.
401
+ *
402
+ * React currently throws a warning when using useLayoutEffect on the server.
403
+ * To get around it, we can conditionally useEffect on the server (no-op) and
404
+ * useLayoutEffect elsewhere.
405
+ *
406
+ * @see https://github.com/facebook/react/issues/14927
406
407
  */
407
408
  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__namespace.useLayoutEffect : React__namespace.useEffect;
408
409
  function useMutableCallback(fn) {
@@ -447,13 +448,22 @@ function calculateDpr(dpr) {
447
448
  return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
448
449
  }
449
450
 
450
- /**
451
- * Returns instance root state
451
+ /**
452
+ * Returns instance root state
452
453
  */
453
454
  const getRootState = obj => {
454
455
  var _r3f;
455
456
  return (_r3f = obj.__r3f) == null ? void 0 : _r3f.root.getState();
456
457
  };
458
+
459
+ /**
460
+ * Returns the instances initial (outmost) root
461
+ */
462
+ function findInitialRoot(child) {
463
+ let root = child.__r3f.root;
464
+ while (root.getState().previousRoot) root = root.getState().previousRoot;
465
+ return root;
466
+ }
457
467
  // A collection of compare functions
458
468
  const is = {
459
469
  obj: a => a === Object(a) && !is.arr(a) && typeof a !== 'function',
@@ -504,8 +514,8 @@ const is = {
504
514
  }
505
515
  };
506
516
 
507
- /**
508
- * Collects nodes and materials from a THREE.Object3D.
517
+ /**
518
+ * Collects nodes and materials from a THREE.Object3D.
509
519
  */
510
520
  function buildGraph(object) {
511
521
  const data = {
@@ -771,12 +781,14 @@ function applyProps$1(instance, data) {
771
781
  }
772
782
  invalidateInstance(instance);
773
783
  }
774
- if (localState.parent && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
784
+ if (localState.parent && instance.raycast && prevHandlers !== localState.eventCount) {
785
+ // Get the initial root state's internals
786
+ const internal = findInitialRoot(instance).getState().internal;
775
787
  // Pre-emptively remove the instance from the interaction manager
776
- const index = rootState.internal.interaction.indexOf(instance);
777
- if (index > -1) rootState.internal.interaction.splice(index, 1);
788
+ const index = internal.interaction.indexOf(instance);
789
+ if (index > -1) internal.interaction.splice(index, 1);
778
790
  // Add the instance to the interaction manager only when it has handlers
779
- if (localState.eventCount) rootState.internal.interaction.push(instance);
791
+ if (localState.eventCount) internal.interaction.push(instance);
780
792
  }
781
793
 
782
794
  // Call the update lifecycle when it is being updated, but only when it is part of the scene.
@@ -845,9 +857,9 @@ function getEventPriority() {
845
857
  }
846
858
  }
847
859
 
848
- /**
849
- * Release pointer captures.
850
- * This is called by releasePointerCapture in the API, and when an object is removed.
860
+ /**
861
+ * Release pointer captures.
862
+ * This is called by releasePointerCapture in the API, and when an object is removed.
851
863
  */
852
864
  function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
853
865
  const captureData = captures.get(obj);
@@ -1182,19 +1194,19 @@ function createEvents(store) {
1182
1194
  // Check presence of handlers
1183
1195
  if (!(instance != null && instance.eventCount)) return;
1184
1196
 
1185
- /*
1186
- MAYBE TODO, DELETE IF NOT:
1187
- Check if the object is captured, captured events should not have intersects running in parallel
1188
- But wouldn't it be better to just replace capturedMap with a single entry?
1189
- Also, are we OK with straight up making picking up multiple objects impossible?
1190
-
1191
- const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
1192
- if (pointerId !== undefined) {
1193
- const capturedMeshSet = internal.capturedMap.get(pointerId)
1194
- if (capturedMeshSet) {
1195
- const captured = capturedMeshSet.get(eventObject)
1196
- if (captured && captured.localState.stopped) return
1197
- }
1197
+ /*
1198
+ MAYBE TODO, DELETE IF NOT:
1199
+ Check if the object is captured, captured events should not have intersects running in parallel
1200
+ But wouldn't it be better to just replace capturedMap with a single entry?
1201
+ Also, are we OK with straight up making picking up multiple objects impossible?
1202
+
1203
+ const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
1204
+ if (pointerId !== undefined) {
1205
+ const capturedMeshSet = internal.capturedMap.get(pointerId)
1206
+ if (capturedMeshSet) {
1207
+ const captured = capturedMeshSet.get(eventObject)
1208
+ if (captured && captured.localState.stopped) return
1209
+ }
1198
1210
  }*/
1199
1211
 
1200
1212
  if (isPointerMove) {
@@ -1500,21 +1512,21 @@ let globalEffects = new Set();
1500
1512
  let globalAfterEffects = new Set();
1501
1513
  let globalTailEffects = new Set();
1502
1514
 
1503
- /**
1504
- * Adds a global render callback which is called each frame.
1505
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
1515
+ /**
1516
+ * Adds a global render callback which is called each frame.
1517
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
1506
1518
  */
1507
1519
  const addEffect = callback => createSubs(callback, globalEffects);
1508
1520
 
1509
- /**
1510
- * Adds a global after-render callback which is called each frame.
1511
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
1521
+ /**
1522
+ * Adds a global after-render callback which is called each frame.
1523
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
1512
1524
  */
1513
1525
  const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
1514
1526
 
1515
- /**
1516
- * Adds a global callback which is called when rendering stops.
1517
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
1527
+ /**
1528
+ * Adds a global callback which is called when rendering stops.
1529
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
1518
1530
  */
1519
1531
  const addTail = callback => createSubs(callback, globalTailEffects);
1520
1532
  function run(effects, timestamp) {
@@ -1613,24 +1625,24 @@ function createLoop(roots) {
1613
1625
  }
1614
1626
  return {
1615
1627
  loop,
1616
- /**
1617
- * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
1618
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
1628
+ /**
1629
+ * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
1630
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
1619
1631
  */
1620
1632
  invalidate,
1621
- /**
1622
- * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
1623
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
1633
+ /**
1634
+ * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
1635
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
1624
1636
  */
1625
1637
  advance
1626
1638
  };
1627
1639
  }
1628
1640
 
1629
- /**
1630
- * Exposes an object's {@link LocalState}.
1631
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1632
- *
1633
- * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1641
+ /**
1642
+ * Exposes an object's {@link LocalState}.
1643
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1644
+ *
1645
+ * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1634
1646
  */
1635
1647
  function useInstanceHandle(ref) {
1636
1648
  const instance = React__namespace.useRef(null);
@@ -1643,18 +1655,18 @@ function useStore() {
1643
1655
  return store;
1644
1656
  }
1645
1657
 
1646
- /**
1647
- * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1648
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1658
+ /**
1659
+ * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1660
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1649
1661
  */
1650
1662
  function useThree(selector = state => state, equalityFn) {
1651
1663
  return useStore()(selector, equalityFn);
1652
1664
  }
1653
1665
 
1654
- /**
1655
- * Executes a callback before render in a shared frame loop.
1656
- * Can order effects with render priority or manually render with a positive priority.
1657
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1666
+ /**
1667
+ * Executes a callback before render in a shared frame loop.
1668
+ * Can order effects with render priority or manually render with a positive priority.
1669
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1658
1670
  */
1659
1671
  function useFrame(callback, renderPriority = 0) {
1660
1672
  const store = useStore();
@@ -1666,9 +1678,9 @@ function useFrame(callback, renderPriority = 0) {
1666
1678
  return null;
1667
1679
  }
1668
1680
 
1669
- /**
1670
- * Returns a node graph of an object with named nodes & materials.
1671
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1681
+ /**
1682
+ * Returns a node graph of an object with named nodes & materials.
1683
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1672
1684
  */
1673
1685
  function useGraph(object) {
1674
1686
  return React__namespace.useMemo(() => buildGraph(object), [object]);
@@ -1690,11 +1702,11 @@ function loadingFn(extensions, onProgress) {
1690
1702
  }, onProgress, error => reject(new Error(`Could not load ${input}: ${error == null ? void 0 : error.message}`)))))).finally(() => loader.dispose == null ? void 0 : loader.dispose());
1691
1703
  };
1692
1704
  }
1693
- /**
1694
- * Synchronously loads and caches assets with a three loader.
1695
- *
1696
- * Note: this hook's caller must be wrapped with `React.Suspense`
1697
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1705
+ /**
1706
+ * Synchronously loads and caches assets with a three loader.
1707
+ *
1708
+ * Note: this hook's caller must be wrapped with `React.Suspense`
1709
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1698
1710
  */
1699
1711
  function useLoader(Proto, input, extensions, onProgress) {
1700
1712
  // Use suspense to load async assets
@@ -1706,16 +1718,16 @@ function useLoader(Proto, input, extensions, onProgress) {
1706
1718
  return Array.isArray(input) ? results : results[0];
1707
1719
  }
1708
1720
 
1709
- /**
1710
- * Preloads an asset into cache as a side-effect.
1721
+ /**
1722
+ * Preloads an asset into cache as a side-effect.
1711
1723
  */
1712
1724
  useLoader.preload = function (Proto, input, extensions) {
1713
1725
  const keys = Array.isArray(input) ? input : [input];
1714
1726
  return suspendReact.preload(loadingFn(extensions), [Proto, ...keys]);
1715
1727
  };
1716
1728
 
1717
- /**
1718
- * Removes a loaded asset from cache.
1729
+ /**
1730
+ * Removes a loaded asset from cache.
1719
1731
  */
1720
1732
  useLoader.clear = function (Proto, input) {
1721
1733
  const keys = Array.isArray(input) ? input : [input];
@@ -2111,10 +2123,10 @@ function Portal({
2111
2123
  children,
2112
2124
  container
2113
2125
  }) {
2114
- /** This has to be a component because it would not be able to call useThree/useStore otherwise since
2115
- * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
2116
- * the "R3F hooks can only be used within the Canvas component!" warning:
2117
- * <Canvas>
2126
+ /** This has to be a component because it would not be able to call useThree/useStore otherwise since
2127
+ * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
2128
+ * the "R3F hooks can only be used within the Canvas component!" warning:
2129
+ * <Canvas>
2118
2130
  * {createPortal(...)} */
2119
2131
  const {
2120
2132
  events,