@react-three/fiber 8.13.2 → 8.13.4

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.
@@ -278,8 +278,11 @@ function createRenderer(_roots, _getEventPriority) {
278
278
  return Boolean(localState.handlers);
279
279
  },
280
280
  prepareUpdate(instance, _type, oldProps, newProps) {
281
+ var _instance$__r3f3;
282
+ const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {};
283
+
281
284
  // Create diff-sets
282
- if (instance.__r3f.primitive && newProps.object && newProps.object !== instance) {
285
+ if (localState.primitive && newProps.object && newProps.object !== instance) {
283
286
  return [true];
284
287
  } else {
285
288
  // This is a data object, let's extract critical information about it
@@ -314,10 +317,10 @@ function createRenderer(_roots, _getEventPriority) {
314
317
  else applyProps$1(instance, diff);
315
318
  },
316
319
  commitMount(instance, _type, _props, _int) {
317
- var _instance$__r3f3;
320
+ var _instance$__r3f4;
318
321
  // https://github.com/facebook/react/issues/20271
319
322
  // This will make sure events are only added once to the central container
320
- const localState = (_instance$__r3f3 = instance.__r3f) != null ? _instance$__r3f3 : {};
323
+ const localState = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
321
324
  if (instance.raycast && localState.handlers && localState.eventCount) {
322
325
  instance.__r3f.root.getState().internal.interaction.push(instance);
323
326
  }
@@ -329,23 +332,23 @@ function createRenderer(_roots, _getEventPriority) {
329
332
  shouldSetTextContent: () => false,
330
333
  clearContainer: () => false,
331
334
  hideInstance(instance) {
332
- var _instance$__r3f4;
335
+ var _instance$__r3f5;
333
336
  // Detach while the instance is hidden
334
337
  const {
335
338
  attach: type,
336
339
  parent
337
- } = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
340
+ } = (_instance$__r3f5 = instance.__r3f) != null ? _instance$__r3f5 : {};
338
341
  if (type && parent) detach(parent, instance, type);
339
342
  if (instance.isObject3D) instance.visible = false;
340
343
  invalidateInstance(instance);
341
344
  },
342
345
  unhideInstance(instance, props) {
343
- var _instance$__r3f5;
346
+ var _instance$__r3f6;
344
347
  // Re-attach when the instance is unhidden
345
348
  const {
346
349
  attach: type,
347
350
  parent
348
- } = (_instance$__r3f5 = instance.__r3f) != null ? _instance$__r3f5 : {};
351
+ } = (_instance$__r3f6 = instance.__r3f) != null ? _instance$__r3f6 : {};
349
352
  if (type && parent) attach(parent, instance, type);
350
353
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
351
354
  invalidateInstance(instance);
@@ -521,19 +524,17 @@ function dispose(obj) {
521
524
  // Each object in the scene carries a small LocalState descriptor
522
525
  function prepare(object, state) {
523
526
  const instance = object;
524
- if (state != null && state.primitive || !instance.__r3f) {
525
- instance.__r3f = {
526
- type: '',
527
- root: null,
528
- previousAttach: null,
529
- memoizedProps: {},
530
- eventCount: 0,
531
- handlers: {},
532
- objects: [],
533
- parent: null,
534
- ...state
535
- };
536
- }
527
+ instance.__r3f = {
528
+ type: '',
529
+ root: null,
530
+ previousAttach: null,
531
+ memoizedProps: {},
532
+ eventCount: 0,
533
+ handlers: {},
534
+ objects: [],
535
+ parent: null,
536
+ ...state
537
+ };
537
538
  return object;
538
539
  }
539
540
  function resolve(instance, key) {
@@ -1227,6 +1228,8 @@ function createEvents(store) {
1227
1228
  };
1228
1229
  }
1229
1230
 
1231
+ // Keys that shouldn't be copied between R3F stores
1232
+ const privateKeys = ['set', 'get', 'setSize', 'setFrameloop', 'setDpr', 'events', 'invalidate', 'advance', 'size', 'viewport'];
1230
1233
  const isRenderer = def => !!(def != null && def.render);
1231
1234
  const context = /*#__PURE__*/React__namespace.createContext(null);
1232
1235
  const createStore = (invalidate, advance) => {
@@ -2056,6 +2059,7 @@ function unmountComponentAtNode(canvas, callback) {
2056
2059
  }
2057
2060
  function createPortal(children, container, state) {
2058
2061
  return /*#__PURE__*/React__namespace.createElement(Portal, {
2062
+ key: container.uuid,
2059
2063
  children: children,
2060
2064
  container: container,
2061
2065
  state: state
@@ -2079,9 +2083,26 @@ function Portal({
2079
2083
  const previousRoot = useStore();
2080
2084
  const [raycaster] = React__namespace.useState(() => new THREE__namespace.Raycaster());
2081
2085
  const [pointer] = React__namespace.useState(() => new THREE__namespace.Vector2());
2082
- const inject = useMutableCallback((rootState, injectState) => {
2083
- let viewport;
2084
- if (injectState.camera && size) {
2086
+ const inject = React__namespace.useCallback((rootState, injectState) => {
2087
+ const intersect = {
2088
+ ...rootState
2089
+ }; // all prev state props
2090
+
2091
+ // Only the fields of "rootState" that do not differ from injectState
2092
+ // Some props should be off-limits
2093
+ // Otherwise filter out the props that are different and let the inject layer take precedence
2094
+ Object.keys(rootState).forEach(key => {
2095
+ if (
2096
+ // Some props should be off-limits
2097
+ privateKeys.includes(key) ||
2098
+ // Otherwise filter out the props that are different and let the inject layer take precedence
2099
+ // Unless the inject layer props is undefined, then we keep the root layer
2100
+ rootState[key] !== injectState[key] && injectState[key]) {
2101
+ delete intersect[key];
2102
+ }
2103
+ });
2104
+ let viewport = undefined;
2105
+ if (injectState && size) {
2085
2106
  const camera = injectState.camera;
2086
2107
  // Calculate the override viewport, if present
2087
2108
  viewport = rootState.viewport.getCurrentViewport(camera, new THREE__namespace.Vector3(), size);
@@ -2090,9 +2111,7 @@ function Portal({
2090
2111
  }
2091
2112
  return {
2092
2113
  // The intersect consists of the previous root state
2093
- ...rootState,
2094
- get: injectState.get,
2095
- set: injectState.set,
2114
+ ...intersect,
2096
2115
  // Portals have their own scene, which forms the root, a raycaster and a pointer
2097
2116
  scene: container,
2098
2117
  raycaster,
@@ -2103,7 +2122,7 @@ function Portal({
2103
2122
  // Events, size and viewport can be overridden by the inject layer
2104
2123
  events: {
2105
2124
  ...rootState.events,
2106
- ...injectState.events,
2125
+ ...(injectState == null ? void 0 : injectState.events),
2107
2126
  ...events
2108
2127
  },
2109
2128
  size: {
@@ -2114,33 +2133,53 @@ function Portal({
2114
2133
  ...rootState.viewport,
2115
2134
  ...viewport
2116
2135
  },
2136
+ ...rest
2137
+ };
2138
+ }, [state]);
2139
+ const [usePortalStore] = React__namespace.useState(() => {
2140
+ // Create a mirrored store, based on the previous root with a few overrides ...
2141
+ const previousState = previousRoot.getState();
2142
+ const store = create__default["default"]((set, get) => ({
2143
+ ...previousState,
2144
+ scene: container,
2145
+ raycaster,
2146
+ pointer,
2147
+ mouse: pointer,
2148
+ previousRoot,
2149
+ events: {
2150
+ ...previousState.events,
2151
+ ...events
2152
+ },
2153
+ size: {
2154
+ ...previousState.size,
2155
+ ...size
2156
+ },
2157
+ ...rest,
2158
+ // Set and get refer to this root-state
2159
+ set,
2160
+ get,
2117
2161
  // Layers are allowed to override events
2118
- setEvents: events => injectState.set(state => ({
2162
+ setEvents: events => set(state => ({
2119
2163
  ...state,
2120
2164
  events: {
2121
2165
  ...state.events,
2122
2166
  ...events
2123
2167
  }
2124
2168
  }))
2125
- };
2126
- });
2127
- const usePortalStore = React__namespace.useMemo(() => {
2128
- const store = create__default["default"]((set, get) => ({
2129
- ...rest,
2130
- set,
2131
- get
2132
2169
  }));
2133
-
2134
- // Subscribe to previous root-state and copy changes over to the mirrored portal-state
2135
- const onMutate = prev => store.setState(state => inject.current(prev, state));
2136
- onMutate(previousRoot.getState());
2137
- previousRoot.subscribe(onMutate);
2138
2170
  return store;
2139
- // eslint-disable-next-line react-hooks/exhaustive-deps
2140
- }, [previousRoot, container]);
2171
+ });
2172
+ React__namespace.useEffect(() => {
2173
+ // Subscribe to previous root-state and copy changes over to the mirrored portal-state
2174
+ const unsub = previousRoot.subscribe(prev => usePortalStore.setState(state => inject(prev, state)));
2175
+ return () => {
2176
+ unsub();
2177
+ usePortalStore.destroy();
2178
+ };
2179
+ }, []);
2141
2180
  React__namespace.useEffect(() => {
2142
- return () => usePortalStore.destroy();
2143
- }, [usePortalStore]);
2181
+ usePortalStore.setState(injectState => inject(previousRoot.getState(), injectState));
2182
+ }, [inject]);
2144
2183
  return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, reconciler.createPortal( /*#__PURE__*/React__namespace.createElement(context.Provider, {
2145
2184
  value: usePortalStore
2146
2185
  }, children), usePortalStore, null));
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-a0deb08b.cjs.dev.js');
5
+ var index = require('./index-c4a77a3a.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-948f4806.cjs.prod.js');
5
+ var index = require('./index-eae395d9.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 useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-13b06ff5.esm.js';
2
- export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-13b06ff5.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-27578f8f.esm.js';
2
+ export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-27578f8f.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-a0deb08b.cjs.dev.js');
5
+ var index = require('../../dist/index-c4a77a3a.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-948f4806.cjs.prod.js');
5
+ var index = require('../../dist/index-eae395d9.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, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-13b06ff5.esm.js';
2
- export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-13b06ff5.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-27578f8f.esm.js';
2
+ export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-27578f8f.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.13.2",
3
+ "version": "8.13.4",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",
@@ -48,7 +48,7 @@
48
48
  "react-reconciler": "^0.27.0",
49
49
  "react-use-measure": "^2.1.1",
50
50
  "scheduler": "^0.21.0",
51
- "suspend-react": "^0.1.0",
51
+ "suspend-react": "^0.1.3",
52
52
  "zustand": "^3.7.1"
53
53
  },
54
54
  "peerDependencies": {