@react-three/fiber 8.0.22 → 8.0.25

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.
@@ -173,7 +173,7 @@ function prepare(object, state) {
173
173
  eventCount: 0,
174
174
  handlers: {},
175
175
  objects: [],
176
- parents: [],
176
+ parent: null,
177
177
  ...state
178
178
  };
179
179
  }
@@ -287,7 +287,7 @@ function diffProps(instance, {
287
287
  } // This function applies a set of changes to the instance
288
288
 
289
289
  function applyProps$1(instance, data) {
290
- var _instance$__r3f3, _root$getState, _localState$parents;
290
+ var _instance$__r3f3, _root$getState;
291
291
 
292
292
  // Filter equals, events and reserved props
293
293
  const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
@@ -378,7 +378,7 @@ function applyProps$1(instance, data) {
378
378
  invalidateInstance(instance);
379
379
  });
380
380
 
381
- if ((_localState$parents = localState.parents) != null && _localState$parents.length && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
381
+ if (localState.parent && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
382
382
  // Pre-emptively remove the instance from the interaction manager
383
383
  const index = rootState.internal.interaction.indexOf(instance);
384
384
  if (index > -1) rootState.internal.interaction.splice(index, 1); // Add the instance to the interaction manager only when it has handlers
@@ -871,7 +871,7 @@ function createRenderer(roots, getEventPriority) {
871
871
  if (type === 'primitive') {
872
872
  if (props.object === undefined) throw `Primitives without 'object' are invalid!`;
873
873
  const object = props.object;
874
- instance = prepare(object, { ...object.__r3f,
874
+ instance = prepare(object, {
875
875
  type,
876
876
  root,
877
877
  attach,
@@ -913,9 +913,10 @@ function createRenderer(roots, getEventPriority) {
913
913
  if (child) {
914
914
  var _child$__r3f, _parentInstance$__r3f;
915
915
 
916
- // The attach attribute implies that the object attaches itself on the parent.
917
- // That is handled at commit to avoid duplication during Suspense
918
- if (!((_child$__r3f = child.__r3f) != null && _child$__r3f.attach) && child.isObject3D && parentInstance.isObject3D) {
916
+ // The attach attribute implies that the object attaches itself on the parent
917
+ if ((_child$__r3f = child.__r3f) != null && _child$__r3f.attach) {
918
+ attach(parentInstance, child, child.__r3f.attach);
919
+ } else if (child.isObject3D && parentInstance.isObject3D) {
919
920
  // add in the usual parent-child way
920
921
  parentInstance.add(child);
921
922
  added = true;
@@ -925,9 +926,7 @@ function createRenderer(roots, getEventPriority) {
925
926
 
926
927
  if (!added) (_parentInstance$__r3f = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f.objects.push(child);
927
928
  if (!child.__r3f) prepare(child, {});
928
-
929
- child.__r3f.parents.push(parentInstance);
930
-
929
+ child.__r3f.parent = parentInstance;
931
930
  updateInstance(child);
932
931
  invalidateInstance(child);
933
932
  }
@@ -939,7 +938,9 @@ function createRenderer(roots, getEventPriority) {
939
938
  if (child) {
940
939
  var _child$__r3f2, _parentInstance$__r3f2;
941
940
 
942
- if (!((_child$__r3f2 = child.__r3f) != null && _child$__r3f2.attach) && child.isObject3D && parentInstance.isObject3D) {
941
+ if ((_child$__r3f2 = child.__r3f) != null && _child$__r3f2.attach) {
942
+ attach(parentInstance, child, child.__r3f.attach);
943
+ } else if (child.isObject3D && parentInstance.isObject3D) {
943
944
  child.parent = parentInstance;
944
945
  child.dispatchEvent({
945
946
  type: 'added'
@@ -952,9 +953,7 @@ function createRenderer(roots, getEventPriority) {
952
953
 
953
954
  if (!added) (_parentInstance$__r3f2 = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f2.objects.push(child);
954
955
  if (!child.__r3f) prepare(child, {});
955
-
956
- child.__r3f.parents.push(parentInstance);
957
-
956
+ child.__r3f.parent = parentInstance;
958
957
  updateInstance(child);
959
958
  invalidateInstance(child);
960
959
  }
@@ -969,7 +968,7 @@ function createRenderer(roots, getEventPriority) {
969
968
  var _parentInstance$__r3f3, _child$__r3f3, _child$__r3f5;
970
969
 
971
970
  // Clear the parent reference
972
- if (child.__r3f) child.__r3f.parents = child.__r3f.parents.filter(parent => parent !== parentInstance); // Remove child from the parents objects
971
+ if (child.__r3f) child.__r3f.parent = null; // Remove child from the parents objects
973
972
 
974
973
  if ((_parentInstance$__r3f3 = parentInstance.__r3f) != null && _parentInstance$__r3f3.objects) parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child); // Remove attachment
975
974
 
@@ -1030,10 +1029,10 @@ function createRenderer(roots, getEventPriority) {
1030
1029
  }
1031
1030
 
1032
1031
  function switchInstance(instance, type, newProps, fiber) {
1033
- var _instance$__r3f, _newInstance$__r3f;
1032
+ var _instance$__r3f;
1034
1033
 
1035
- const parents = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parents;
1036
- if (!(parents != null && parents.length)) return;
1034
+ const parent = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parent;
1035
+ if (!parent) return;
1037
1036
  const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1038
1037
  // When args change the instance has to be re-constructed, which then
1039
1038
  // forces r3f to re-parent the children and non-scene objects
@@ -1042,34 +1041,18 @@ function createRenderer(roots, getEventPriority) {
1042
1041
  if (type !== 'primitive' && instance.children) {
1043
1042
  instance.children.forEach(child => appendChild(newInstance, child));
1044
1043
  instance.children = [];
1045
- } // Copy over child attachments
1046
-
1047
-
1048
- for (const child of instance.__r3f.objects) {
1049
- appendChild(newInstance, child);
1050
- detach(instance, child, child.__r3f.attach);
1051
- attach(newInstance, child, child.__r3f.attach);
1052
1044
  }
1053
1045
 
1054
- instance.__r3f.objects = [];
1055
-
1056
- for (const parent of parents) {
1057
- removeChild(parent, instance);
1058
- appendChild(parent, newInstance);
1059
- } // Re-bind event handlers
1046
+ instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
1060
1047
 
1048
+ instance.__r3f.objects = [];
1049
+ removeChild(parent, instance);
1050
+ appendChild(parent, newInstance); // Re-bind event handlers
1061
1051
 
1062
1052
  if (newInstance.raycast && newInstance.__r3f.eventCount) {
1063
1053
  const rootState = newInstance.__r3f.root.getState();
1064
1054
 
1065
1055
  rootState.internal.interaction.push(newInstance);
1066
- } // Attach instance to parent
1067
-
1068
-
1069
- if ((_newInstance$__r3f = newInstance.__r3f) != null && _newInstance$__r3f.attach) {
1070
- for (const parent of parents) {
1071
- attach(parent, newInstance, newInstance.__r3f.attach);
1072
- }
1073
1056
  } // This evil hack switches the react-internal fiber node
1074
1057
  [fiber, fiber.alternate].forEach(fiber => {
1075
1058
  if (fiber !== null) {
@@ -1110,7 +1093,7 @@ function createRenderer(roots, getEventPriority) {
1110
1093
  const localState = (_instance$__r3f2 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f2 : {}; // https://github.com/facebook/react/issues/20271
1111
1094
  // Returning true will trigger commitMount
1112
1095
 
1113
- return !!localState.handlers || !!localState.attach;
1096
+ return !!localState.handlers;
1114
1097
  },
1115
1098
 
1116
1099
  prepareUpdate(instance, type, oldProps, newProps) {
@@ -1156,13 +1139,6 @@ function createRenderer(roots, getEventPriority) {
1156
1139
 
1157
1140
  if (instance.raycast && localState.handlers && localState.eventCount) {
1158
1141
  instance.__r3f.root.getState().internal.interaction.push(instance);
1159
- } // The attach attribute implies that the object attaches itself on the parent
1160
-
1161
-
1162
- if (localState.attach) {
1163
- for (const parent of localState.parents) {
1164
- attach(parent, instance, localState.attach);
1165
- }
1166
1142
  }
1167
1143
  },
1168
1144
 
@@ -1176,11 +1152,27 @@ function createRenderer(roots, getEventPriority) {
1176
1152
  detachDeletedInstance: () => {},
1177
1153
 
1178
1154
  hideInstance(instance) {
1155
+ var _instance$__r3f4;
1156
+
1157
+ // Deatch while the instance is hidden
1158
+ const {
1159
+ attach: type,
1160
+ parent
1161
+ } = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1162
+ if (type && parent) detach(parent, instance, type);
1179
1163
  if (instance.isObject3D) instance.visible = false;
1180
1164
  invalidateInstance(instance);
1181
1165
  },
1182
1166
 
1183
1167
  unhideInstance(instance, props) {
1168
+ var _instance$__r3f5;
1169
+
1170
+ // Re-attach when the instance is unhidden
1171
+ const {
1172
+ attach: type,
1173
+ parent
1174
+ } = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1175
+ if (type && parent) attach(parent, instance, type);
1184
1176
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1185
1177
  invalidateInstance(instance);
1186
1178
  },
@@ -1417,6 +1409,23 @@ const createStore = (invalidate, advance) => {
1417
1409
  oldSize = size;
1418
1410
  oldDpr = viewport.dpr;
1419
1411
  }
1412
+ }); // Update viewport once the camera changes
1413
+
1414
+ let oldCamera = state.camera;
1415
+ rootState.subscribe(() => {
1416
+ const {
1417
+ camera,
1418
+ set
1419
+ } = rootState.getState();
1420
+
1421
+ if (camera !== oldCamera) {
1422
+ set(state => ({
1423
+ viewport: { ...state.viewport,
1424
+ ...state.viewport.getCurrentViewport(camera)
1425
+ }
1426
+ }));
1427
+ oldCamera = camera;
1428
+ }
1420
1429
  }); // Invalidate on any change
1421
1430
 
1422
1431
  rootState.subscribe(state => invalidate(state)); // Return root state
@@ -1605,13 +1614,14 @@ function loadingFn(extensions, onProgress) {
1605
1614
  }, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
1606
1615
  };
1607
1616
  }
1608
-
1609
1617
  /**
1610
1618
  * Synchronously loads and caches assets with a three loader.
1611
1619
  *
1612
1620
  * Note: this hook's caller must be wrapped with `React.Suspense`
1613
1621
  * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1614
1622
  */
1623
+
1624
+
1615
1625
  function useLoader(Proto, input, extensions, onProgress) {
1616
1626
  // Use suspense to load async assets
1617
1627
  const keys = Array.isArray(input) ? input : [input];
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-8ec72a6b.cjs.dev.js');
5
+ var index = require('./index-63f47889.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-b47473f2.cjs.prod.js');
5
+ var index = require('./index-cd0062f1.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 createRoot, E as ErrorBoundary, B as Block, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-f1b43982.esm.js';
2
- export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from './index-f1b43982.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-8d5cf4a3.esm.js';
2
+ export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from './index-8d5cf4a3.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-8ec72a6b.cjs.dev.js');
5
+ var index = require('../../dist/index-63f47889.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-b47473f2.cjs.prod.js');
5
+ var index = require('../../dist/index-cd0062f1.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 createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-f1b43982.esm.js';
2
- export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from '../../dist/index-f1b43982.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-8d5cf4a3.esm.js';
2
+ export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from '../../dist/index-8d5cf4a3.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.0.22",
3
+ "version": "8.0.25",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",