@react-three/fiber 8.0.20 → 8.0.23

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.
@@ -1,9 +1,9 @@
1
- import * as React from 'react';
2
- import type { Options as ResizeOptions } from 'react-use-measure';
3
- import { RenderProps } from '../core';
4
- export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size'>, React.HTMLAttributes<HTMLDivElement> {
5
- children: React.ReactNode;
6
- fallback?: React.ReactNode;
7
- resize?: ResizeOptions;
8
- }
9
- export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
1
+ import * as React from 'react';
2
+ import type { Options as ResizeOptions } from 'react-use-measure';
3
+ import { RenderProps } from '../core';
4
+ export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size'>, React.HTMLAttributes<HTMLDivElement> {
5
+ children: React.ReactNode;
6
+ fallback?: React.ReactNode;
7
+ resize?: ResizeOptions;
8
+ }
9
+ export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
@@ -1,4 +1,4 @@
1
- import { UseBoundStore } from 'zustand';
2
- import { RootState } from '../core/store';
3
- import { EventManager } from '../core/events';
4
- export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
1
+ import { UseBoundStore } from 'zustand';
2
+ import { RootState } from '../core/store';
3
+ import { EventManager } from '../core/events';
4
+ export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
@@ -164,7 +164,7 @@ function dispose(obj) {
164
164
  function prepare(object, state) {
165
165
  const instance = object;
166
166
 
167
- if (!instance.__r3f) {
167
+ if (state != null && state.primitive || !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
- parents: [],
176
+ parent: null,
177
177
  ...state
178
178
  };
179
179
  }
@@ -287,7 +287,7 @@ function diffProps(instance, {
287
287
  } // This function applies a set of changes to the instance
288
288
 
289
289
  function applyProps$1(instance, data) {
290
- var _instance$__r3f3, _root$getState, _localState$parents;
290
+ var _instance$__r3f3, _root$getState;
291
291
 
292
292
  // Filter equals, events and reserved props
293
293
  const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
@@ -378,7 +378,7 @@ function applyProps$1(instance, data) {
378
378
  invalidateInstance(instance);
379
379
  });
380
380
 
381
- if ((_localState$parents = localState.parents) != null && _localState$parents.length && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
381
+ if (localState.parent && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
382
382
  // Pre-emptively remove the instance from the interaction manager
383
383
  const index = rootState.internal.interaction.indexOf(instance);
384
384
  if (index > -1) rootState.internal.interaction.splice(index, 1); // Add the instance to the interaction manager only when it has handlers
@@ -925,9 +925,7 @@ function createRenderer(roots, getEventPriority) {
925
925
 
926
926
  if (!added) (_parentInstance$__r3f = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f.objects.push(child);
927
927
  if (!child.__r3f) prepare(child, {});
928
-
929
- child.__r3f.parents.push(parentInstance);
930
-
928
+ child.__r3f.parent = parentInstance;
931
929
  updateInstance(child);
932
930
  invalidateInstance(child);
933
931
  }
@@ -952,9 +950,7 @@ function createRenderer(roots, getEventPriority) {
952
950
 
953
951
  if (!added) (_parentInstance$__r3f2 = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f2.objects.push(child);
954
952
  if (!child.__r3f) prepare(child, {});
955
-
956
- child.__r3f.parents.push(parentInstance);
957
-
953
+ child.__r3f.parent = parentInstance;
958
954
  updateInstance(child);
959
955
  invalidateInstance(child);
960
956
  }
@@ -969,7 +965,7 @@ function createRenderer(roots, getEventPriority) {
969
965
  var _parentInstance$__r3f3, _child$__r3f3, _child$__r3f5;
970
966
 
971
967
  // Clear the parent reference
972
- if (child.__r3f) child.__r3f.parents = child.__r3f.parents.filter(parent => parent !== parentInstance); // Remove child from the parents objects
968
+ if (child.__r3f) child.__r3f.parent = null; // Remove child from the parents objects
973
969
 
974
970
  if ((_parentInstance$__r3f3 = parentInstance.__r3f) != null && _parentInstance$__r3f3.objects) parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child); // Remove attachment
975
971
 
@@ -1032,8 +1028,8 @@ function createRenderer(roots, getEventPriority) {
1032
1028
  function switchInstance(instance, type, newProps, fiber) {
1033
1029
  var _instance$__r3f, _newInstance$__r3f;
1034
1030
 
1035
- const parents = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parents;
1036
- if (!(parents != null && parents.length)) return;
1031
+ const parent = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parent;
1032
+ if (!parent) return;
1037
1033
  const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1038
1034
  // When args change the instance has to be re-constructed, which then
1039
1035
  // forces r3f to re-parent the children and non-scene objects
@@ -1042,29 +1038,28 @@ function createRenderer(roots, getEventPriority) {
1042
1038
  if (type !== 'primitive' && instance.children) {
1043
1039
  instance.children.forEach(child => appendChild(newInstance, child));
1044
1040
  instance.children = [];
1045
- }
1046
-
1047
- instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
1041
+ } // Copy over child attachments
1048
1042
 
1049
- instance.__r3f.objects = [];
1050
1043
 
1051
- for (const parent of parents) {
1052
- removeChild(parent, instance);
1053
- appendChild(parent, newInstance);
1054
- } // Re-bind event handlers
1044
+ for (const child of instance.__r3f.objects) {
1045
+ appendChild(newInstance, child);
1046
+ detach(instance, child, child.__r3f.attach);
1047
+ attach(newInstance, child, child.__r3f.attach);
1048
+ }
1055
1049
 
1050
+ instance.__r3f.objects = [];
1051
+ removeChild(parent, instance);
1052
+ appendChild(parent, newInstance); // Re-bind event handlers
1056
1053
 
1057
1054
  if (newInstance.raycast && newInstance.__r3f.eventCount) {
1058
1055
  const rootState = newInstance.__r3f.root.getState();
1059
1056
 
1060
1057
  rootState.internal.interaction.push(newInstance);
1061
- } // The attach attribute implies that the object attaches itself on the parent
1058
+ } // Attach instance to parent
1062
1059
 
1063
1060
 
1064
1061
  if ((_newInstance$__r3f = newInstance.__r3f) != null && _newInstance$__r3f.attach) {
1065
- for (const parent of parents) {
1066
- attach(parent, newInstance, newInstance.__r3f.attach);
1067
- }
1062
+ attach(parent, newInstance, newInstance.__r3f.attach);
1068
1063
  } // This evil hack switches the react-internal fiber node
1069
1064
  [fiber, fiber.alternate].forEach(fiber => {
1070
1065
  if (fiber !== null) {
@@ -1154,10 +1149,8 @@ function createRenderer(roots, getEventPriority) {
1154
1149
  } // The attach attribute implies that the object attaches itself on the parent
1155
1150
 
1156
1151
 
1157
- if (localState.attach) {
1158
- for (const parent of localState.parents) {
1159
- attach(parent, instance, localState.attach);
1160
- }
1152
+ if (localState.parent && localState.attach) {
1153
+ attach(localState.parent, instance, localState.attach);
1161
1154
  }
1162
1155
  },
1163
1156
 
@@ -1295,7 +1288,8 @@ const createStore = (invalidate, advance) => {
1295
1288
  },
1296
1289
  size: {
1297
1290
  width: 0,
1298
- height: 0
1291
+ height: 0,
1292
+ updateStyle: false
1299
1293
  },
1300
1294
  viewport: {
1301
1295
  initialDpr: 0,
@@ -1312,11 +1306,12 @@ const createStore = (invalidate, advance) => {
1312
1306
  ...events
1313
1307
  }
1314
1308
  })),
1315
- setSize: (width, height) => {
1309
+ setSize: (width, height, updateStyle) => {
1316
1310
  const camera = get().camera;
1317
1311
  const size = {
1318
1312
  width,
1319
- height
1313
+ height,
1314
+ updateStyle
1320
1315
  };
1321
1316
  set(state => ({
1322
1317
  size,
@@ -1406,7 +1401,7 @@ const createStore = (invalidate, advance) => {
1406
1401
  updateCamera(camera, size); // Update renderer
1407
1402
 
1408
1403
  gl.setPixelRatio(viewport.dpr);
1409
- gl.setSize(size.width, size.height);
1404
+ gl.setSize(size.width, size.height, size.updateStyle);
1410
1405
  oldSize = size;
1411
1406
  oldDpr = viewport.dpr;
1412
1407
  }
@@ -1828,7 +1823,7 @@ function createRoot(canvas) {
1828
1823
  width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
1829
1824
  height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
1830
1825
  };
1831
- if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height); // Check frameloop
1826
+ if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height, size.updateStyle); // Check frameloop
1832
1827
 
1833
1828
  if (state.frameloop !== frameloop) state.setFrameloop(frameloop); // Check pointer missed
1834
1829
 
@@ -137,7 +137,7 @@ function dispose(obj) {
137
137
  function prepare(object, state) {
138
138
  const instance = object;
139
139
 
140
- if (!instance.__r3f) {
140
+ if (state != null && state.primitive || !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
- parents: [],
149
+ parent: null,
150
150
  ...state
151
151
  };
152
152
  }
@@ -260,7 +260,7 @@ 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, _localState$parents;
263
+ var _instance$__r3f3, _root$getState;
264
264
 
265
265
  // Filter equals, events and reserved props
266
266
  const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
@@ -351,7 +351,7 @@ function applyProps$1(instance, data) {
351
351
  invalidateInstance(instance);
352
352
  });
353
353
 
354
- if ((_localState$parents = localState.parents) != null && _localState$parents.length && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
354
+ if (localState.parent && 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
@@ -898,9 +898,7 @@ function createRenderer(roots, getEventPriority) {
898
898
 
899
899
  if (!added) (_parentInstance$__r3f = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f.objects.push(child);
900
900
  if (!child.__r3f) prepare(child, {});
901
-
902
- child.__r3f.parents.push(parentInstance);
903
-
901
+ child.__r3f.parent = parentInstance;
904
902
  updateInstance(child);
905
903
  invalidateInstance(child);
906
904
  }
@@ -925,9 +923,7 @@ function createRenderer(roots, getEventPriority) {
925
923
 
926
924
  if (!added) (_parentInstance$__r3f2 = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f2.objects.push(child);
927
925
  if (!child.__r3f) prepare(child, {});
928
-
929
- child.__r3f.parents.push(parentInstance);
930
-
926
+ child.__r3f.parent = parentInstance;
931
927
  updateInstance(child);
932
928
  invalidateInstance(child);
933
929
  }
@@ -942,7 +938,7 @@ function createRenderer(roots, getEventPriority) {
942
938
  var _parentInstance$__r3f3, _child$__r3f3, _child$__r3f5;
943
939
 
944
940
  // Clear the parent reference
945
- if (child.__r3f) child.__r3f.parents = child.__r3f.parents.filter(parent => parent !== parentInstance); // Remove child from the parents objects
941
+ if (child.__r3f) child.__r3f.parent = null; // Remove child from the parents objects
946
942
 
947
943
  if ((_parentInstance$__r3f3 = parentInstance.__r3f) != null && _parentInstance$__r3f3.objects) parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child); // Remove attachment
948
944
 
@@ -1005,8 +1001,8 @@ function createRenderer(roots, getEventPriority) {
1005
1001
  function switchInstance(instance, type, newProps, fiber) {
1006
1002
  var _instance$__r3f, _newInstance$__r3f;
1007
1003
 
1008
- const parents = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parents;
1009
- if (!(parents != null && parents.length)) return;
1004
+ const parent = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parent;
1005
+ if (!parent) return;
1010
1006
  const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1011
1007
  // When args change the instance has to be re-constructed, which then
1012
1008
  // forces r3f to re-parent the children and non-scene objects
@@ -1015,29 +1011,28 @@ function createRenderer(roots, getEventPriority) {
1015
1011
  if (type !== 'primitive' && instance.children) {
1016
1012
  instance.children.forEach(child => appendChild(newInstance, child));
1017
1013
  instance.children = [];
1018
- }
1019
-
1020
- instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
1014
+ } // Copy over child attachments
1021
1015
 
1022
- instance.__r3f.objects = [];
1023
1016
 
1024
- for (const parent of parents) {
1025
- removeChild(parent, instance);
1026
- appendChild(parent, newInstance);
1027
- } // Re-bind event handlers
1017
+ for (const child of instance.__r3f.objects) {
1018
+ appendChild(newInstance, child);
1019
+ detach(instance, child, child.__r3f.attach);
1020
+ attach(newInstance, child, child.__r3f.attach);
1021
+ }
1028
1022
 
1023
+ instance.__r3f.objects = [];
1024
+ removeChild(parent, instance);
1025
+ appendChild(parent, newInstance); // Re-bind event handlers
1029
1026
 
1030
1027
  if (newInstance.raycast && newInstance.__r3f.eventCount) {
1031
1028
  const rootState = newInstance.__r3f.root.getState();
1032
1029
 
1033
1030
  rootState.internal.interaction.push(newInstance);
1034
- } // The attach attribute implies that the object attaches itself on the parent
1031
+ } // Attach instance to parent
1035
1032
 
1036
1033
 
1037
1034
  if ((_newInstance$__r3f = newInstance.__r3f) != null && _newInstance$__r3f.attach) {
1038
- for (const parent of parents) {
1039
- attach(parent, newInstance, newInstance.__r3f.attach);
1040
- }
1035
+ attach(parent, newInstance, newInstance.__r3f.attach);
1041
1036
  } // This evil hack switches the react-internal fiber node
1042
1037
  [fiber, fiber.alternate].forEach(fiber => {
1043
1038
  if (fiber !== null) {
@@ -1127,10 +1122,8 @@ function createRenderer(roots, getEventPriority) {
1127
1122
  } // The attach attribute implies that the object attaches itself on the parent
1128
1123
 
1129
1124
 
1130
- if (localState.attach) {
1131
- for (const parent of localState.parents) {
1132
- attach(parent, instance, localState.attach);
1133
- }
1125
+ if (localState.parent && localState.attach) {
1126
+ attach(localState.parent, instance, localState.attach);
1134
1127
  }
1135
1128
  },
1136
1129
 
@@ -1268,7 +1261,8 @@ const createStore = (invalidate, advance) => {
1268
1261
  },
1269
1262
  size: {
1270
1263
  width: 0,
1271
- height: 0
1264
+ height: 0,
1265
+ updateStyle: false
1272
1266
  },
1273
1267
  viewport: {
1274
1268
  initialDpr: 0,
@@ -1285,11 +1279,12 @@ const createStore = (invalidate, advance) => {
1285
1279
  ...events
1286
1280
  }
1287
1281
  })),
1288
- setSize: (width, height) => {
1282
+ setSize: (width, height, updateStyle) => {
1289
1283
  const camera = get().camera;
1290
1284
  const size = {
1291
1285
  width,
1292
- height
1286
+ height,
1287
+ updateStyle
1293
1288
  };
1294
1289
  set(state => ({
1295
1290
  size,
@@ -1379,7 +1374,7 @@ const createStore = (invalidate, advance) => {
1379
1374
  updateCamera(camera, size); // Update renderer
1380
1375
 
1381
1376
  gl.setPixelRatio(viewport.dpr);
1382
- gl.setSize(size.width, size.height);
1377
+ gl.setSize(size.width, size.height, size.updateStyle);
1383
1378
  oldSize = size;
1384
1379
  oldDpr = viewport.dpr;
1385
1380
  }
@@ -1801,7 +1796,7 @@ function createRoot(canvas) {
1801
1796
  width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
1802
1797
  height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
1803
1798
  };
1804
- if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height); // Check frameloop
1799
+ if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height, size.updateStyle); // Check frameloop
1805
1800
 
1806
1801
  if (state.frameloop !== frameloop) state.setFrameloop(frameloop); // Check pointer missed
1807
1802
 
@@ -164,7 +164,7 @@ function dispose(obj) {
164
164
  function prepare(object, state) {
165
165
  const instance = object;
166
166
 
167
- if (!instance.__r3f) {
167
+ if (state != null && state.primitive || !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
- parents: [],
176
+ parent: null,
177
177
  ...state
178
178
  };
179
179
  }
@@ -287,7 +287,7 @@ function diffProps(instance, {
287
287
  } // This function applies a set of changes to the instance
288
288
 
289
289
  function applyProps$1(instance, data) {
290
- var _instance$__r3f3, _root$getState, _localState$parents;
290
+ var _instance$__r3f3, _root$getState;
291
291
 
292
292
  // Filter equals, events and reserved props
293
293
  const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
@@ -378,7 +378,7 @@ function applyProps$1(instance, data) {
378
378
  invalidateInstance(instance);
379
379
  });
380
380
 
381
- if ((_localState$parents = localState.parents) != null && _localState$parents.length && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
381
+ if (localState.parent && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
382
382
  // Pre-emptively remove the instance from the interaction manager
383
383
  const index = rootState.internal.interaction.indexOf(instance);
384
384
  if (index > -1) rootState.internal.interaction.splice(index, 1); // Add the instance to the interaction manager only when it has handlers
@@ -925,9 +925,7 @@ function createRenderer(roots, getEventPriority) {
925
925
 
926
926
  if (!added) (_parentInstance$__r3f = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f.objects.push(child);
927
927
  if (!child.__r3f) prepare(child, {});
928
-
929
- child.__r3f.parents.push(parentInstance);
930
-
928
+ child.__r3f.parent = parentInstance;
931
929
  updateInstance(child);
932
930
  invalidateInstance(child);
933
931
  }
@@ -952,9 +950,7 @@ function createRenderer(roots, getEventPriority) {
952
950
 
953
951
  if (!added) (_parentInstance$__r3f2 = parentInstance.__r3f) == null ? void 0 : _parentInstance$__r3f2.objects.push(child);
954
952
  if (!child.__r3f) prepare(child, {});
955
-
956
- child.__r3f.parents.push(parentInstance);
957
-
953
+ child.__r3f.parent = parentInstance;
958
954
  updateInstance(child);
959
955
  invalidateInstance(child);
960
956
  }
@@ -969,7 +965,7 @@ function createRenderer(roots, getEventPriority) {
969
965
  var _parentInstance$__r3f3, _child$__r3f3, _child$__r3f5;
970
966
 
971
967
  // Clear the parent reference
972
- if (child.__r3f) child.__r3f.parents = child.__r3f.parents.filter(parent => parent !== parentInstance); // Remove child from the parents objects
968
+ if (child.__r3f) child.__r3f.parent = null; // Remove child from the parents objects
973
969
 
974
970
  if ((_parentInstance$__r3f3 = parentInstance.__r3f) != null && _parentInstance$__r3f3.objects) parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child); // Remove attachment
975
971
 
@@ -1032,8 +1028,8 @@ function createRenderer(roots, getEventPriority) {
1032
1028
  function switchInstance(instance, type, newProps, fiber) {
1033
1029
  var _instance$__r3f, _newInstance$__r3f;
1034
1030
 
1035
- const parents = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parents;
1036
- if (!(parents != null && parents.length)) return;
1031
+ const parent = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parent;
1032
+ if (!parent) return;
1037
1033
  const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1038
1034
  // When args change the instance has to be re-constructed, which then
1039
1035
  // forces r3f to re-parent the children and non-scene objects
@@ -1042,29 +1038,28 @@ function createRenderer(roots, getEventPriority) {
1042
1038
  if (type !== 'primitive' && instance.children) {
1043
1039
  instance.children.forEach(child => appendChild(newInstance, child));
1044
1040
  instance.children = [];
1045
- }
1046
-
1047
- instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
1041
+ } // Copy over child attachments
1048
1042
 
1049
- instance.__r3f.objects = [];
1050
1043
 
1051
- for (const parent of parents) {
1052
- removeChild(parent, instance);
1053
- appendChild(parent, newInstance);
1054
- } // Re-bind event handlers
1044
+ for (const child of instance.__r3f.objects) {
1045
+ appendChild(newInstance, child);
1046
+ detach(instance, child, child.__r3f.attach);
1047
+ attach(newInstance, child, child.__r3f.attach);
1048
+ }
1055
1049
 
1050
+ instance.__r3f.objects = [];
1051
+ removeChild(parent, instance);
1052
+ appendChild(parent, newInstance); // Re-bind event handlers
1056
1053
 
1057
1054
  if (newInstance.raycast && newInstance.__r3f.eventCount) {
1058
1055
  const rootState = newInstance.__r3f.root.getState();
1059
1056
 
1060
1057
  rootState.internal.interaction.push(newInstance);
1061
- } // The attach attribute implies that the object attaches itself on the parent
1058
+ } // Attach instance to parent
1062
1059
 
1063
1060
 
1064
1061
  if ((_newInstance$__r3f = newInstance.__r3f) != null && _newInstance$__r3f.attach) {
1065
- for (const parent of parents) {
1066
- attach(parent, newInstance, newInstance.__r3f.attach);
1067
- }
1062
+ attach(parent, newInstance, newInstance.__r3f.attach);
1068
1063
  } // This evil hack switches the react-internal fiber node
1069
1064
  [fiber, fiber.alternate].forEach(fiber => {
1070
1065
  if (fiber !== null) {
@@ -1154,10 +1149,8 @@ function createRenderer(roots, getEventPriority) {
1154
1149
  } // The attach attribute implies that the object attaches itself on the parent
1155
1150
 
1156
1151
 
1157
- if (localState.attach) {
1158
- for (const parent of localState.parents) {
1159
- attach(parent, instance, localState.attach);
1160
- }
1152
+ if (localState.parent && localState.attach) {
1153
+ attach(localState.parent, instance, localState.attach);
1161
1154
  }
1162
1155
  },
1163
1156
 
@@ -1295,7 +1288,8 @@ const createStore = (invalidate, advance) => {
1295
1288
  },
1296
1289
  size: {
1297
1290
  width: 0,
1298
- height: 0
1291
+ height: 0,
1292
+ updateStyle: false
1299
1293
  },
1300
1294
  viewport: {
1301
1295
  initialDpr: 0,
@@ -1312,11 +1306,12 @@ const createStore = (invalidate, advance) => {
1312
1306
  ...events
1313
1307
  }
1314
1308
  })),
1315
- setSize: (width, height) => {
1309
+ setSize: (width, height, updateStyle) => {
1316
1310
  const camera = get().camera;
1317
1311
  const size = {
1318
1312
  width,
1319
- height
1313
+ height,
1314
+ updateStyle
1320
1315
  };
1321
1316
  set(state => ({
1322
1317
  size,
@@ -1406,7 +1401,7 @@ const createStore = (invalidate, advance) => {
1406
1401
  updateCamera(camera, size); // Update renderer
1407
1402
 
1408
1403
  gl.setPixelRatio(viewport.dpr);
1409
- gl.setSize(size.width, size.height);
1404
+ gl.setSize(size.width, size.height, size.updateStyle);
1410
1405
  oldSize = size;
1411
1406
  oldDpr = viewport.dpr;
1412
1407
  }
@@ -1828,7 +1823,7 @@ function createRoot(canvas) {
1828
1823
  width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
1829
1824
  height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
1830
1825
  };
1831
- if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height); // Check frameloop
1826
+ if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height, size.updateStyle); // Check frameloop
1832
1827
 
1833
1828
  if (state.frameloop !== frameloop) state.setFrameloop(frameloop); // Check pointer missed
1834
1829
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-f796b922.cjs.dev.js');
5
+ var index = require('./index-1c8e10cf.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-d2826534.cjs.prod.js');
5
+ var index = require('./index-e8067a9e.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-2de7e188.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-2de7e188.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-ac97daed.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-ac97daed.esm.js';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-f796b922.cjs.dev.js');
5
+ var index = require('../../dist/index-1c8e10cf.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-d2826534.cjs.prod.js');
5
+ var index = require('../../dist/index-e8067a9e.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-2de7e188.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-2de7e188.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-ac97daed.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-ac97daed.esm.js';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.0.20",
3
+ "version": "8.0.23",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",