@react-three/fiber 8.4.1 → 8.6.0

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,16 +1,22 @@
1
1
  # @react-three/fiber
2
2
 
3
- ## 8.4.1
3
+ ## 8.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 85c80e70: eventsource and eventprefix on the canvas component
8
+
9
+ ## 8.5.1
4
10
 
5
11
  ### Patch Changes
6
12
 
7
- - 7d29f5dc: Rename eventTarget to eventSource
13
+ - 87821d9: fix: null-check instance.children on reconstruct
8
14
 
9
- ## 8.4.0
15
+ ## 8.5.0
10
16
 
11
17
  ### Minor Changes
12
18
 
13
- - 5a7b5321: Add eventTarget and eventPrefix
19
+ - edc8252: feat: handle primitive children, auto-attach via instanceof
14
20
 
15
21
  ## 8.3.1
16
22
 
@@ -869,11 +869,7 @@ function createRenderer(_roots, _getEventPriority) {
869
869
  ...props
870
870
  }, root) {
871
871
  let name = `${type[0].toUpperCase()}${type.slice(1)}`;
872
- let instance; // Auto-attach geometries and materials
873
-
874
- if (attach === undefined) {
875
- if (name.endsWith('Geometry')) attach = 'geometry';else if (name.endsWith('Material')) attach = 'material';
876
- }
872
+ let instance;
877
873
 
878
874
  if (type === 'primitive') {
879
875
  if (props.object === undefined) throw new Error("R3F: Primitives without 'object' are invalid!");
@@ -904,6 +900,11 @@ function createRenderer(_roots, _getEventPriority) {
904
900
  args
905
901
  }
906
902
  });
903
+ } // Auto-attach geometries and materials
904
+
905
+
906
+ if (instance.__r3f.attach === undefined) {
907
+ if (instance instanceof THREE__namespace.BufferGeometry) instance.__r3f.attach = 'geometry';else if (instance instanceof THREE__namespace.Material) instance.__r3f.attach = 'material';
907
908
  } // It should NOT call onUpdate on object instanciation, because it hasn't been added to the
908
909
  // view yet. If the callback relies on references for instance, they won't be ready yet, this is
909
910
  // why it passes "true" here
@@ -1043,11 +1044,13 @@ function createRenderer(_roots, _getEventPriority) {
1043
1044
  const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1044
1045
  // When args change the instance has to be re-constructed, which then
1045
1046
  // forces r3f to re-parent the children and non-scene objects
1046
- // This can not include primitives, which should not have declarative children
1047
1047
 
1048
- if (type !== 'primitive' && instance.children) {
1049
- instance.children.forEach(child => appendChild(newInstance, child));
1050
- instance.children = [];
1048
+ if (instance.children) {
1049
+ for (const child of instance.children) {
1050
+ if (child.__r3f) appendChild(newInstance, child);
1051
+ }
1052
+
1053
+ instance.children = instance.children.filter(child => !child.__r3f);
1051
1054
  }
1052
1055
 
1053
1056
  instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
@@ -1169,11 +1172,11 @@ function createRenderer(_roots, _getEventPriority) {
1169
1172
  hideInstance(instance) {
1170
1173
  var _instance$__r3f4;
1171
1174
 
1172
- // Deatch while the instance is hidden
1175
+ // Detach while the instance is hidden
1173
1176
  const {
1174
1177
  attach: type,
1175
1178
  parent
1176
- } = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1179
+ } = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
1177
1180
  if (type && parent) detach(parent, instance, type);
1178
1181
  if (instance.isObject3D) instance.visible = false;
1179
1182
  invalidateInstance(instance);
@@ -1186,7 +1189,7 @@ function createRenderer(_roots, _getEventPriority) {
1186
1189
  const {
1187
1190
  attach: type,
1188
1191
  parent
1189
- } = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1192
+ } = (_instance$__r3f5 = instance.__r3f) != null ? _instance$__r3f5 : {};
1190
1193
  if (type && parent) attach(parent, instance, type);
1191
1194
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1192
1195
  invalidateInstance(instance);
@@ -869,11 +869,7 @@ function createRenderer(_roots, _getEventPriority) {
869
869
  ...props
870
870
  }, root) {
871
871
  let name = `${type[0].toUpperCase()}${type.slice(1)}`;
872
- let instance; // Auto-attach geometries and materials
873
-
874
- if (attach === undefined) {
875
- if (name.endsWith('Geometry')) attach = 'geometry';else if (name.endsWith('Material')) attach = 'material';
876
- }
872
+ let instance;
877
873
 
878
874
  if (type === 'primitive') {
879
875
  if (props.object === undefined) throw new Error("R3F: Primitives without 'object' are invalid!");
@@ -904,6 +900,11 @@ function createRenderer(_roots, _getEventPriority) {
904
900
  args
905
901
  }
906
902
  });
903
+ } // Auto-attach geometries and materials
904
+
905
+
906
+ if (instance.__r3f.attach === undefined) {
907
+ if (instance instanceof THREE__namespace.BufferGeometry) instance.__r3f.attach = 'geometry';else if (instance instanceof THREE__namespace.Material) instance.__r3f.attach = 'material';
907
908
  } // It should NOT call onUpdate on object instanciation, because it hasn't been added to the
908
909
  // view yet. If the callback relies on references for instance, they won't be ready yet, this is
909
910
  // why it passes "true" here
@@ -1043,11 +1044,13 @@ function createRenderer(_roots, _getEventPriority) {
1043
1044
  const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1044
1045
  // When args change the instance has to be re-constructed, which then
1045
1046
  // forces r3f to re-parent the children and non-scene objects
1046
- // This can not include primitives, which should not have declarative children
1047
1047
 
1048
- if (type !== 'primitive' && instance.children) {
1049
- instance.children.forEach(child => appendChild(newInstance, child));
1050
- instance.children = [];
1048
+ if (instance.children) {
1049
+ for (const child of instance.children) {
1050
+ if (child.__r3f) appendChild(newInstance, child);
1051
+ }
1052
+
1053
+ instance.children = instance.children.filter(child => !child.__r3f);
1051
1054
  }
1052
1055
 
1053
1056
  instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
@@ -1169,11 +1172,11 @@ function createRenderer(_roots, _getEventPriority) {
1169
1172
  hideInstance(instance) {
1170
1173
  var _instance$__r3f4;
1171
1174
 
1172
- // Deatch while the instance is hidden
1175
+ // Detach while the instance is hidden
1173
1176
  const {
1174
1177
  attach: type,
1175
1178
  parent
1176
- } = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1179
+ } = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
1177
1180
  if (type && parent) detach(parent, instance, type);
1178
1181
  if (instance.isObject3D) instance.visible = false;
1179
1182
  invalidateInstance(instance);
@@ -1186,7 +1189,7 @@ function createRenderer(_roots, _getEventPriority) {
1186
1189
  const {
1187
1190
  attach: type,
1188
1191
  parent
1189
- } = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1192
+ } = (_instance$__r3f5 = instance.__r3f) != null ? _instance$__r3f5 : {};
1190
1193
  if (type && parent) attach(parent, instance, type);
1191
1194
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1192
1195
  invalidateInstance(instance);
@@ -842,11 +842,7 @@ function createRenderer(_roots, _getEventPriority) {
842
842
  ...props
843
843
  }, root) {
844
844
  let name = `${type[0].toUpperCase()}${type.slice(1)}`;
845
- let instance; // Auto-attach geometries and materials
846
-
847
- if (attach === undefined) {
848
- if (name.endsWith('Geometry')) attach = 'geometry';else if (name.endsWith('Material')) attach = 'material';
849
- }
845
+ let instance;
850
846
 
851
847
  if (type === 'primitive') {
852
848
  if (props.object === undefined) throw new Error("R3F: Primitives without 'object' are invalid!");
@@ -877,6 +873,11 @@ function createRenderer(_roots, _getEventPriority) {
877
873
  args
878
874
  }
879
875
  });
876
+ } // Auto-attach geometries and materials
877
+
878
+
879
+ if (instance.__r3f.attach === undefined) {
880
+ if (instance instanceof THREE.BufferGeometry) instance.__r3f.attach = 'geometry';else if (instance instanceof THREE.Material) instance.__r3f.attach = 'material';
880
881
  } // It should NOT call onUpdate on object instanciation, because it hasn't been added to the
881
882
  // view yet. If the callback relies on references for instance, they won't be ready yet, this is
882
883
  // why it passes "true" here
@@ -1016,11 +1017,13 @@ function createRenderer(_roots, _getEventPriority) {
1016
1017
  const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1017
1018
  // When args change the instance has to be re-constructed, which then
1018
1019
  // forces r3f to re-parent the children and non-scene objects
1019
- // This can not include primitives, which should not have declarative children
1020
1020
 
1021
- if (type !== 'primitive' && instance.children) {
1022
- instance.children.forEach(child => appendChild(newInstance, child));
1023
- instance.children = [];
1021
+ if (instance.children) {
1022
+ for (const child of instance.children) {
1023
+ if (child.__r3f) appendChild(newInstance, child);
1024
+ }
1025
+
1026
+ instance.children = instance.children.filter(child => !child.__r3f);
1024
1027
  }
1025
1028
 
1026
1029
  instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
@@ -1142,11 +1145,11 @@ function createRenderer(_roots, _getEventPriority) {
1142
1145
  hideInstance(instance) {
1143
1146
  var _instance$__r3f4;
1144
1147
 
1145
- // Deatch while the instance is hidden
1148
+ // Detach while the instance is hidden
1146
1149
  const {
1147
1150
  attach: type,
1148
1151
  parent
1149
- } = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1152
+ } = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
1150
1153
  if (type && parent) detach(parent, instance, type);
1151
1154
  if (instance.isObject3D) instance.visible = false;
1152
1155
  invalidateInstance(instance);
@@ -1159,7 +1162,7 @@ function createRenderer(_roots, _getEventPriority) {
1159
1162
  const {
1160
1163
  attach: type,
1161
1164
  parent
1162
- } = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1165
+ } = (_instance$__r3f5 = instance.__r3f) != null ? _instance$__r3f5 : {};
1163
1166
  if (type && parent) attach(parent, instance, type);
1164
1167
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1165
1168
  invalidateInstance(instance);
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-bcd3e47c.cjs.dev.js');
5
+ var index = require('./index-08c4a2bb.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-e086bd20.cjs.prod.js');
5
+ var index = require('./index-8826c241.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-212b30d8.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, c as createEvents, 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-212b30d8.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-cf0284c7.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, c as createEvents, 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-cf0284c7.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-bcd3e47c.cjs.dev.js');
5
+ var index = require('../../dist/index-08c4a2bb.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-e086bd20.cjs.prod.js');
5
+ var index = require('../../dist/index-8826c241.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-212b30d8.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-212b30d8.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-cf0284c7.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-cf0284c7.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.4.1",
3
+ "version": "8.6.0",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",