@react-three/fiber 8.0.19 → 8.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @react-three/fiber
2
2
 
3
+ ## 8.0.22
4
+
5
+ ### Patch Changes
6
+
7
+ - 419e854: fix: always prepare primitives
8
+
9
+ ## 8.0.21
10
+
11
+ ### Patch Changes
12
+
13
+ - 3098b9b: fix: resizing in worker contexts, copy over attachments on reconstruct
14
+
15
+ ## 8.0.20
16
+
17
+ ### Patch Changes
18
+
19
+ - 4c87bce: fix: attach, devtools, and perf fixes
20
+
3
21
  ## 8.0.19
4
22
 
5
23
  ### Patch Changes
@@ -12,7 +12,7 @@ export declare type LocalState = {
12
12
  type: string;
13
13
  root: UseBoundStore<RootState>;
14
14
  objects: Instance[];
15
- parent: Instance | null;
15
+ parents: Instance[];
16
16
  primitive?: boolean;
17
17
  eventCount: number;
18
18
  handlers: Partial<EventHandlers>;
@@ -17,6 +17,7 @@ export declare type Dpr = number | [min: number, max: number];
17
17
  export declare type Size = {
18
18
  width: number;
19
19
  height: number;
20
+ updateStyle?: boolean;
20
21
  };
21
22
  export declare type Viewport = Size & {
22
23
  initialDpr: number;
@@ -80,7 +81,7 @@ export declare type RootState = {
80
81
  invalidate: (frames?: number) => void;
81
82
  advance: (timestamp: number, runGlobalEffects?: boolean) => void;
82
83
  setEvents: (events: Partial<EventManager<any>>) => void;
83
- setSize: (width: number, height: number) => void;
84
+ setSize: (width: number, height: number, updateStyle?: boolean) => void;
84
85
  setDpr: (dpr: Dpr) => void;
85
86
  setFrameloop: (frameloop?: 'always' | 'demand' | 'never') => void;
86
87
  onPointerMissed?: (event: MouseEvent) => void;
@@ -173,7 +173,7 @@ function prepare(object, state) {
173
173
  eventCount: 0,
174
174
  handlers: {},
175
175
  objects: [],
176
- parent: null,
176
+ parents: [],
177
177
  ...state
178
178
  };
179
179
  }
@@ -287,10 +287,10 @@ 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;
290
+ var _instance$__r3f3, _root$getState, _localState$parents;
291
291
 
292
292
  // Filter equals, events and reserved props
293
- const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {};
293
+ const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
294
294
  const root = localState.root;
295
295
  const rootState = (_root$getState = root == null ? void 0 : root.getState == null ? void 0 : root.getState()) != null ? _root$getState : {};
296
296
  const {
@@ -378,7 +378,7 @@ function applyProps$1(instance, data) {
378
378
  invalidateInstance(instance);
379
379
  });
380
380
 
381
- if (localState.parent && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
381
+ if ((_localState$parents = localState.parents) != null && _localState$parents.length && 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
@@ -480,7 +480,6 @@ function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
480
480
 
481
481
  function removeInteractivity(store, object) {
482
482
  const {
483
- events,
484
483
  internal
485
484
  } = store.getState(); // Removes every trace of an object from the data store
486
485
 
@@ -707,14 +706,14 @@ function createEvents(store) {
707
706
  return intersections;
708
707
  }
709
708
 
710
- function cancelPointer(hits) {
709
+ function cancelPointer(intersections) {
711
710
  const {
712
711
  internal
713
712
  } = store.getState();
714
713
  Array.from(internal.hovered.values()).forEach(hoveredObj => {
715
714
  // When no objects were hit or the the hovered object wasn't found underneath the cursor
716
715
  // we call onPointerOut and delete the object from the hovered-elements map
717
- if (!hits.length || !hits.find(hit => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId)) {
716
+ if (!intersections.length || !intersections.find(hit => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId)) {
718
717
  const eventObject = hoveredObj.eventObject;
719
718
  const instance = eventObject.__r3f;
720
719
  const handlers = instance == null ? void 0 : instance.handlers;
@@ -723,7 +722,7 @@ function createEvents(store) {
723
722
  if (instance != null && instance.eventCount) {
724
723
  // Clear out intersects, they are outdated by now
725
724
  const data = { ...hoveredObj,
726
- intersections: hits || []
725
+ intersections
727
726
  };
728
727
  handlers.onPointerOut == null ? void 0 : handlers.onPointerOut(data);
729
728
  handlers.onPointerLeave == null ? void 0 : handlers.onPointerLeave(data);
@@ -872,7 +871,7 @@ function createRenderer(roots, getEventPriority) {
872
871
  if (type === 'primitive') {
873
872
  if (props.object === undefined) throw `Primitives without 'object' are invalid!`;
874
873
  const object = props.object;
875
- instance = prepare(object, {
874
+ instance = prepare(object, { ...object.__r3f,
876
875
  type,
877
876
  root,
878
877
  attach,
@@ -926,7 +925,9 @@ function createRenderer(roots, getEventPriority) {
926
925
 
927
926
  if (!added) (_parentInstance$__r3f = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f.objects.push(child);
928
927
  if (!child.__r3f) prepare(child, {});
929
- child.__r3f.parent = parentInstance;
928
+
929
+ child.__r3f.parents.push(parentInstance);
930
+
930
931
  updateInstance(child);
931
932
  invalidateInstance(child);
932
933
  }
@@ -938,9 +939,7 @@ function createRenderer(roots, getEventPriority) {
938
939
  if (child) {
939
940
  var _child$__r3f2, _parentInstance$__r3f2;
940
941
 
941
- if ((_child$__r3f2 = child.__r3f) != null && _child$__r3f2.attach) {
942
- attach(parentInstance, child, child.__r3f.attach);
943
- } else if (child.isObject3D && parentInstance.isObject3D) {
942
+ if (!((_child$__r3f2 = child.__r3f) != null && _child$__r3f2.attach) && child.isObject3D && parentInstance.isObject3D) {
944
943
  child.parent = parentInstance;
945
944
  child.dispatchEvent({
946
945
  type: 'added'
@@ -953,7 +952,9 @@ function createRenderer(roots, getEventPriority) {
953
952
 
954
953
  if (!added) (_parentInstance$__r3f2 = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f2.objects.push(child);
955
954
  if (!child.__r3f) prepare(child, {});
956
- child.__r3f.parent = parentInstance;
955
+
956
+ child.__r3f.parents.push(parentInstance);
957
+
957
958
  updateInstance(child);
958
959
  invalidateInstance(child);
959
960
  }
@@ -968,7 +969,7 @@ function createRenderer(roots, getEventPriority) {
968
969
  var _parentInstance$__r3f3, _child$__r3f3, _child$__r3f5;
969
970
 
970
971
  // Clear the parent reference
971
- if (child.__r3f) child.__r3f.parent = null; // Remove child from the parents objects
972
+ if (child.__r3f) child.__r3f.parents = child.__r3f.parents.filter(parent => parent !== parentInstance); // Remove child from the parents objects
972
973
 
973
974
  if ((_parentInstance$__r3f3 = parentInstance.__r3f) != null && _parentInstance$__r3f3.objects) parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child); // Remove attachment
974
975
 
@@ -1029,11 +1030,11 @@ function createRenderer(roots, getEventPriority) {
1029
1030
  }
1030
1031
 
1031
1032
  function switchInstance(instance, type, newProps, fiber) {
1032
- var _instance$__r3f, _instance$__r3f2, _newInstance$__r3f;
1033
+ var _instance$__r3f, _newInstance$__r3f;
1033
1034
 
1034
- const parent = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parent;
1035
- if (!parent) return;
1036
- const newInstance = createInstance(type, newProps, (_instance$__r3f2 = instance.__r3f) == null ? void 0 : _instance$__r3f2.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1035
+ const parents = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parents;
1036
+ if (!(parents != null && parents.length)) return;
1037
+ const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1037
1038
  // When args change the instance has to be re-constructed, which then
1038
1039
  // forces r3f to re-parent the children and non-scene objects
1039
1040
  // This can not include primitives, which should not have declarative children
@@ -1041,23 +1042,34 @@ function createRenderer(roots, getEventPriority) {
1041
1042
  if (type !== 'primitive' && instance.children) {
1042
1043
  instance.children.forEach(child => appendChild(newInstance, child));
1043
1044
  instance.children = [];
1044
- }
1045
+ } // Copy over child attachments
1046
+
1045
1047
 
1046
- instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
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
+ }
1047
1053
 
1048
1054
  instance.__r3f.objects = [];
1049
- removeChild(parent, instance);
1050
- appendChild(parent, newInstance); // Re-bind event handlers
1055
+
1056
+ for (const parent of parents) {
1057
+ removeChild(parent, instance);
1058
+ appendChild(parent, newInstance);
1059
+ } // Re-bind event handlers
1060
+
1051
1061
 
1052
1062
  if (newInstance.raycast && newInstance.__r3f.eventCount) {
1053
1063
  const rootState = newInstance.__r3f.root.getState();
1054
1064
 
1055
1065
  rootState.internal.interaction.push(newInstance);
1056
- } // The attach attribute implies that the object attaches itself on the parent
1066
+ } // Attach instance to parent
1057
1067
 
1058
1068
 
1059
1069
  if ((_newInstance$__r3f = newInstance.__r3f) != null && _newInstance$__r3f.attach) {
1060
- attach(parent, newInstance, newInstance.__r3f.attach);
1070
+ for (const parent of parents) {
1071
+ attach(parent, newInstance, newInstance.__r3f.attach);
1072
+ }
1061
1073
  } // This evil hack switches the react-internal fiber node
1062
1074
  [fiber, fiber.alternate].forEach(fiber => {
1063
1075
  if (fiber !== null) {
@@ -1093,9 +1105,9 @@ function createRenderer(roots, getEventPriority) {
1093
1105
  getChildHostContext: parentHostContext => parentHostContext,
1094
1106
 
1095
1107
  finalizeInitialChildren(instance) {
1096
- var _instance$__r3f3;
1108
+ var _instance$__r3f2;
1097
1109
 
1098
- const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {}; // https://github.com/facebook/react/issues/20271
1110
+ const localState = (_instance$__r3f2 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f2 : {}; // https://github.com/facebook/react/issues/20271
1099
1111
  // Returning true will trigger commitMount
1100
1112
 
1101
1113
  return !!localState.handlers || !!localState.attach;
@@ -1136,11 +1148,11 @@ function createRenderer(roots, getEventPriority) {
1136
1148
  },
1137
1149
 
1138
1150
  commitMount(instance, type, props, int) {
1139
- var _instance$__r3f4;
1151
+ var _instance$__r3f3;
1140
1152
 
1141
1153
  // https://github.com/facebook/react/issues/20271
1142
1154
  // This will make sure events are only added once to the central container
1143
- const localState = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1155
+ const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
1144
1156
 
1145
1157
  if (instance.raycast && localState.handlers && localState.eventCount) {
1146
1158
  instance.__r3f.root.getState().internal.interaction.push(instance);
@@ -1148,7 +1160,9 @@ function createRenderer(roots, getEventPriority) {
1148
1160
 
1149
1161
 
1150
1162
  if (localState.attach) {
1151
- attach(localState.parent, instance, localState.attach);
1163
+ for (const parent of localState.parents) {
1164
+ attach(parent, instance, localState.attach);
1165
+ }
1152
1166
  }
1153
1167
  },
1154
1168
 
@@ -1286,7 +1300,8 @@ const createStore = (invalidate, advance) => {
1286
1300
  },
1287
1301
  size: {
1288
1302
  width: 0,
1289
- height: 0
1303
+ height: 0,
1304
+ updateStyle: false
1290
1305
  },
1291
1306
  viewport: {
1292
1307
  initialDpr: 0,
@@ -1303,11 +1318,12 @@ const createStore = (invalidate, advance) => {
1303
1318
  ...events
1304
1319
  }
1305
1320
  })),
1306
- setSize: (width, height) => {
1321
+ setSize: (width, height, updateStyle) => {
1307
1322
  const camera = get().camera;
1308
1323
  const size = {
1309
1324
  width,
1310
- height
1325
+ height,
1326
+ updateStyle
1311
1327
  };
1312
1328
  set(state => ({
1313
1329
  size,
@@ -1353,35 +1369,29 @@ const createStore = (invalidate, advance) => {
1353
1369
  initialHits: [],
1354
1370
  capturedMap: new Map(),
1355
1371
  subscribe: (ref, priority, store) => {
1356
- set(({
1357
- internal
1358
- }) => ({
1359
- internal: { ...internal,
1360
- // If this subscription was given a priority, it takes rendering into its own hands
1361
- // For that reason we switch off automatic rendering and increase the manual flag
1362
- // As long as this flag is positive there can be no internal rendering at all
1363
- // because there could be multiple render subscriptions
1364
- priority: internal.priority + (priority > 0 ? 1 : 0),
1365
- // Register subscriber and sort layers from lowest to highest, meaning,
1366
- // highest priority renders last (on top of the other frames)
1367
- subscribers: [...internal.subscribers, {
1368
- ref,
1369
- priority,
1370
- store
1371
- }].sort((a, b) => a.priority - b.priority)
1372
- }
1373
- }));
1372
+ const internal = get().internal; // If this subscription was given a priority, it takes rendering into its own hands
1373
+ // For that reason we switch off automatic rendering and increase the manual flag
1374
+ // As long as this flag is positive there can be no internal rendering at all
1375
+ // because there could be multiple render subscriptions
1376
+
1377
+ internal.priority = internal.priority + (priority > 0 ? 1 : 0);
1378
+ internal.subscribers.push({
1379
+ ref,
1380
+ priority,
1381
+ store
1382
+ }); // Register subscriber and sort layers from lowest to highest, meaning,
1383
+ // highest priority renders last (on top of the other frames)
1384
+
1385
+ internal.subscribers = internal.subscribers.sort((a, b) => a.priority - b.priority);
1374
1386
  return () => {
1375
- set(({
1376
- internal
1377
- }) => ({
1378
- internal: { ...internal,
1379
- // Decrease manual flag if this subscription had a priority
1380
- priority: internal.priority - (priority > 0 ? 1 : 0),
1381
- // Remove subscriber from list
1382
- subscribers: internal.subscribers.filter(s => s.ref !== ref)
1383
- }
1384
- }));
1387
+ const internal = get().internal;
1388
+
1389
+ if (internal != null && internal.subscribers) {
1390
+ // Decrease manual flag if this subscription had a priority
1391
+ internal.priority = internal.priority - (priority > 0 ? 1 : 0); // Remove subscriber from list
1392
+
1393
+ internal.subscribers = internal.subscribers.filter(s => s.ref !== ref);
1394
+ }
1385
1395
  };
1386
1396
  }
1387
1397
  }
@@ -1403,7 +1413,7 @@ const createStore = (invalidate, advance) => {
1403
1413
  updateCamera(camera, size); // Update renderer
1404
1414
 
1405
1415
  gl.setPixelRatio(viewport.dpr);
1406
- gl.setSize(size.width, size.height);
1416
+ gl.setSize(size.width, size.height, size.updateStyle);
1407
1417
  oldSize = size;
1408
1418
  oldDpr = viewport.dpr;
1409
1419
  }
@@ -1825,7 +1835,7 @@ function createRoot(canvas) {
1825
1835
  width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
1826
1836
  height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
1827
1837
  };
1828
- if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height); // Check frameloop
1838
+ if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height, size.updateStyle); // Check frameloop
1829
1839
 
1830
1840
  if (state.frameloop !== frameloop) state.setFrameloop(frameloop); // Check pointer missed
1831
1841
 
@@ -2045,7 +2055,7 @@ function Portal({
2045
2055
  reconciler.injectIntoDevTools({
2046
2056
  bundleType: process.env.NODE_ENV === 'production' ? 0 : 1,
2047
2057
  rendererPackageName: '@react-three/fiber',
2048
- version: '18.0.0'
2058
+ version: React__namespace.version
2049
2059
  });
2050
2060
  const act = React__namespace.unstable_act;
2051
2061
 
@@ -173,7 +173,7 @@ function prepare(object, state) {
173
173
  eventCount: 0,
174
174
  handlers: {},
175
175
  objects: [],
176
- parent: null,
176
+ parents: [],
177
177
  ...state
178
178
  };
179
179
  }
@@ -287,10 +287,10 @@ 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;
290
+ var _instance$__r3f3, _root$getState, _localState$parents;
291
291
 
292
292
  // Filter equals, events and reserved props
293
- const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {};
293
+ const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
294
294
  const root = localState.root;
295
295
  const rootState = (_root$getState = root == null ? void 0 : root.getState == null ? void 0 : root.getState()) != null ? _root$getState : {};
296
296
  const {
@@ -378,7 +378,7 @@ function applyProps$1(instance, data) {
378
378
  invalidateInstance(instance);
379
379
  });
380
380
 
381
- if (localState.parent && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
381
+ if ((_localState$parents = localState.parents) != null && _localState$parents.length && 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
@@ -480,7 +480,6 @@ function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
480
480
 
481
481
  function removeInteractivity(store, object) {
482
482
  const {
483
- events,
484
483
  internal
485
484
  } = store.getState(); // Removes every trace of an object from the data store
486
485
 
@@ -707,14 +706,14 @@ function createEvents(store) {
707
706
  return intersections;
708
707
  }
709
708
 
710
- function cancelPointer(hits) {
709
+ function cancelPointer(intersections) {
711
710
  const {
712
711
  internal
713
712
  } = store.getState();
714
713
  Array.from(internal.hovered.values()).forEach(hoveredObj => {
715
714
  // When no objects were hit or the the hovered object wasn't found underneath the cursor
716
715
  // we call onPointerOut and delete the object from the hovered-elements map
717
- if (!hits.length || !hits.find(hit => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId)) {
716
+ if (!intersections.length || !intersections.find(hit => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId)) {
718
717
  const eventObject = hoveredObj.eventObject;
719
718
  const instance = eventObject.__r3f;
720
719
  const handlers = instance == null ? void 0 : instance.handlers;
@@ -723,7 +722,7 @@ function createEvents(store) {
723
722
  if (instance != null && instance.eventCount) {
724
723
  // Clear out intersects, they are outdated by now
725
724
  const data = { ...hoveredObj,
726
- intersections: hits || []
725
+ intersections
727
726
  };
728
727
  handlers.onPointerOut == null ? void 0 : handlers.onPointerOut(data);
729
728
  handlers.onPointerLeave == null ? void 0 : handlers.onPointerLeave(data);
@@ -872,7 +871,7 @@ function createRenderer(roots, getEventPriority) {
872
871
  if (type === 'primitive') {
873
872
  if (props.object === undefined) throw `Primitives without 'object' are invalid!`;
874
873
  const object = props.object;
875
- instance = prepare(object, {
874
+ instance = prepare(object, { ...object.__r3f,
876
875
  type,
877
876
  root,
878
877
  attach,
@@ -926,7 +925,9 @@ function createRenderer(roots, getEventPriority) {
926
925
 
927
926
  if (!added) (_parentInstance$__r3f = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f.objects.push(child);
928
927
  if (!child.__r3f) prepare(child, {});
929
- child.__r3f.parent = parentInstance;
928
+
929
+ child.__r3f.parents.push(parentInstance);
930
+
930
931
  updateInstance(child);
931
932
  invalidateInstance(child);
932
933
  }
@@ -938,9 +939,7 @@ function createRenderer(roots, getEventPriority) {
938
939
  if (child) {
939
940
  var _child$__r3f2, _parentInstance$__r3f2;
940
941
 
941
- if ((_child$__r3f2 = child.__r3f) != null && _child$__r3f2.attach) {
942
- attach(parentInstance, child, child.__r3f.attach);
943
- } else if (child.isObject3D && parentInstance.isObject3D) {
942
+ if (!((_child$__r3f2 = child.__r3f) != null && _child$__r3f2.attach) && child.isObject3D && parentInstance.isObject3D) {
944
943
  child.parent = parentInstance;
945
944
  child.dispatchEvent({
946
945
  type: 'added'
@@ -953,7 +952,9 @@ function createRenderer(roots, getEventPriority) {
953
952
 
954
953
  if (!added) (_parentInstance$__r3f2 = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f2.objects.push(child);
955
954
  if (!child.__r3f) prepare(child, {});
956
- child.__r3f.parent = parentInstance;
955
+
956
+ child.__r3f.parents.push(parentInstance);
957
+
957
958
  updateInstance(child);
958
959
  invalidateInstance(child);
959
960
  }
@@ -968,7 +969,7 @@ function createRenderer(roots, getEventPriority) {
968
969
  var _parentInstance$__r3f3, _child$__r3f3, _child$__r3f5;
969
970
 
970
971
  // Clear the parent reference
971
- if (child.__r3f) child.__r3f.parent = null; // Remove child from the parents objects
972
+ if (child.__r3f) child.__r3f.parents = child.__r3f.parents.filter(parent => parent !== parentInstance); // Remove child from the parents objects
972
973
 
973
974
  if ((_parentInstance$__r3f3 = parentInstance.__r3f) != null && _parentInstance$__r3f3.objects) parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child); // Remove attachment
974
975
 
@@ -1029,11 +1030,11 @@ function createRenderer(roots, getEventPriority) {
1029
1030
  }
1030
1031
 
1031
1032
  function switchInstance(instance, type, newProps, fiber) {
1032
- var _instance$__r3f, _instance$__r3f2, _newInstance$__r3f;
1033
+ var _instance$__r3f, _newInstance$__r3f;
1033
1034
 
1034
- const parent = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parent;
1035
- if (!parent) return;
1036
- const newInstance = createInstance(type, newProps, (_instance$__r3f2 = instance.__r3f) == null ? void 0 : _instance$__r3f2.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1035
+ const parents = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parents;
1036
+ if (!(parents != null && parents.length)) return;
1037
+ const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1037
1038
  // When args change the instance has to be re-constructed, which then
1038
1039
  // forces r3f to re-parent the children and non-scene objects
1039
1040
  // This can not include primitives, which should not have declarative children
@@ -1041,23 +1042,34 @@ function createRenderer(roots, getEventPriority) {
1041
1042
  if (type !== 'primitive' && instance.children) {
1042
1043
  instance.children.forEach(child => appendChild(newInstance, child));
1043
1044
  instance.children = [];
1044
- }
1045
+ } // Copy over child attachments
1046
+
1045
1047
 
1046
- instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
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
+ }
1047
1053
 
1048
1054
  instance.__r3f.objects = [];
1049
- removeChild(parent, instance);
1050
- appendChild(parent, newInstance); // Re-bind event handlers
1055
+
1056
+ for (const parent of parents) {
1057
+ removeChild(parent, instance);
1058
+ appendChild(parent, newInstance);
1059
+ } // Re-bind event handlers
1060
+
1051
1061
 
1052
1062
  if (newInstance.raycast && newInstance.__r3f.eventCount) {
1053
1063
  const rootState = newInstance.__r3f.root.getState();
1054
1064
 
1055
1065
  rootState.internal.interaction.push(newInstance);
1056
- } // The attach attribute implies that the object attaches itself on the parent
1066
+ } // Attach instance to parent
1057
1067
 
1058
1068
 
1059
1069
  if ((_newInstance$__r3f = newInstance.__r3f) != null && _newInstance$__r3f.attach) {
1060
- attach(parent, newInstance, newInstance.__r3f.attach);
1070
+ for (const parent of parents) {
1071
+ attach(parent, newInstance, newInstance.__r3f.attach);
1072
+ }
1061
1073
  } // This evil hack switches the react-internal fiber node
1062
1074
  [fiber, fiber.alternate].forEach(fiber => {
1063
1075
  if (fiber !== null) {
@@ -1093,9 +1105,9 @@ function createRenderer(roots, getEventPriority) {
1093
1105
  getChildHostContext: parentHostContext => parentHostContext,
1094
1106
 
1095
1107
  finalizeInitialChildren(instance) {
1096
- var _instance$__r3f3;
1108
+ var _instance$__r3f2;
1097
1109
 
1098
- const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {}; // https://github.com/facebook/react/issues/20271
1110
+ const localState = (_instance$__r3f2 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f2 : {}; // https://github.com/facebook/react/issues/20271
1099
1111
  // Returning true will trigger commitMount
1100
1112
 
1101
1113
  return !!localState.handlers || !!localState.attach;
@@ -1136,11 +1148,11 @@ function createRenderer(roots, getEventPriority) {
1136
1148
  },
1137
1149
 
1138
1150
  commitMount(instance, type, props, int) {
1139
- var _instance$__r3f4;
1151
+ var _instance$__r3f3;
1140
1152
 
1141
1153
  // https://github.com/facebook/react/issues/20271
1142
1154
  // This will make sure events are only added once to the central container
1143
- const localState = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1155
+ const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
1144
1156
 
1145
1157
  if (instance.raycast && localState.handlers && localState.eventCount) {
1146
1158
  instance.__r3f.root.getState().internal.interaction.push(instance);
@@ -1148,7 +1160,9 @@ function createRenderer(roots, getEventPriority) {
1148
1160
 
1149
1161
 
1150
1162
  if (localState.attach) {
1151
- attach(localState.parent, instance, localState.attach);
1163
+ for (const parent of localState.parents) {
1164
+ attach(parent, instance, localState.attach);
1165
+ }
1152
1166
  }
1153
1167
  },
1154
1168
 
@@ -1286,7 +1300,8 @@ const createStore = (invalidate, advance) => {
1286
1300
  },
1287
1301
  size: {
1288
1302
  width: 0,
1289
- height: 0
1303
+ height: 0,
1304
+ updateStyle: false
1290
1305
  },
1291
1306
  viewport: {
1292
1307
  initialDpr: 0,
@@ -1303,11 +1318,12 @@ const createStore = (invalidate, advance) => {
1303
1318
  ...events
1304
1319
  }
1305
1320
  })),
1306
- setSize: (width, height) => {
1321
+ setSize: (width, height, updateStyle) => {
1307
1322
  const camera = get().camera;
1308
1323
  const size = {
1309
1324
  width,
1310
- height
1325
+ height,
1326
+ updateStyle
1311
1327
  };
1312
1328
  set(state => ({
1313
1329
  size,
@@ -1353,35 +1369,29 @@ const createStore = (invalidate, advance) => {
1353
1369
  initialHits: [],
1354
1370
  capturedMap: new Map(),
1355
1371
  subscribe: (ref, priority, store) => {
1356
- set(({
1357
- internal
1358
- }) => ({
1359
- internal: { ...internal,
1360
- // If this subscription was given a priority, it takes rendering into its own hands
1361
- // For that reason we switch off automatic rendering and increase the manual flag
1362
- // As long as this flag is positive there can be no internal rendering at all
1363
- // because there could be multiple render subscriptions
1364
- priority: internal.priority + (priority > 0 ? 1 : 0),
1365
- // Register subscriber and sort layers from lowest to highest, meaning,
1366
- // highest priority renders last (on top of the other frames)
1367
- subscribers: [...internal.subscribers, {
1368
- ref,
1369
- priority,
1370
- store
1371
- }].sort((a, b) => a.priority - b.priority)
1372
- }
1373
- }));
1372
+ const internal = get().internal; // If this subscription was given a priority, it takes rendering into its own hands
1373
+ // For that reason we switch off automatic rendering and increase the manual flag
1374
+ // As long as this flag is positive there can be no internal rendering at all
1375
+ // because there could be multiple render subscriptions
1376
+
1377
+ internal.priority = internal.priority + (priority > 0 ? 1 : 0);
1378
+ internal.subscribers.push({
1379
+ ref,
1380
+ priority,
1381
+ store
1382
+ }); // Register subscriber and sort layers from lowest to highest, meaning,
1383
+ // highest priority renders last (on top of the other frames)
1384
+
1385
+ internal.subscribers = internal.subscribers.sort((a, b) => a.priority - b.priority);
1374
1386
  return () => {
1375
- set(({
1376
- internal
1377
- }) => ({
1378
- internal: { ...internal,
1379
- // Decrease manual flag if this subscription had a priority
1380
- priority: internal.priority - (priority > 0 ? 1 : 0),
1381
- // Remove subscriber from list
1382
- subscribers: internal.subscribers.filter(s => s.ref !== ref)
1383
- }
1384
- }));
1387
+ const internal = get().internal;
1388
+
1389
+ if (internal != null && internal.subscribers) {
1390
+ // Decrease manual flag if this subscription had a priority
1391
+ internal.priority = internal.priority - (priority > 0 ? 1 : 0); // Remove subscriber from list
1392
+
1393
+ internal.subscribers = internal.subscribers.filter(s => s.ref !== ref);
1394
+ }
1385
1395
  };
1386
1396
  }
1387
1397
  }
@@ -1403,7 +1413,7 @@ const createStore = (invalidate, advance) => {
1403
1413
  updateCamera(camera, size); // Update renderer
1404
1414
 
1405
1415
  gl.setPixelRatio(viewport.dpr);
1406
- gl.setSize(size.width, size.height);
1416
+ gl.setSize(size.width, size.height, size.updateStyle);
1407
1417
  oldSize = size;
1408
1418
  oldDpr = viewport.dpr;
1409
1419
  }
@@ -1825,7 +1835,7 @@ function createRoot(canvas) {
1825
1835
  width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
1826
1836
  height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
1827
1837
  };
1828
- if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height); // Check frameloop
1838
+ if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height, size.updateStyle); // Check frameloop
1829
1839
 
1830
1840
  if (state.frameloop !== frameloop) state.setFrameloop(frameloop); // Check pointer missed
1831
1841
 
@@ -2045,7 +2055,7 @@ function Portal({
2045
2055
  reconciler.injectIntoDevTools({
2046
2056
  bundleType: 0 ,
2047
2057
  rendererPackageName: '@react-three/fiber',
2048
- version: '18.0.0'
2058
+ version: React__namespace.version
2049
2059
  });
2050
2060
  const act = React__namespace.unstable_act;
2051
2061
 
@@ -146,7 +146,7 @@ function prepare(object, state) {
146
146
  eventCount: 0,
147
147
  handlers: {},
148
148
  objects: [],
149
- parent: null,
149
+ parents: [],
150
150
  ...state
151
151
  };
152
152
  }
@@ -260,10 +260,10 @@ function diffProps(instance, {
260
260
  } // This function applies a set of changes to the instance
261
261
 
262
262
  function applyProps$1(instance, data) {
263
- var _instance$__r3f3, _root$getState;
263
+ var _instance$__r3f3, _root$getState, _localState$parents;
264
264
 
265
265
  // Filter equals, events and reserved props
266
- const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {};
266
+ const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
267
267
  const root = localState.root;
268
268
  const rootState = (_root$getState = root == null ? void 0 : root.getState == null ? void 0 : root.getState()) != null ? _root$getState : {};
269
269
  const {
@@ -351,7 +351,7 @@ function applyProps$1(instance, data) {
351
351
  invalidateInstance(instance);
352
352
  });
353
353
 
354
- if (localState.parent && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
354
+ if ((_localState$parents = localState.parents) != null && _localState$parents.length && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
355
355
  // Pre-emptively remove the instance from the interaction manager
356
356
  const index = rootState.internal.interaction.indexOf(instance);
357
357
  if (index > -1) rootState.internal.interaction.splice(index, 1); // Add the instance to the interaction manager only when it has handlers
@@ -453,7 +453,6 @@ function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
453
453
 
454
454
  function removeInteractivity(store, object) {
455
455
  const {
456
- events,
457
456
  internal
458
457
  } = store.getState(); // Removes every trace of an object from the data store
459
458
 
@@ -680,14 +679,14 @@ function createEvents(store) {
680
679
  return intersections;
681
680
  }
682
681
 
683
- function cancelPointer(hits) {
682
+ function cancelPointer(intersections) {
684
683
  const {
685
684
  internal
686
685
  } = store.getState();
687
686
  Array.from(internal.hovered.values()).forEach(hoveredObj => {
688
687
  // When no objects were hit or the the hovered object wasn't found underneath the cursor
689
688
  // we call onPointerOut and delete the object from the hovered-elements map
690
- if (!hits.length || !hits.find(hit => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId)) {
689
+ if (!intersections.length || !intersections.find(hit => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId)) {
691
690
  const eventObject = hoveredObj.eventObject;
692
691
  const instance = eventObject.__r3f;
693
692
  const handlers = instance == null ? void 0 : instance.handlers;
@@ -696,7 +695,7 @@ function createEvents(store) {
696
695
  if (instance != null && instance.eventCount) {
697
696
  // Clear out intersects, they are outdated by now
698
697
  const data = { ...hoveredObj,
699
- intersections: hits || []
698
+ intersections
700
699
  };
701
700
  handlers.onPointerOut == null ? void 0 : handlers.onPointerOut(data);
702
701
  handlers.onPointerLeave == null ? void 0 : handlers.onPointerLeave(data);
@@ -845,7 +844,7 @@ function createRenderer(roots, getEventPriority) {
845
844
  if (type === 'primitive') {
846
845
  if (props.object === undefined) throw `Primitives without 'object' are invalid!`;
847
846
  const object = props.object;
848
- instance = prepare(object, {
847
+ instance = prepare(object, { ...object.__r3f,
849
848
  type,
850
849
  root,
851
850
  attach,
@@ -899,7 +898,9 @@ function createRenderer(roots, getEventPriority) {
899
898
 
900
899
  if (!added) (_parentInstance$__r3f = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f.objects.push(child);
901
900
  if (!child.__r3f) prepare(child, {});
902
- child.__r3f.parent = parentInstance;
901
+
902
+ child.__r3f.parents.push(parentInstance);
903
+
903
904
  updateInstance(child);
904
905
  invalidateInstance(child);
905
906
  }
@@ -911,9 +912,7 @@ function createRenderer(roots, getEventPriority) {
911
912
  if (child) {
912
913
  var _child$__r3f2, _parentInstance$__r3f2;
913
914
 
914
- if ((_child$__r3f2 = child.__r3f) != null && _child$__r3f2.attach) {
915
- attach(parentInstance, child, child.__r3f.attach);
916
- } else if (child.isObject3D && parentInstance.isObject3D) {
915
+ if (!((_child$__r3f2 = child.__r3f) != null && _child$__r3f2.attach) && child.isObject3D && parentInstance.isObject3D) {
917
916
  child.parent = parentInstance;
918
917
  child.dispatchEvent({
919
918
  type: 'added'
@@ -926,7 +925,9 @@ function createRenderer(roots, getEventPriority) {
926
925
 
927
926
  if (!added) (_parentInstance$__r3f2 = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f2.objects.push(child);
928
927
  if (!child.__r3f) prepare(child, {});
929
- child.__r3f.parent = parentInstance;
928
+
929
+ child.__r3f.parents.push(parentInstance);
930
+
930
931
  updateInstance(child);
931
932
  invalidateInstance(child);
932
933
  }
@@ -941,7 +942,7 @@ function createRenderer(roots, getEventPriority) {
941
942
  var _parentInstance$__r3f3, _child$__r3f3, _child$__r3f5;
942
943
 
943
944
  // Clear the parent reference
944
- if (child.__r3f) child.__r3f.parent = null; // Remove child from the parents objects
945
+ if (child.__r3f) child.__r3f.parents = child.__r3f.parents.filter(parent => parent !== parentInstance); // Remove child from the parents objects
945
946
 
946
947
  if ((_parentInstance$__r3f3 = parentInstance.__r3f) != null && _parentInstance$__r3f3.objects) parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child); // Remove attachment
947
948
 
@@ -1002,11 +1003,11 @@ function createRenderer(roots, getEventPriority) {
1002
1003
  }
1003
1004
 
1004
1005
  function switchInstance(instance, type, newProps, fiber) {
1005
- var _instance$__r3f, _instance$__r3f2, _newInstance$__r3f;
1006
+ var _instance$__r3f, _newInstance$__r3f;
1006
1007
 
1007
- const parent = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parent;
1008
- if (!parent) return;
1009
- const newInstance = createInstance(type, newProps, (_instance$__r3f2 = instance.__r3f) == null ? void 0 : _instance$__r3f2.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1008
+ const parents = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parents;
1009
+ if (!(parents != null && parents.length)) return;
1010
+ const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1010
1011
  // When args change the instance has to be re-constructed, which then
1011
1012
  // forces r3f to re-parent the children and non-scene objects
1012
1013
  // This can not include primitives, which should not have declarative children
@@ -1014,23 +1015,34 @@ function createRenderer(roots, getEventPriority) {
1014
1015
  if (type !== 'primitive' && instance.children) {
1015
1016
  instance.children.forEach(child => appendChild(newInstance, child));
1016
1017
  instance.children = [];
1017
- }
1018
+ } // Copy over child attachments
1019
+
1018
1020
 
1019
- instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
1021
+ for (const child of instance.__r3f.objects) {
1022
+ appendChild(newInstance, child);
1023
+ detach(instance, child, child.__r3f.attach);
1024
+ attach(newInstance, child, child.__r3f.attach);
1025
+ }
1020
1026
 
1021
1027
  instance.__r3f.objects = [];
1022
- removeChild(parent, instance);
1023
- appendChild(parent, newInstance); // Re-bind event handlers
1028
+
1029
+ for (const parent of parents) {
1030
+ removeChild(parent, instance);
1031
+ appendChild(parent, newInstance);
1032
+ } // Re-bind event handlers
1033
+
1024
1034
 
1025
1035
  if (newInstance.raycast && newInstance.__r3f.eventCount) {
1026
1036
  const rootState = newInstance.__r3f.root.getState();
1027
1037
 
1028
1038
  rootState.internal.interaction.push(newInstance);
1029
- } // The attach attribute implies that the object attaches itself on the parent
1039
+ } // Attach instance to parent
1030
1040
 
1031
1041
 
1032
1042
  if ((_newInstance$__r3f = newInstance.__r3f) != null && _newInstance$__r3f.attach) {
1033
- attach(parent, newInstance, newInstance.__r3f.attach);
1043
+ for (const parent of parents) {
1044
+ attach(parent, newInstance, newInstance.__r3f.attach);
1045
+ }
1034
1046
  } // This evil hack switches the react-internal fiber node
1035
1047
  [fiber, fiber.alternate].forEach(fiber => {
1036
1048
  if (fiber !== null) {
@@ -1066,9 +1078,9 @@ function createRenderer(roots, getEventPriority) {
1066
1078
  getChildHostContext: parentHostContext => parentHostContext,
1067
1079
 
1068
1080
  finalizeInitialChildren(instance) {
1069
- var _instance$__r3f3;
1081
+ var _instance$__r3f2;
1070
1082
 
1071
- const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {}; // https://github.com/facebook/react/issues/20271
1083
+ const localState = (_instance$__r3f2 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f2 : {}; // https://github.com/facebook/react/issues/20271
1072
1084
  // Returning true will trigger commitMount
1073
1085
 
1074
1086
  return !!localState.handlers || !!localState.attach;
@@ -1109,11 +1121,11 @@ function createRenderer(roots, getEventPriority) {
1109
1121
  },
1110
1122
 
1111
1123
  commitMount(instance, type, props, int) {
1112
- var _instance$__r3f4;
1124
+ var _instance$__r3f3;
1113
1125
 
1114
1126
  // https://github.com/facebook/react/issues/20271
1115
1127
  // This will make sure events are only added once to the central container
1116
- const localState = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1128
+ const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
1117
1129
 
1118
1130
  if (instance.raycast && localState.handlers && localState.eventCount) {
1119
1131
  instance.__r3f.root.getState().internal.interaction.push(instance);
@@ -1121,7 +1133,9 @@ function createRenderer(roots, getEventPriority) {
1121
1133
 
1122
1134
 
1123
1135
  if (localState.attach) {
1124
- attach(localState.parent, instance, localState.attach);
1136
+ for (const parent of localState.parents) {
1137
+ attach(parent, instance, localState.attach);
1138
+ }
1125
1139
  }
1126
1140
  },
1127
1141
 
@@ -1259,7 +1273,8 @@ const createStore = (invalidate, advance) => {
1259
1273
  },
1260
1274
  size: {
1261
1275
  width: 0,
1262
- height: 0
1276
+ height: 0,
1277
+ updateStyle: false
1263
1278
  },
1264
1279
  viewport: {
1265
1280
  initialDpr: 0,
@@ -1276,11 +1291,12 @@ const createStore = (invalidate, advance) => {
1276
1291
  ...events
1277
1292
  }
1278
1293
  })),
1279
- setSize: (width, height) => {
1294
+ setSize: (width, height, updateStyle) => {
1280
1295
  const camera = get().camera;
1281
1296
  const size = {
1282
1297
  width,
1283
- height
1298
+ height,
1299
+ updateStyle
1284
1300
  };
1285
1301
  set(state => ({
1286
1302
  size,
@@ -1326,35 +1342,29 @@ const createStore = (invalidate, advance) => {
1326
1342
  initialHits: [],
1327
1343
  capturedMap: new Map(),
1328
1344
  subscribe: (ref, priority, store) => {
1329
- set(({
1330
- internal
1331
- }) => ({
1332
- internal: { ...internal,
1333
- // If this subscription was given a priority, it takes rendering into its own hands
1334
- // For that reason we switch off automatic rendering and increase the manual flag
1335
- // As long as this flag is positive there can be no internal rendering at all
1336
- // because there could be multiple render subscriptions
1337
- priority: internal.priority + (priority > 0 ? 1 : 0),
1338
- // Register subscriber and sort layers from lowest to highest, meaning,
1339
- // highest priority renders last (on top of the other frames)
1340
- subscribers: [...internal.subscribers, {
1341
- ref,
1342
- priority,
1343
- store
1344
- }].sort((a, b) => a.priority - b.priority)
1345
- }
1346
- }));
1345
+ const internal = get().internal; // If this subscription was given a priority, it takes rendering into its own hands
1346
+ // For that reason we switch off automatic rendering and increase the manual flag
1347
+ // As long as this flag is positive there can be no internal rendering at all
1348
+ // because there could be multiple render subscriptions
1349
+
1350
+ internal.priority = internal.priority + (priority > 0 ? 1 : 0);
1351
+ internal.subscribers.push({
1352
+ ref,
1353
+ priority,
1354
+ store
1355
+ }); // Register subscriber and sort layers from lowest to highest, meaning,
1356
+ // highest priority renders last (on top of the other frames)
1357
+
1358
+ internal.subscribers = internal.subscribers.sort((a, b) => a.priority - b.priority);
1347
1359
  return () => {
1348
- set(({
1349
- internal
1350
- }) => ({
1351
- internal: { ...internal,
1352
- // Decrease manual flag if this subscription had a priority
1353
- priority: internal.priority - (priority > 0 ? 1 : 0),
1354
- // Remove subscriber from list
1355
- subscribers: internal.subscribers.filter(s => s.ref !== ref)
1356
- }
1357
- }));
1360
+ const internal = get().internal;
1361
+
1362
+ if (internal != null && internal.subscribers) {
1363
+ // Decrease manual flag if this subscription had a priority
1364
+ internal.priority = internal.priority - (priority > 0 ? 1 : 0); // Remove subscriber from list
1365
+
1366
+ internal.subscribers = internal.subscribers.filter(s => s.ref !== ref);
1367
+ }
1358
1368
  };
1359
1369
  }
1360
1370
  }
@@ -1376,7 +1386,7 @@ const createStore = (invalidate, advance) => {
1376
1386
  updateCamera(camera, size); // Update renderer
1377
1387
 
1378
1388
  gl.setPixelRatio(viewport.dpr);
1379
- gl.setSize(size.width, size.height);
1389
+ gl.setSize(size.width, size.height, size.updateStyle);
1380
1390
  oldSize = size;
1381
1391
  oldDpr = viewport.dpr;
1382
1392
  }
@@ -1798,7 +1808,7 @@ function createRoot(canvas) {
1798
1808
  width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
1799
1809
  height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
1800
1810
  };
1801
- if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height); // Check frameloop
1811
+ if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height, size.updateStyle); // Check frameloop
1802
1812
 
1803
1813
  if (state.frameloop !== frameloop) state.setFrameloop(frameloop); // Check pointer missed
1804
1814
 
@@ -2018,7 +2028,7 @@ function Portal({
2018
2028
  reconciler.injectIntoDevTools({
2019
2029
  bundleType: process.env.NODE_ENV === 'production' ? 0 : 1,
2020
2030
  rendererPackageName: '@react-three/fiber',
2021
- version: '18.0.0'
2031
+ version: React.version
2022
2032
  });
2023
2033
  const act = React.unstable_act;
2024
2034
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-88f08658.cjs.dev.js');
5
+ var index = require('./index-8ec72a6b.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -83,7 +83,7 @@ function createPointerEvents(store) {
83
83
  connected: target
84
84
  }
85
85
  }));
86
- Object.entries((_events$handlers = events == null ? void 0 : events.handlers) != null ? _events$handlers : []).forEach(([name, event]) => {
86
+ Object.entries((_events$handlers = events.handlers) != null ? _events$handlers : []).forEach(([name, event]) => {
87
87
  const [eventName, passive] = DOM_EVENTS[name];
88
88
  target.addEventListener(eventName, event, {
89
89
  passive
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-dcd9befe.cjs.prod.js');
5
+ var index = require('./index-b47473f2.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -83,7 +83,7 @@ function createPointerEvents(store) {
83
83
  connected: target
84
84
  }
85
85
  }));
86
- Object.entries((_events$handlers = events == null ? void 0 : events.handlers) != null ? _events$handlers : []).forEach(([name, event]) => {
86
+ Object.entries((_events$handlers = events.handlers) != null ? _events$handlers : []).forEach(([name, event]) => {
87
87
  const [eventName, passive] = DOM_EVENTS[name];
88
88
  target.addEventListener(eventName, event, {
89
89
  passive
@@ -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-1e2a4313.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-1e2a4313.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-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';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
@@ -56,7 +56,7 @@ function createPointerEvents(store) {
56
56
  connected: target
57
57
  }
58
58
  }));
59
- Object.entries((_events$handlers = events == null ? void 0 : events.handlers) != null ? _events$handlers : []).forEach(([name, event]) => {
59
+ Object.entries((_events$handlers = events.handlers) != null ? _events$handlers : []).forEach(([name, event]) => {
60
60
  const [eventName, passive] = DOM_EVENTS[name];
61
61
  target.addEventListener(eventName, event, {
62
62
  passive
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-88f08658.cjs.dev.js');
5
+ var index = require('../../dist/index-8ec72a6b.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -95,7 +95,7 @@ function createTouchEvents(store) {
95
95
  events
96
96
  } = store.getState();
97
97
  events.disconnect == null ? void 0 : events.disconnect();
98
- const connected = new Pressability__default["default"](events == null ? void 0 : events.handlers);
98
+ const connected = new Pressability__default["default"](events.handlers);
99
99
  set(state => ({
100
100
  events: { ...state.events,
101
101
  connected
@@ -286,7 +286,9 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
286
286
  width,
287
287
  height
288
288
  });
289
- }, []);
289
+ }, []); // Called on context create or swap
290
+ // https://github.com/pmndrs/react-three-fiber/pull/2297
291
+
290
292
  const onContextCreate = React__namespace.useCallback(context => {
291
293
  const canvasShim = {
292
294
  width: context.drawingBufferWidth,
@@ -297,11 +299,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
297
299
  clientHeight: context.drawingBufferHeight,
298
300
  getContext: () => context
299
301
  };
302
+ root.current = index.createRoot(canvasShim);
300
303
  setCanvas(canvasShim);
301
304
  }, []);
302
305
 
303
- if (width > 0 && height > 0 && canvas) {
304
- if (!root.current) root.current = index.createRoot(canvas);
306
+ if (root.current && width > 0 && height > 0) {
305
307
  root.current.configure({
306
308
  gl,
307
309
  events,
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-dcd9befe.cjs.prod.js');
5
+ var index = require('../../dist/index-b47473f2.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -95,7 +95,7 @@ function createTouchEvents(store) {
95
95
  events
96
96
  } = store.getState();
97
97
  events.disconnect == null ? void 0 : events.disconnect();
98
- const connected = new Pressability__default["default"](events == null ? void 0 : events.handlers);
98
+ const connected = new Pressability__default["default"](events.handlers);
99
99
  set(state => ({
100
100
  events: { ...state.events,
101
101
  connected
@@ -286,7 +286,9 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
286
286
  width,
287
287
  height
288
288
  });
289
- }, []);
289
+ }, []); // Called on context create or swap
290
+ // https://github.com/pmndrs/react-three-fiber/pull/2297
291
+
290
292
  const onContextCreate = React__namespace.useCallback(context => {
291
293
  const canvasShim = {
292
294
  width: context.drawingBufferWidth,
@@ -297,11 +299,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
297
299
  clientHeight: context.drawingBufferHeight,
298
300
  getContext: () => context
299
301
  };
302
+ root.current = index.createRoot(canvasShim);
300
303
  setCanvas(canvasShim);
301
304
  }, []);
302
305
 
303
- if (width > 0 && height > 0 && canvas) {
304
- if (!root.current) root.current = index.createRoot(canvas);
306
+ if (root.current && width > 0 && height > 0) {
305
307
  root.current.configure({
306
308
  gl,
307
309
  events,
@@ -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-1e2a4313.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-1e2a4313.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-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';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
@@ -68,7 +68,7 @@ function createTouchEvents(store) {
68
68
  events
69
69
  } = store.getState();
70
70
  events.disconnect == null ? void 0 : events.disconnect();
71
- const connected = new Pressability(events == null ? void 0 : events.handlers);
71
+ const connected = new Pressability(events.handlers);
72
72
  set(state => ({
73
73
  events: { ...state.events,
74
74
  connected
@@ -259,7 +259,9 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
259
259
  width,
260
260
  height
261
261
  });
262
- }, []);
262
+ }, []); // Called on context create or swap
263
+ // https://github.com/pmndrs/react-three-fiber/pull/2297
264
+
263
265
  const onContextCreate = React.useCallback(context => {
264
266
  const canvasShim = {
265
267
  width: context.drawingBufferWidth,
@@ -270,11 +272,11 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
270
272
  clientHeight: context.drawingBufferHeight,
271
273
  getContext: () => context
272
274
  };
275
+ root.current = createRoot(canvasShim);
273
276
  setCanvas(canvasShim);
274
277
  }, []);
275
278
 
276
- if (width > 0 && height > 0 && canvas) {
277
- if (!root.current) root.current = createRoot(canvas);
279
+ if (root.current && width > 0 && height > 0) {
278
280
  root.current.configure({
279
281
  gl,
280
282
  events,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.0.19",
3
+ "version": "8.0.22",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",