@react-three/fiber 8.15.13 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @react-three/fiber
2
2
 
3
+ ## 8.15.14
4
+
5
+ ### Patch Changes
6
+
7
+ - 0afc9c12: fix: portal events, update examples
8
+
3
9
  ## 8.15.13
4
10
 
5
11
  ### Patch Changes
@@ -127,7 +127,7 @@ export declare type RootState = {
127
127
  setFrameloop: (frameloop?: 'always' | 'demand' | 'never') => void;
128
128
  /** When the canvas was clicked but nothing was hit */
129
129
  onPointerMissed?: (event: MouseEvent) => void;
130
- /** If this state model is layerd (via createPortal) then this contains the previous layer */
130
+ /** If this state model is layered (via createPortal) then this contains the previous layer */
131
131
  previousRoot?: UseBoundStore<RootState, StoreApi<RootState>>;
132
132
  /** Internals */
133
133
  internal: InternalState;
@@ -1,6 +1,7 @@
1
1
  /// <reference types="webxr" />
2
2
  import * as THREE from 'three';
3
3
  import * as React from 'react';
4
+ import { UseBoundStore } from 'zustand';
4
5
  import { AttachType, Instance, InstanceProps, LocalState } from './renderer';
5
6
  import { Dpr, Renderer, RootState, Size } from './store';
6
7
  /** @ts-ignore */
@@ -85,6 +86,10 @@ export declare function calculateDpr(dpr: Dpr): number;
85
86
  * Returns instance root state
86
87
  */
87
88
  export declare const getRootState: (obj: THREE.Object3D) => RootState | undefined;
89
+ /**
90
+ * Returns the instances initial (outmost) root
91
+ */
92
+ export declare function findInitialRoot(child: Instance): UseBoundStore<RootState, import("zustand").StoreApi<RootState>>;
88
93
  export declare type EquConfig = {
89
94
  /** Compare arrays by reference equality a === b (default), or by shallow equality */
90
95
  arrays?: 'reference' | 'shallow';
@@ -123,9 +123,10 @@ function createRenderer(_roots, _getEventPriority) {
123
123
  } else if (child.isObject3D && parentInstance.isObject3D) {
124
124
  var _child$__r3f4;
125
125
  parentInstance.remove(child);
126
- // Remove interactivity
126
+ // @ts-ignore
127
+ // Remove interactivity on the initial root
127
128
  if ((_child$__r3f4 = child.__r3f) != null && _child$__r3f4.root) {
128
- removeInteractivity(child.__r3f.root, child);
129
+ removeInteractivity(findInitialRoot(child), child);
129
130
  }
130
131
  }
131
132
 
@@ -197,9 +198,9 @@ function createRenderer(_roots, _getEventPriority) {
197
198
  }
198
199
  appendChild(parent, newInstance);
199
200
 
200
- // Re-bind event handlers
201
+ // Re-bind event handlers on the initial root
201
202
  if (newInstance.raycast && newInstance.__r3f.eventCount) {
202
- const rootState = newInstance.__r3f.root.getState();
203
+ const rootState = findInitialRoot(newInstance).getState();
203
204
  rootState.internal.interaction.push(newInstance);
204
205
  }
205
206
  [fiber, fiber.alternate].forEach(fiber => {
@@ -299,10 +300,10 @@ function createRenderer(_roots, _getEventPriority) {
299
300
  commitMount(instance, _type, _props, _int) {
300
301
  var _instance$__r3f4;
301
302
  // https://github.com/facebook/react/issues/20271
302
- // This will make sure events are only added once to the central container
303
+ // This will make sure events are only added once to the central container on the initial root
303
304
  const localState = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
304
305
  if (instance.raycast && localState.handlers && localState.eventCount) {
305
- instance.__r3f.root.getState().internal.interaction.push(instance);
306
+ findInitialRoot(instance).getState().internal.interaction.push(instance);
306
307
  }
307
308
  },
308
309
  getPublicInstance: instance => instance,
@@ -427,6 +428,15 @@ const getRootState = obj => {
427
428
  var _r3f;
428
429
  return (_r3f = obj.__r3f) == null ? void 0 : _r3f.root.getState();
429
430
  };
431
+
432
+ /**
433
+ * Returns the instances initial (outmost) root
434
+ */
435
+ function findInitialRoot(child) {
436
+ let root = child.__r3f.root;
437
+ while (root.getState().previousRoot) root = root.getState().previousRoot;
438
+ return root;
439
+ }
430
440
  // A collection of compare functions
431
441
  const is = {
432
442
  obj: a => a === Object(a) && !is.arr(a) && typeof a !== 'function',
@@ -744,12 +754,14 @@ function applyProps$1(instance, data) {
744
754
  }
745
755
  invalidateInstance(instance);
746
756
  }
747
- if (localState.parent && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
757
+ if (localState.parent && instance.raycast && prevHandlers !== localState.eventCount) {
758
+ // Get the initial root state's internals
759
+ const internal = findInitialRoot(instance).getState().internal;
748
760
  // Pre-emptively remove the instance from the interaction manager
749
- const index = rootState.internal.interaction.indexOf(instance);
750
- if (index > -1) rootState.internal.interaction.splice(index, 1);
761
+ const index = internal.interaction.indexOf(instance);
762
+ if (index > -1) internal.interaction.splice(index, 1);
751
763
  // Add the instance to the interaction manager only when it has handlers
752
- if (localState.eventCount) rootState.internal.interaction.push(instance);
764
+ if (localState.eventCount) internal.interaction.push(instance);
753
765
  }
754
766
 
755
767
  // Call the update lifecycle when it is being updated, but only when it is part of the scene.
@@ -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,
@@ -454,6 +455,15 @@ 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',
@@ -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.
@@ -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,
@@ -454,6 +455,15 @@ 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',
@@ -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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-0ee5ddc9.cjs.dev.js');
5
+ var index = require('./index-54c0bb16.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-2003c0bb.cjs.prod.js');
5
+ var index = require('./index-8eb7ac4a.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-710fb441.esm.js';
2
- export { t as ReactThreeFiber, x as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, w as buildGraph, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, C as useFrame, D as useGraph, y as useInstanceHandle, F as useLoader, z as useStore, A as useThree } from './index-710fb441.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-29b7121b.esm.js';
2
+ export { t as ReactThreeFiber, x as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, w as buildGraph, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, C as useFrame, D as useGraph, y as useInstanceHandle, F as useLoader, z as useStore, A as useThree } from './index-29b7121b.esm.js';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-0ee5ddc9.cjs.dev.js');
5
+ var index = require('../../dist/index-54c0bb16.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-2003c0bb.cjs.prod.js');
5
+ var index = require('../../dist/index-8eb7ac4a.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-710fb441.esm.js';
2
- export { t as ReactThreeFiber, x as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, w as buildGraph, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, C as useFrame, D as useGraph, y as useInstanceHandle, F as useLoader, z as useStore, A as useThree } from '../../dist/index-710fb441.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-29b7121b.esm.js';
2
+ export { t as ReactThreeFiber, x as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, w as buildGraph, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, C as useFrame, D as useGraph, y as useInstanceHandle, F as useLoader, z as useStore, A as useThree } from '../../dist/index-29b7121b.esm.js';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.15.13",
3
+ "version": "8.15.14",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",