@react-three/fiber 8.0.17 → 8.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @react-three/fiber
2
2
 
3
+ ## 8.0.18
4
+
5
+ ### Patch Changes
6
+
7
+ - be567c1: fix: suspense attach and three compat in webpack
8
+
3
9
  ## 8.0.17
4
10
 
5
11
  ### Patch Changes
@@ -79,3 +79,4 @@ export declare function updateInstance(instance: Instance): void;
79
79
  export declare function updateCamera(camera: Camera & {
80
80
  manual?: boolean;
81
81
  }, size: Size): void;
82
+ export declare function setDeep(obj: any, value: any, keys: string[]): any;
@@ -335,7 +335,7 @@ function applyProps$1(instance, data) {
335
335
  // Auto-convert sRGB colors
336
336
  // https://github.com/pmndrs/react-three-fiber/issues/344
337
337
 
338
- const supportsColorManagement = THREE.ColorManagement;
338
+ const supportsColorManagement = ('ColorManagement' in THREE);
339
339
  if (!supportsColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
340
340
  } // Else, just overwrite the value
341
341
 
@@ -391,6 +391,15 @@ function updateCamera(camera, size) {
391
391
  camera.updateMatrixWorld();
392
392
  }
393
393
  }
394
+ /**
395
+ * Safely sets a deeply-nested value on an object.
396
+ */
397
+
398
+ function setDeep(obj, value, keys) {
399
+ const key = keys.pop();
400
+ const target = keys.reduce((acc, key) => acc[key], obj);
401
+ return target[key] = value;
402
+ }
394
403
 
395
404
  function makeId(event) {
396
405
  return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
@@ -857,7 +866,7 @@ function createRenderer(roots, getEventPriority) {
857
866
  type,
858
867
  root,
859
868
  attach,
860
- // TODO: Figure out what this is for
869
+ // Save args in case we need to reconstruct later for HMR
861
870
  memoizedProps: {
862
871
  args
863
872
  }
@@ -878,10 +887,9 @@ function createRenderer(roots, getEventPriority) {
878
887
  if (child) {
879
888
  var _child$__r3f, _parentInstance$__r3f;
880
889
 
881
- // The attach attribute implies that the object attaches itself on the parent
882
- if ((_child$__r3f = child.__r3f) != null && _child$__r3f.attach) {
883
- attach(parentInstance, child, child.__r3f.attach);
884
- } else if (child.isObject3D && parentInstance.isObject3D) {
890
+ // The attach attribute implies that the object attaches itself on the parent.
891
+ // That is handled at commit to avoid duplication during Suspense
892
+ if (!((_child$__r3f = child.__r3f) != null && _child$__r3f.attach) && child.isObject3D && parentInstance.isObject3D) {
885
893
  // add in the usual parent-child way
886
894
  parentInstance.add(child);
887
895
  added = true;
@@ -947,7 +955,7 @@ function createRenderer(roots, getEventPriority) {
947
955
  if ((_child$__r3f4 = child.__r3f) != null && _child$__r3f4.root) {
948
956
  removeInteractivity(child.__r3f.root, child);
949
957
  }
950
- } // Allow objects to bail out of recursive dispose alltogether by passing dispose={null}
958
+ } // Allow objects to bail out of recursive dispose altogether by passing dispose={null}
951
959
  // Never dispose of primitives because their state may be kept outside of React!
952
960
  // In order for an object to be able to dispose it has to have
953
961
  // - a dispose method,
@@ -1058,7 +1066,7 @@ function createRenderer(roots, getEventPriority) {
1058
1066
  const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {}; // https://github.com/facebook/react/issues/20271
1059
1067
  // Returning true will trigger commitMount
1060
1068
 
1061
- return !!localState.handlers;
1069
+ return !!localState.handlers || !!localState.attach;
1062
1070
  },
1063
1071
 
1064
1072
  prepareUpdate(instance, type, oldProps, newProps) {
@@ -1104,6 +1112,11 @@ function createRenderer(roots, getEventPriority) {
1104
1112
 
1105
1113
  if (instance.raycast && localState.handlers && localState.eventCount) {
1106
1114
  instance.__r3f.root.getState().internal.interaction.push(instance);
1115
+ } // The attach attribute implies that the object attaches itself on the parent
1116
+
1117
+
1118
+ if (localState.attach) {
1119
+ attach(localState.parent, instance, localState.attach);
1107
1120
  }
1108
1121
  },
1109
1122
 
@@ -1117,27 +1130,11 @@ function createRenderer(roots, getEventPriority) {
1117
1130
  detachDeletedInstance: () => {},
1118
1131
 
1119
1132
  hideInstance(instance) {
1120
- var _instance$__r3f5;
1121
-
1122
- // Deatch while the instance is hidden
1123
- const {
1124
- attach: type,
1125
- parent
1126
- } = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1127
- if (type && parent) detach(parent, instance, type);
1128
1133
  if (instance.isObject3D) instance.visible = false;
1129
1134
  invalidateInstance(instance);
1130
1135
  },
1131
1136
 
1132
1137
  unhideInstance(instance, props) {
1133
- var _instance$__r3f6;
1134
-
1135
- // Re-attach when the instance is unhidden
1136
- const {
1137
- attach: type,
1138
- parent
1139
- } = (_instance$__r3f6 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f6 : {};
1140
- if (type && parent) attach(parent, instance, type);
1141
1138
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1142
1139
  invalidateInstance(instance);
1143
1140
  },
@@ -1761,11 +1758,12 @@ function createRoot(canvas) {
1761
1758
  if (!isBoolean) Object.assign(gl.shadowMap, shadows);else gl.shadowMap.type = THREE.PCFSoftShadowMap;
1762
1759
  if (old !== gl.shadowMap.enabled) gl.shadowMap.needsUpdate = true;
1763
1760
  }
1764
- } // Set color management
1761
+ } // Safely set color management if available.
1762
+ // Avoid accessing THREE.ColorManagement to play nice with older versions
1765
1763
 
1766
1764
 
1767
- if (THREE.ColorManagement) {
1768
- THREE.ColorManagement.legacyMode = legacy;
1765
+ if ('ColorManagement' in THREE) {
1766
+ setDeep(THREE, legacy, ['ColorManagement', 'legacyMode']);
1769
1767
  }
1770
1768
 
1771
1769
  const outputEncoding = linear ? THREE.LinearEncoding : THREE.sRGBEncoding;
@@ -362,7 +362,7 @@ function applyProps$1(instance, data) {
362
362
  // Auto-convert sRGB colors
363
363
  // https://github.com/pmndrs/react-three-fiber/issues/344
364
364
 
365
- const supportsColorManagement = THREE__namespace.ColorManagement;
365
+ const supportsColorManagement = ('ColorManagement' in THREE__namespace);
366
366
  if (!supportsColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
367
367
  } // Else, just overwrite the value
368
368
 
@@ -418,6 +418,15 @@ function updateCamera(camera, size) {
418
418
  camera.updateMatrixWorld();
419
419
  }
420
420
  }
421
+ /**
422
+ * Safely sets a deeply-nested value on an object.
423
+ */
424
+
425
+ function setDeep(obj, value, keys) {
426
+ const key = keys.pop();
427
+ const target = keys.reduce((acc, key) => acc[key], obj);
428
+ return target[key] = value;
429
+ }
421
430
 
422
431
  function makeId(event) {
423
432
  return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
@@ -884,7 +893,7 @@ function createRenderer(roots, getEventPriority) {
884
893
  type,
885
894
  root,
886
895
  attach,
887
- // TODO: Figure out what this is for
896
+ // Save args in case we need to reconstruct later for HMR
888
897
  memoizedProps: {
889
898
  args
890
899
  }
@@ -905,10 +914,9 @@ function createRenderer(roots, getEventPriority) {
905
914
  if (child) {
906
915
  var _child$__r3f, _parentInstance$__r3f;
907
916
 
908
- // The attach attribute implies that the object attaches itself on the parent
909
- if ((_child$__r3f = child.__r3f) != null && _child$__r3f.attach) {
910
- attach(parentInstance, child, child.__r3f.attach);
911
- } else if (child.isObject3D && parentInstance.isObject3D) {
917
+ // The attach attribute implies that the object attaches itself on the parent.
918
+ // That is handled at commit to avoid duplication during Suspense
919
+ if (!((_child$__r3f = child.__r3f) != null && _child$__r3f.attach) && child.isObject3D && parentInstance.isObject3D) {
912
920
  // add in the usual parent-child way
913
921
  parentInstance.add(child);
914
922
  added = true;
@@ -974,7 +982,7 @@ function createRenderer(roots, getEventPriority) {
974
982
  if ((_child$__r3f4 = child.__r3f) != null && _child$__r3f4.root) {
975
983
  removeInteractivity(child.__r3f.root, child);
976
984
  }
977
- } // Allow objects to bail out of recursive dispose alltogether by passing dispose={null}
985
+ } // Allow objects to bail out of recursive dispose altogether by passing dispose={null}
978
986
  // Never dispose of primitives because their state may be kept outside of React!
979
987
  // In order for an object to be able to dispose it has to have
980
988
  // - a dispose method,
@@ -1085,7 +1093,7 @@ function createRenderer(roots, getEventPriority) {
1085
1093
  const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {}; // https://github.com/facebook/react/issues/20271
1086
1094
  // Returning true will trigger commitMount
1087
1095
 
1088
- return !!localState.handlers;
1096
+ return !!localState.handlers || !!localState.attach;
1089
1097
  },
1090
1098
 
1091
1099
  prepareUpdate(instance, type, oldProps, newProps) {
@@ -1131,6 +1139,11 @@ function createRenderer(roots, getEventPriority) {
1131
1139
 
1132
1140
  if (instance.raycast && localState.handlers && localState.eventCount) {
1133
1141
  instance.__r3f.root.getState().internal.interaction.push(instance);
1142
+ } // The attach attribute implies that the object attaches itself on the parent
1143
+
1144
+
1145
+ if (localState.attach) {
1146
+ attach(localState.parent, instance, localState.attach);
1134
1147
  }
1135
1148
  },
1136
1149
 
@@ -1144,27 +1157,11 @@ function createRenderer(roots, getEventPriority) {
1144
1157
  detachDeletedInstance: () => {},
1145
1158
 
1146
1159
  hideInstance(instance) {
1147
- var _instance$__r3f5;
1148
-
1149
- // Deatch while the instance is hidden
1150
- const {
1151
- attach: type,
1152
- parent
1153
- } = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1154
- if (type && parent) detach(parent, instance, type);
1155
1160
  if (instance.isObject3D) instance.visible = false;
1156
1161
  invalidateInstance(instance);
1157
1162
  },
1158
1163
 
1159
1164
  unhideInstance(instance, props) {
1160
- var _instance$__r3f6;
1161
-
1162
- // Re-attach when the instance is unhidden
1163
- const {
1164
- attach: type,
1165
- parent
1166
- } = (_instance$__r3f6 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f6 : {};
1167
- if (type && parent) attach(parent, instance, type);
1168
1165
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1169
1166
  invalidateInstance(instance);
1170
1167
  },
@@ -1788,11 +1785,12 @@ function createRoot(canvas) {
1788
1785
  if (!isBoolean) Object.assign(gl.shadowMap, shadows);else gl.shadowMap.type = THREE__namespace.PCFSoftShadowMap;
1789
1786
  if (old !== gl.shadowMap.enabled) gl.shadowMap.needsUpdate = true;
1790
1787
  }
1791
- } // Set color management
1788
+ } // Safely set color management if available.
1789
+ // Avoid accessing THREE.ColorManagement to play nice with older versions
1792
1790
 
1793
1791
 
1794
- if (THREE__namespace.ColorManagement) {
1795
- THREE__namespace.ColorManagement.legacyMode = legacy;
1792
+ if ('ColorManagement' in THREE__namespace) {
1793
+ setDeep(THREE__namespace, legacy, ['ColorManagement', 'legacyMode']);
1796
1794
  }
1797
1795
 
1798
1796
  const outputEncoding = linear ? THREE__namespace.LinearEncoding : THREE__namespace.sRGBEncoding;
@@ -362,7 +362,7 @@ function applyProps$1(instance, data) {
362
362
  // Auto-convert sRGB colors
363
363
  // https://github.com/pmndrs/react-three-fiber/issues/344
364
364
 
365
- const supportsColorManagement = THREE__namespace.ColorManagement;
365
+ const supportsColorManagement = ('ColorManagement' in THREE__namespace);
366
366
  if (!supportsColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
367
367
  } // Else, just overwrite the value
368
368
 
@@ -418,6 +418,15 @@ function updateCamera(camera, size) {
418
418
  camera.updateMatrixWorld();
419
419
  }
420
420
  }
421
+ /**
422
+ * Safely sets a deeply-nested value on an object.
423
+ */
424
+
425
+ function setDeep(obj, value, keys) {
426
+ const key = keys.pop();
427
+ const target = keys.reduce((acc, key) => acc[key], obj);
428
+ return target[key] = value;
429
+ }
421
430
 
422
431
  function makeId(event) {
423
432
  return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
@@ -884,7 +893,7 @@ function createRenderer(roots, getEventPriority) {
884
893
  type,
885
894
  root,
886
895
  attach,
887
- // TODO: Figure out what this is for
896
+ // Save args in case we need to reconstruct later for HMR
888
897
  memoizedProps: {
889
898
  args
890
899
  }
@@ -905,10 +914,9 @@ function createRenderer(roots, getEventPriority) {
905
914
  if (child) {
906
915
  var _child$__r3f, _parentInstance$__r3f;
907
916
 
908
- // The attach attribute implies that the object attaches itself on the parent
909
- if ((_child$__r3f = child.__r3f) != null && _child$__r3f.attach) {
910
- attach(parentInstance, child, child.__r3f.attach);
911
- } else if (child.isObject3D && parentInstance.isObject3D) {
917
+ // The attach attribute implies that the object attaches itself on the parent.
918
+ // That is handled at commit to avoid duplication during Suspense
919
+ if (!((_child$__r3f = child.__r3f) != null && _child$__r3f.attach) && child.isObject3D && parentInstance.isObject3D) {
912
920
  // add in the usual parent-child way
913
921
  parentInstance.add(child);
914
922
  added = true;
@@ -974,7 +982,7 @@ function createRenderer(roots, getEventPriority) {
974
982
  if ((_child$__r3f4 = child.__r3f) != null && _child$__r3f4.root) {
975
983
  removeInteractivity(child.__r3f.root, child);
976
984
  }
977
- } // Allow objects to bail out of recursive dispose alltogether by passing dispose={null}
985
+ } // Allow objects to bail out of recursive dispose altogether by passing dispose={null}
978
986
  // Never dispose of primitives because their state may be kept outside of React!
979
987
  // In order for an object to be able to dispose it has to have
980
988
  // - a dispose method,
@@ -1085,7 +1093,7 @@ function createRenderer(roots, getEventPriority) {
1085
1093
  const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {}; // https://github.com/facebook/react/issues/20271
1086
1094
  // Returning true will trigger commitMount
1087
1095
 
1088
- return !!localState.handlers;
1096
+ return !!localState.handlers || !!localState.attach;
1089
1097
  },
1090
1098
 
1091
1099
  prepareUpdate(instance, type, oldProps, newProps) {
@@ -1131,6 +1139,11 @@ function createRenderer(roots, getEventPriority) {
1131
1139
 
1132
1140
  if (instance.raycast && localState.handlers && localState.eventCount) {
1133
1141
  instance.__r3f.root.getState().internal.interaction.push(instance);
1142
+ } // The attach attribute implies that the object attaches itself on the parent
1143
+
1144
+
1145
+ if (localState.attach) {
1146
+ attach(localState.parent, instance, localState.attach);
1134
1147
  }
1135
1148
  },
1136
1149
 
@@ -1144,27 +1157,11 @@ function createRenderer(roots, getEventPriority) {
1144
1157
  detachDeletedInstance: () => {},
1145
1158
 
1146
1159
  hideInstance(instance) {
1147
- var _instance$__r3f5;
1148
-
1149
- // Deatch while the instance is hidden
1150
- const {
1151
- attach: type,
1152
- parent
1153
- } = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1154
- if (type && parent) detach(parent, instance, type);
1155
1160
  if (instance.isObject3D) instance.visible = false;
1156
1161
  invalidateInstance(instance);
1157
1162
  },
1158
1163
 
1159
1164
  unhideInstance(instance, props) {
1160
- var _instance$__r3f6;
1161
-
1162
- // Re-attach when the instance is unhidden
1163
- const {
1164
- attach: type,
1165
- parent
1166
- } = (_instance$__r3f6 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f6 : {};
1167
- if (type && parent) attach(parent, instance, type);
1168
1165
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1169
1166
  invalidateInstance(instance);
1170
1167
  },
@@ -1788,11 +1785,12 @@ function createRoot(canvas) {
1788
1785
  if (!isBoolean) Object.assign(gl.shadowMap, shadows);else gl.shadowMap.type = THREE__namespace.PCFSoftShadowMap;
1789
1786
  if (old !== gl.shadowMap.enabled) gl.shadowMap.needsUpdate = true;
1790
1787
  }
1791
- } // Set color management
1788
+ } // Safely set color management if available.
1789
+ // Avoid accessing THREE.ColorManagement to play nice with older versions
1792
1790
 
1793
1791
 
1794
- if (THREE__namespace.ColorManagement) {
1795
- THREE__namespace.ColorManagement.legacyMode = legacy;
1792
+ if ('ColorManagement' in THREE__namespace) {
1793
+ setDeep(THREE__namespace, legacy, ['ColorManagement', 'legacyMode']);
1796
1794
  }
1797
1795
 
1798
1796
  const outputEncoding = linear ? THREE__namespace.LinearEncoding : THREE__namespace.sRGBEncoding;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-f3176a33.cjs.dev.js');
5
+ var index = require('./index-c937c162.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-4e1c76e5.cjs.prod.js');
5
+ var index = require('./index-e2e71da1.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-136ca0b0.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-136ca0b0.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-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';
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-f3176a33.cjs.dev.js');
5
+ var index = require('../../dist/index-c937c162.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-4e1c76e5.cjs.prod.js');
5
+ var index = require('../../dist/index-e2e71da1.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-136ca0b0.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-136ca0b0.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-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';
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.17",
3
+ "version": "8.0.18",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",