@react-three/fiber 7.0.23 → 7.0.24

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
+ ## 7.0.24
4
+
5
+ ### Patch Changes
6
+
7
+ - 7f46ddf: cleanup captured pointers when released (#1914)
8
+
3
9
  ## 7.0.23
4
10
 
5
11
  ### Patch Changes
@@ -74,7 +74,8 @@ const is = {
74
74
  function makeId(event) {
75
75
  return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
76
76
  }
77
- /** Release pointer captures.
77
+ /**
78
+ * Release pointer captures.
78
79
  * This is called by releasePointerCapture in the API, and when an object is removed.
79
80
  */
80
81
 
@@ -361,13 +362,16 @@ function createEvents(store) {
361
362
 
362
363
  case 'onLostPointerCapture':
363
364
  return event => {
364
- if ('pointerId' in event) {
365
+ const {
366
+ internal
367
+ } = store.getState();
368
+
369
+ if ('pointerId' in event && !internal.capturedMap.has(event.pointerId)) {
365
370
  // If the object event interface had onLostPointerCapture, we'd call it here on every
366
371
  // object that's getting removed.
367
- store.getState().internal.capturedMap.delete(event.pointerId);
372
+ internal.capturedMap.delete(event.pointerId);
373
+ cancelPointer([]);
368
374
  }
369
-
370
- cancelPointer([]);
371
375
  };
372
376
  } // Any other pointer goes here ...
373
377
 
@@ -837,7 +841,7 @@ function createRenderer(roots) {
837
841
  parentInstance[child.attachArray] = parentInstance[child.attachArray].filter(x => x !== child);
838
842
  } else if (child.attachObject) {
839
843
  delete parentInstance[child.attachObject[0]][child.attachObject[1]];
840
- } else if (child.attach && !is.fun(child.attach)) {
844
+ } else if (child.attach && !is.fun(child.attach) && parentInstance[child.attach] === child) {
841
845
  parentInstance[child.attach] = null;
842
846
  } else if (is.arr(child.attachFns)) {
843
847
  const [, detachFn] = child.attachFns;
@@ -985,7 +989,17 @@ function createRenderer(roots) {
985
989
  if (argsNew.some((value, index) => value !== argsOld[index])) return [true]; // Create a diff-set, flag if there are any changes
986
990
 
987
991
  const diff = diffProps(instance, restNew, restOld, true);
988
- if (diff.changes.length) return [false, diff]; // Otherwise do not touch the instance
992
+ if (diff.changes.length) return [false, diff]; // If instance was never attached, attach it
993
+
994
+ if (instance.attach && typeof instance.attach !== 'function') {
995
+ const localState = instance.__r3f;
996
+ const parent = localState.parent;
997
+
998
+ if (parent && parent[instance.attach] !== instance) {
999
+ appendChild(parent, instance);
1000
+ }
1001
+ } // Otherwise do not touch the instance
1002
+
989
1003
 
990
1004
  return null;
991
1005
  }
@@ -74,7 +74,8 @@ const is = {
74
74
  function makeId(event) {
75
75
  return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
76
76
  }
77
- /** Release pointer captures.
77
+ /**
78
+ * Release pointer captures.
78
79
  * This is called by releasePointerCapture in the API, and when an object is removed.
79
80
  */
80
81
 
@@ -361,13 +362,16 @@ function createEvents(store) {
361
362
 
362
363
  case 'onLostPointerCapture':
363
364
  return event => {
364
- if ('pointerId' in event) {
365
+ const {
366
+ internal
367
+ } = store.getState();
368
+
369
+ if ('pointerId' in event && !internal.capturedMap.has(event.pointerId)) {
365
370
  // If the object event interface had onLostPointerCapture, we'd call it here on every
366
371
  // object that's getting removed.
367
- store.getState().internal.capturedMap.delete(event.pointerId);
372
+ internal.capturedMap.delete(event.pointerId);
373
+ cancelPointer([]);
368
374
  }
369
-
370
- cancelPointer([]);
371
375
  };
372
376
  } // Any other pointer goes here ...
373
377
 
@@ -837,7 +841,7 @@ function createRenderer(roots) {
837
841
  parentInstance[child.attachArray] = parentInstance[child.attachArray].filter(x => x !== child);
838
842
  } else if (child.attachObject) {
839
843
  delete parentInstance[child.attachObject[0]][child.attachObject[1]];
840
- } else if (child.attach && !is.fun(child.attach)) {
844
+ } else if (child.attach && !is.fun(child.attach) && parentInstance[child.attach] === child) {
841
845
  parentInstance[child.attach] = null;
842
846
  } else if (is.arr(child.attachFns)) {
843
847
  const [, detachFn] = child.attachFns;
@@ -985,7 +989,17 @@ function createRenderer(roots) {
985
989
  if (argsNew.some((value, index) => value !== argsOld[index])) return [true]; // Create a diff-set, flag if there are any changes
986
990
 
987
991
  const diff = diffProps(instance, restNew, restOld, true);
988
- if (diff.changes.length) return [false, diff]; // Otherwise do not touch the instance
992
+ if (diff.changes.length) return [false, diff]; // If instance was never attached, attach it
993
+
994
+ if (instance.attach && typeof instance.attach !== 'function') {
995
+ const localState = instance.__r3f;
996
+ const parent = localState.parent;
997
+
998
+ if (parent && parent[instance.attach] !== instance) {
999
+ appendChild(parent, instance);
1000
+ }
1001
+ } // Otherwise do not touch the instance
1002
+
989
1003
 
990
1004
  return null;
991
1005
  }
@@ -41,7 +41,8 @@ const is = {
41
41
  function makeId(event) {
42
42
  return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
43
43
  }
44
- /** Release pointer captures.
44
+ /**
45
+ * Release pointer captures.
45
46
  * This is called by releasePointerCapture in the API, and when an object is removed.
46
47
  */
47
48
 
@@ -328,13 +329,16 @@ function createEvents(store) {
328
329
 
329
330
  case 'onLostPointerCapture':
330
331
  return event => {
331
- if ('pointerId' in event) {
332
+ const {
333
+ internal
334
+ } = store.getState();
335
+
336
+ if ('pointerId' in event && !internal.capturedMap.has(event.pointerId)) {
332
337
  // If the object event interface had onLostPointerCapture, we'd call it here on every
333
338
  // object that's getting removed.
334
- store.getState().internal.capturedMap.delete(event.pointerId);
339
+ internal.capturedMap.delete(event.pointerId);
340
+ cancelPointer([]);
335
341
  }
336
-
337
- cancelPointer([]);
338
342
  };
339
343
  } // Any other pointer goes here ...
340
344
 
@@ -804,7 +808,7 @@ function createRenderer(roots) {
804
808
  parentInstance[child.attachArray] = parentInstance[child.attachArray].filter(x => x !== child);
805
809
  } else if (child.attachObject) {
806
810
  delete parentInstance[child.attachObject[0]][child.attachObject[1]];
807
- } else if (child.attach && !is.fun(child.attach)) {
811
+ } else if (child.attach && !is.fun(child.attach) && parentInstance[child.attach] === child) {
808
812
  parentInstance[child.attach] = null;
809
813
  } else if (is.arr(child.attachFns)) {
810
814
  const [, detachFn] = child.attachFns;
@@ -952,7 +956,17 @@ function createRenderer(roots) {
952
956
  if (argsNew.some((value, index) => value !== argsOld[index])) return [true]; // Create a diff-set, flag if there are any changes
953
957
 
954
958
  const diff = diffProps(instance, restNew, restOld, true);
955
- if (diff.changes.length) return [false, diff]; // Otherwise do not touch the instance
959
+ if (diff.changes.length) return [false, diff]; // If instance was never attached, attach it
960
+
961
+ if (instance.attach && typeof instance.attach !== 'function') {
962
+ const localState = instance.__r3f;
963
+ const parent = localState.parent;
964
+
965
+ if (parent && parent[instance.attach] !== instance) {
966
+ appendChild(parent, instance);
967
+ }
968
+ } // Otherwise do not touch the instance
969
+
956
970
 
957
971
  return null;
958
972
  }