@react-three/fiber 8.0.18 → 8.0.21

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.21
4
+
5
+ ### Patch Changes
6
+
7
+ - 3098b9b: fix: resizing in worker contexts, copy over attachments on reconstruct
8
+
9
+ ## 8.0.20
10
+
11
+ ### Patch Changes
12
+
13
+ - 4c87bce: fix: attach, devtools, and perf fixes
14
+
15
+ ## 8.0.19
16
+
17
+ ### Patch Changes
18
+
19
+ - 360b45a: fix: handle attach on reconstruct
20
+
3
21
  ## 8.0.18
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;
@@ -137,7 +137,7 @@ function dispose(obj) {
137
137
  function prepare(object, state) {
138
138
  const instance = object;
139
139
 
140
- if (state != null && state.primitive || !instance.__r3f) {
140
+ if (!instance.__r3f) {
141
141
  instance.__r3f = {
142
142
  type: '',
143
143
  root: null,
@@ -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);
@@ -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;
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,18 +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);
1039
+ } // Attach instance to parent
1040
+
1041
+
1042
+ if ((_newInstance$__r3f = newInstance.__r3f) != null && _newInstance$__r3f.attach) {
1043
+ for (const parent of parents) {
1044
+ attach(parent, newInstance, newInstance.__r3f.attach);
1045
+ }
1029
1046
  } // This evil hack switches the react-internal fiber node
1030
1047
  [fiber, fiber.alternate].forEach(fiber => {
1031
1048
  if (fiber !== null) {
@@ -1061,9 +1078,9 @@ function createRenderer(roots, getEventPriority) {
1061
1078
  getChildHostContext: parentHostContext => parentHostContext,
1062
1079
 
1063
1080
  finalizeInitialChildren(instance) {
1064
- var _instance$__r3f3;
1081
+ var _instance$__r3f2;
1065
1082
 
1066
- 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
1067
1084
  // Returning true will trigger commitMount
1068
1085
 
1069
1086
  return !!localState.handlers || !!localState.attach;
@@ -1104,11 +1121,11 @@ function createRenderer(roots, getEventPriority) {
1104
1121
  },
1105
1122
 
1106
1123
  commitMount(instance, type, props, int) {
1107
- var _instance$__r3f4;
1124
+ var _instance$__r3f3;
1108
1125
 
1109
1126
  // https://github.com/facebook/react/issues/20271
1110
1127
  // This will make sure events are only added once to the central container
1111
- const localState = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1128
+ const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
1112
1129
 
1113
1130
  if (instance.raycast && localState.handlers && localState.eventCount) {
1114
1131
  instance.__r3f.root.getState().internal.interaction.push(instance);
@@ -1116,7 +1133,9 @@ function createRenderer(roots, getEventPriority) {
1116
1133
 
1117
1134
 
1118
1135
  if (localState.attach) {
1119
- attach(localState.parent, instance, localState.attach);
1136
+ for (const parent of localState.parents) {
1137
+ attach(parent, instance, localState.attach);
1138
+ }
1120
1139
  }
1121
1140
  },
1122
1141
 
@@ -1254,7 +1273,8 @@ const createStore = (invalidate, advance) => {
1254
1273
  },
1255
1274
  size: {
1256
1275
  width: 0,
1257
- height: 0
1276
+ height: 0,
1277
+ updateStyle: false
1258
1278
  },
1259
1279
  viewport: {
1260
1280
  initialDpr: 0,
@@ -1271,11 +1291,12 @@ const createStore = (invalidate, advance) => {
1271
1291
  ...events
1272
1292
  }
1273
1293
  })),
1274
- setSize: (width, height) => {
1294
+ setSize: (width, height, updateStyle) => {
1275
1295
  const camera = get().camera;
1276
1296
  const size = {
1277
1297
  width,
1278
- height
1298
+ height,
1299
+ updateStyle
1279
1300
  };
1280
1301
  set(state => ({
1281
1302
  size,
@@ -1321,35 +1342,29 @@ const createStore = (invalidate, advance) => {
1321
1342
  initialHits: [],
1322
1343
  capturedMap: new Map(),
1323
1344
  subscribe: (ref, priority, store) => {
1324
- set(({
1325
- internal
1326
- }) => ({
1327
- internal: { ...internal,
1328
- // If this subscription was given a priority, it takes rendering into its own hands
1329
- // For that reason we switch off automatic rendering and increase the manual flag
1330
- // As long as this flag is positive there can be no internal rendering at all
1331
- // because there could be multiple render subscriptions
1332
- priority: internal.priority + (priority > 0 ? 1 : 0),
1333
- // Register subscriber and sort layers from lowest to highest, meaning,
1334
- // highest priority renders last (on top of the other frames)
1335
- subscribers: [...internal.subscribers, {
1336
- ref,
1337
- priority,
1338
- store
1339
- }].sort((a, b) => a.priority - b.priority)
1340
- }
1341
- }));
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);
1342
1359
  return () => {
1343
- set(({
1344
- internal
1345
- }) => ({
1346
- internal: { ...internal,
1347
- // Decrease manual flag if this subscription had a priority
1348
- priority: internal.priority - (priority > 0 ? 1 : 0),
1349
- // Remove subscriber from list
1350
- subscribers: internal.subscribers.filter(s => s.ref !== ref)
1351
- }
1352
- }));
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
+ }
1353
1368
  };
1354
1369
  }
1355
1370
  }
@@ -1371,7 +1386,7 @@ const createStore = (invalidate, advance) => {
1371
1386
  updateCamera(camera, size); // Update renderer
1372
1387
 
1373
1388
  gl.setPixelRatio(viewport.dpr);
1374
- gl.setSize(size.width, size.height);
1389
+ gl.setSize(size.width, size.height, size.updateStyle);
1375
1390
  oldSize = size;
1376
1391
  oldDpr = viewport.dpr;
1377
1392
  }
@@ -1793,7 +1808,7 @@ function createRoot(canvas) {
1793
1808
  width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
1794
1809
  height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
1795
1810
  };
1796
- 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
1797
1812
 
1798
1813
  if (state.frameloop !== frameloop) state.setFrameloop(frameloop); // Check pointer missed
1799
1814
 
@@ -2013,7 +2028,7 @@ function Portal({
2013
2028
  reconciler.injectIntoDevTools({
2014
2029
  bundleType: process.env.NODE_ENV === 'production' ? 0 : 1,
2015
2030
  rendererPackageName: '@react-three/fiber',
2016
- version: '18.0.0'
2031
+ version: React.version
2017
2032
  });
2018
2033
  const act = React.unstable_act;
2019
2034
 
@@ -164,7 +164,7 @@ function dispose(obj) {
164
164
  function prepare(object, state) {
165
165
  const instance = object;
166
166
 
167
- if (state != null && state.primitive || !instance.__r3f) {
167
+ if (!instance.__r3f) {
168
168
  instance.__r3f = {
169
169
  type: '',
170
170
  root: null,
@@ -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);
@@ -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;
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,18 +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);
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
+ }
1056
1073
  } // This evil hack switches the react-internal fiber node
1057
1074
  [fiber, fiber.alternate].forEach(fiber => {
1058
1075
  if (fiber !== null) {
@@ -1088,9 +1105,9 @@ function createRenderer(roots, getEventPriority) {
1088
1105
  getChildHostContext: parentHostContext => parentHostContext,
1089
1106
 
1090
1107
  finalizeInitialChildren(instance) {
1091
- var _instance$__r3f3;
1108
+ var _instance$__r3f2;
1092
1109
 
1093
- 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
1094
1111
  // Returning true will trigger commitMount
1095
1112
 
1096
1113
  return !!localState.handlers || !!localState.attach;
@@ -1131,11 +1148,11 @@ function createRenderer(roots, getEventPriority) {
1131
1148
  },
1132
1149
 
1133
1150
  commitMount(instance, type, props, int) {
1134
- var _instance$__r3f4;
1151
+ var _instance$__r3f3;
1135
1152
 
1136
1153
  // https://github.com/facebook/react/issues/20271
1137
1154
  // This will make sure events are only added once to the central container
1138
- const localState = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1155
+ const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
1139
1156
 
1140
1157
  if (instance.raycast && localState.handlers && localState.eventCount) {
1141
1158
  instance.__r3f.root.getState().internal.interaction.push(instance);
@@ -1143,7 +1160,9 @@ function createRenderer(roots, getEventPriority) {
1143
1160
 
1144
1161
 
1145
1162
  if (localState.attach) {
1146
- attach(localState.parent, instance, localState.attach);
1163
+ for (const parent of localState.parents) {
1164
+ attach(parent, instance, localState.attach);
1165
+ }
1147
1166
  }
1148
1167
  },
1149
1168
 
@@ -1281,7 +1300,8 @@ const createStore = (invalidate, advance) => {
1281
1300
  },
1282
1301
  size: {
1283
1302
  width: 0,
1284
- height: 0
1303
+ height: 0,
1304
+ updateStyle: false
1285
1305
  },
1286
1306
  viewport: {
1287
1307
  initialDpr: 0,
@@ -1298,11 +1318,12 @@ const createStore = (invalidate, advance) => {
1298
1318
  ...events
1299
1319
  }
1300
1320
  })),
1301
- setSize: (width, height) => {
1321
+ setSize: (width, height, updateStyle) => {
1302
1322
  const camera = get().camera;
1303
1323
  const size = {
1304
1324
  width,
1305
- height
1325
+ height,
1326
+ updateStyle
1306
1327
  };
1307
1328
  set(state => ({
1308
1329
  size,
@@ -1348,35 +1369,29 @@ const createStore = (invalidate, advance) => {
1348
1369
  initialHits: [],
1349
1370
  capturedMap: new Map(),
1350
1371
  subscribe: (ref, priority, store) => {
1351
- set(({
1352
- internal
1353
- }) => ({
1354
- internal: { ...internal,
1355
- // If this subscription was given a priority, it takes rendering into its own hands
1356
- // For that reason we switch off automatic rendering and increase the manual flag
1357
- // As long as this flag is positive there can be no internal rendering at all
1358
- // because there could be multiple render subscriptions
1359
- priority: internal.priority + (priority > 0 ? 1 : 0),
1360
- // Register subscriber and sort layers from lowest to highest, meaning,
1361
- // highest priority renders last (on top of the other frames)
1362
- subscribers: [...internal.subscribers, {
1363
- ref,
1364
- priority,
1365
- store
1366
- }].sort((a, b) => a.priority - b.priority)
1367
- }
1368
- }));
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);
1369
1386
  return () => {
1370
- set(({
1371
- internal
1372
- }) => ({
1373
- internal: { ...internal,
1374
- // Decrease manual flag if this subscription had a priority
1375
- priority: internal.priority - (priority > 0 ? 1 : 0),
1376
- // Remove subscriber from list
1377
- subscribers: internal.subscribers.filter(s => s.ref !== ref)
1378
- }
1379
- }));
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
+ }
1380
1395
  };
1381
1396
  }
1382
1397
  }
@@ -1398,7 +1413,7 @@ const createStore = (invalidate, advance) => {
1398
1413
  updateCamera(camera, size); // Update renderer
1399
1414
 
1400
1415
  gl.setPixelRatio(viewport.dpr);
1401
- gl.setSize(size.width, size.height);
1416
+ gl.setSize(size.width, size.height, size.updateStyle);
1402
1417
  oldSize = size;
1403
1418
  oldDpr = viewport.dpr;
1404
1419
  }
@@ -1820,7 +1835,7 @@ function createRoot(canvas) {
1820
1835
  width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
1821
1836
  height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
1822
1837
  };
1823
- 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
1824
1839
 
1825
1840
  if (state.frameloop !== frameloop) state.setFrameloop(frameloop); // Check pointer missed
1826
1841
 
@@ -2040,7 +2055,7 @@ function Portal({
2040
2055
  reconciler.injectIntoDevTools({
2041
2056
  bundleType: 0 ,
2042
2057
  rendererPackageName: '@react-three/fiber',
2043
- version: '18.0.0'
2058
+ version: React__namespace.version
2044
2059
  });
2045
2060
  const act = React__namespace.unstable_act;
2046
2061
 
@@ -164,7 +164,7 @@ function dispose(obj) {
164
164
  function prepare(object, state) {
165
165
  const instance = object;
166
166
 
167
- if (state != null && state.primitive || !instance.__r3f) {
167
+ if (!instance.__r3f) {
168
168
  instance.__r3f = {
169
169
  type: '',
170
170
  root: null,
@@ -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);
@@ -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;
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,18 +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);
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
+ }
1056
1073
  } // This evil hack switches the react-internal fiber node
1057
1074
  [fiber, fiber.alternate].forEach(fiber => {
1058
1075
  if (fiber !== null) {
@@ -1088,9 +1105,9 @@ function createRenderer(roots, getEventPriority) {
1088
1105
  getChildHostContext: parentHostContext => parentHostContext,
1089
1106
 
1090
1107
  finalizeInitialChildren(instance) {
1091
- var _instance$__r3f3;
1108
+ var _instance$__r3f2;
1092
1109
 
1093
- 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
1094
1111
  // Returning true will trigger commitMount
1095
1112
 
1096
1113
  return !!localState.handlers || !!localState.attach;
@@ -1131,11 +1148,11 @@ function createRenderer(roots, getEventPriority) {
1131
1148
  },
1132
1149
 
1133
1150
  commitMount(instance, type, props, int) {
1134
- var _instance$__r3f4;
1151
+ var _instance$__r3f3;
1135
1152
 
1136
1153
  // https://github.com/facebook/react/issues/20271
1137
1154
  // This will make sure events are only added once to the central container
1138
- const localState = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1155
+ const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
1139
1156
 
1140
1157
  if (instance.raycast && localState.handlers && localState.eventCount) {
1141
1158
  instance.__r3f.root.getState().internal.interaction.push(instance);
@@ -1143,7 +1160,9 @@ function createRenderer(roots, getEventPriority) {
1143
1160
 
1144
1161
 
1145
1162
  if (localState.attach) {
1146
- attach(localState.parent, instance, localState.attach);
1163
+ for (const parent of localState.parents) {
1164
+ attach(parent, instance, localState.attach);
1165
+ }
1147
1166
  }
1148
1167
  },
1149
1168
 
@@ -1281,7 +1300,8 @@ const createStore = (invalidate, advance) => {
1281
1300
  },
1282
1301
  size: {
1283
1302
  width: 0,
1284
- height: 0
1303
+ height: 0,
1304
+ updateStyle: false
1285
1305
  },
1286
1306
  viewport: {
1287
1307
  initialDpr: 0,
@@ -1298,11 +1318,12 @@ const createStore = (invalidate, advance) => {
1298
1318
  ...events
1299
1319
  }
1300
1320
  })),
1301
- setSize: (width, height) => {
1321
+ setSize: (width, height, updateStyle) => {
1302
1322
  const camera = get().camera;
1303
1323
  const size = {
1304
1324
  width,
1305
- height
1325
+ height,
1326
+ updateStyle
1306
1327
  };
1307
1328
  set(state => ({
1308
1329
  size,
@@ -1348,35 +1369,29 @@ const createStore = (invalidate, advance) => {
1348
1369
  initialHits: [],
1349
1370
  capturedMap: new Map(),
1350
1371
  subscribe: (ref, priority, store) => {
1351
- set(({
1352
- internal
1353
- }) => ({
1354
- internal: { ...internal,
1355
- // If this subscription was given a priority, it takes rendering into its own hands
1356
- // For that reason we switch off automatic rendering and increase the manual flag
1357
- // As long as this flag is positive there can be no internal rendering at all
1358
- // because there could be multiple render subscriptions
1359
- priority: internal.priority + (priority > 0 ? 1 : 0),
1360
- // Register subscriber and sort layers from lowest to highest, meaning,
1361
- // highest priority renders last (on top of the other frames)
1362
- subscribers: [...internal.subscribers, {
1363
- ref,
1364
- priority,
1365
- store
1366
- }].sort((a, b) => a.priority - b.priority)
1367
- }
1368
- }));
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);
1369
1386
  return () => {
1370
- set(({
1371
- internal
1372
- }) => ({
1373
- internal: { ...internal,
1374
- // Decrease manual flag if this subscription had a priority
1375
- priority: internal.priority - (priority > 0 ? 1 : 0),
1376
- // Remove subscriber from list
1377
- subscribers: internal.subscribers.filter(s => s.ref !== ref)
1378
- }
1379
- }));
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
+ }
1380
1395
  };
1381
1396
  }
1382
1397
  }
@@ -1398,7 +1413,7 @@ const createStore = (invalidate, advance) => {
1398
1413
  updateCamera(camera, size); // Update renderer
1399
1414
 
1400
1415
  gl.setPixelRatio(viewport.dpr);
1401
- gl.setSize(size.width, size.height);
1416
+ gl.setSize(size.width, size.height, size.updateStyle);
1402
1417
  oldSize = size;
1403
1418
  oldDpr = viewport.dpr;
1404
1419
  }
@@ -1820,7 +1835,7 @@ function createRoot(canvas) {
1820
1835
  width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
1821
1836
  height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
1822
1837
  };
1823
- 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
1824
1839
 
1825
1840
  if (state.frameloop !== frameloop) state.setFrameloop(frameloop); // Check pointer missed
1826
1841
 
@@ -2040,7 +2055,7 @@ function Portal({
2040
2055
  reconciler.injectIntoDevTools({
2041
2056
  bundleType: process.env.NODE_ENV === 'production' ? 0 : 1,
2042
2057
  rendererPackageName: '@react-three/fiber',
2043
- version: '18.0.0'
2058
+ version: React__namespace.version
2044
2059
  });
2045
2060
  const act = React__namespace.unstable_act;
2046
2061
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-c937c162.cjs.dev.js');
5
+ var index = require('./index-8e20caed.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-e2e71da1.cjs.prod.js');
5
+ var index = require('./index-786a40b6.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-acedf326.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-acedf326.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-30926efc.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-30926efc.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-c937c162.cjs.dev.js');
5
+ var index = require('../../dist/index-8e20caed.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-e2e71da1.cjs.prod.js');
5
+ var index = require('../../dist/index-786a40b6.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-acedf326.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-acedf326.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-30926efc.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-30926efc.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.18",
3
+ "version": "8.0.21",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",