@react-three/fiber 8.2.0 → 8.2.3

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,23 @@
1
1
  # @react-three/fiber
2
2
 
3
+ ## 8.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - b8d2eab: fix: improve useLoader signature, initial size on createRoot
8
+
9
+ ## 8.2.2
10
+
11
+ ### Patch Changes
12
+
13
+ - acd6f04: fix: warn on stray text
14
+
15
+ ## 8.2.1
16
+
17
+ ### Patch Changes
18
+
19
+ - 25e35a1: fix: prefer useLayoutEffect in react-native
20
+
3
21
  ## 8.2.0
4
22
 
5
23
  ### Minor Changes
@@ -3,6 +3,7 @@ import { StateSelector, EqualityChecker } from 'zustand';
3
3
  import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
4
4
  import { RootState, RenderCallback } from './store';
5
5
  import { ObjectMap } from './utils';
6
+ import { LoadingManager } from 'three';
6
7
  export interface Loader<T> extends THREE.Loader {
7
8
  load(url: string, onLoad?: (result: T) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void): unknown;
8
9
  }
@@ -14,7 +15,7 @@ export declare function useStore(): import("zustand").UseBoundStore<RootState, i
14
15
  export declare function useThree<T = RootState>(selector?: StateSelector<RootState, T>, equalityFn?: EqualityChecker<T>): T;
15
16
  export declare function useFrame(callback: RenderCallback, renderPriority?: number): null;
16
17
  export declare function useGraph(object: THREE.Object3D): ObjectMap;
17
- export declare function useLoader<T, U extends string | string[]>(Proto: new () => LoaderResult<T>, input: U, extensions?: Extensions, onProgress?: (event: ProgressEvent<EventTarget>) => void): U extends any[] ? BranchingReturn<T, GLTF, GLTF & ObjectMap>[] : BranchingReturn<T, GLTF, GLTF & ObjectMap>;
18
+ export declare function useLoader<T, U extends string | string[]>(Proto: new (manager?: LoadingManager) => LoaderResult<T>, input: U, extensions?: Extensions, onProgress?: (event: ProgressEvent<EventTarget>) => void): U extends any[] ? BranchingReturn<T, GLTF, GLTF & ObjectMap>[] : BranchingReturn<T, GLTF, GLTF & ObjectMap>;
18
19
  export declare namespace useLoader {
19
20
  var preload: <T, U extends string | string[]>(Proto: new () => LoaderResult<T>, input: U, extensions?: Extensions | undefined) => undefined;
20
21
  var clear: <T, U extends string | string[]>(Proto: new () => LoaderResult<T>, input: U) => void;
@@ -10,7 +10,7 @@ import { EventManager, ComputeFunction } from './events';
10
10
  import { dispose, getRootState, Camera } from './utils';
11
11
  declare const roots: Map<Element, Root>;
12
12
  declare const invalidate: (state?: RootState | undefined, frames?: number) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined, frame?: THREE.XRFrame | undefined) => void;
13
- declare const reconciler: import("react-reconciler").Reconciler<UseBoundStore<RootState, import("zustand").StoreApi<RootState>>, import("./renderer").Instance, never, import("./renderer").Instance, import("./renderer").Instance>, applyProps: typeof import("./utils").applyProps;
13
+ declare const reconciler: import("react-reconciler").Reconciler<UseBoundStore<RootState, import("zustand").StoreApi<RootState>>, import("./renderer").Instance, void, import("./renderer").Instance, import("./renderer").Instance>, applyProps: typeof import("./utils").applyProps;
14
14
  declare type Properties<T> = Pick<T, {
15
15
  [K in keyof T]: T[K] extends (_: any) => any ? never : K;
16
16
  }[keyof T]>;
@@ -45,7 +45,7 @@ export declare type InstanceProps = {
45
45
  };
46
46
  declare let extend: (objects: object) => void;
47
47
  declare function createRenderer<TCanvas>(_roots: Map<TCanvas, Root>, _getEventPriority?: () => any): {
48
- reconciler: Reconciler.Reconciler<UseBoundStore<RootState, import("zustand").StoreApi<RootState>>, Instance, never, Instance, Instance>;
48
+ reconciler: Reconciler.Reconciler<UseBoundStore<RootState, import("zustand").StoreApi<RootState>>, Instance, void, Instance, Instance>;
49
49
  applyProps: typeof applyProps;
50
50
  };
51
51
  export { prepare, createRenderer, extend };
@@ -4,7 +4,7 @@ import { AttachType, Instance, InstanceProps, LocalState } from './renderer';
4
4
  import { Dpr, RootState, Size } from './store';
5
5
  export declare type Camera = THREE.OrthographicCamera | THREE.PerspectiveCamera;
6
6
  export declare const isOrthographicCamera: (def: Camera) => def is THREE.OrthographicCamera;
7
- export declare const useIsomorphicLayoutEffect: typeof React.useEffect;
7
+ export declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
8
8
  export declare function useMutableCallback<T>(fn: T): React.MutableRefObject<T>;
9
9
  export declare type SetBlock = false | Promise<null> | null;
10
10
  export declare type UnblockProps = {
@@ -37,12 +37,19 @@ var threeTypes = /*#__PURE__*/Object.freeze({
37
37
  __proto__: null
38
38
  });
39
39
 
40
- const isOrthographicCamera = def => def && def.isOrthographicCamera; // React currently throws a warning when using useLayoutEffect on the server.
41
- // To get around it, we can conditionally useEffect on the server (no-op) and
42
- // useLayoutEffect on the client.
40
+ var _window$document, _window$navigator;
41
+ const isOrthographicCamera = def => def && def.isOrthographicCamera;
42
+ /**
43
+ * An SSR-friendly useLayoutEffect.
44
+ *
45
+ * React currently throws a warning when using useLayoutEffect on the server.
46
+ * To get around it, we can conditionally useEffect on the server (no-op) and
47
+ * useLayoutEffect elsewhere.
48
+ *
49
+ * @see https://github.com/facebook/react/issues/14927
50
+ */
43
51
 
44
- const isSSR = typeof window === 'undefined' || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
45
- const useIsomorphicLayoutEffect = isSSR ? React__namespace.useEffect : React__namespace.useLayoutEffect;
52
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' && ((_window$document = window.document) != null && _window$document.createElement || ((_window$navigator = window.navigator) == null ? void 0 : _window$navigator.product) === 'ReactNative') ? React__namespace.useLayoutEffect : React__namespace.useEffect;
46
53
  function useMutableCallback(fn) {
47
54
  const ref = React__namespace.useRef(fn);
48
55
  useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
@@ -1063,7 +1070,10 @@ function createRenderer(_roots, _getEventPriority) {
1063
1070
  }
1064
1071
  }
1065
1072
  });
1066
- }
1073
+ } // Don't handle text instances, warn on undefined behavior
1074
+
1075
+
1076
+ const handleTextInstance = () => console.warn('Text is not allowed in the R3F tree! This could be stray whitespace or characters.');
1067
1077
 
1068
1078
  const reconciler = Reconciler__default["default"]({
1069
1079
  createInstance,
@@ -1077,13 +1087,20 @@ function createRenderer(_roots, _getEventPriority) {
1077
1087
  supportsHydration: false,
1078
1088
  noTimeout: -1,
1079
1089
  appendChildToContainer: (container, child) => {
1090
+ if (!child) return;
1080
1091
  const scene = container.getState().scene; // Link current root to the default scene
1081
1092
 
1082
1093
  scene.__r3f.root = container;
1083
1094
  appendChild(scene, child);
1084
1095
  },
1085
- removeChildFromContainer: (container, child) => removeChild(container.getState().scene, child),
1086
- insertInContainerBefore: (container, child, beforeChild) => insertBefore(container.getState().scene, child, beforeChild),
1096
+ removeChildFromContainer: (container, child) => {
1097
+ if (!child) return;
1098
+ removeChild(container.getState().scene, child);
1099
+ },
1100
+ insertInContainerBefore: (container, child, beforeChild) => {
1101
+ if (!child || !beforeChild) return;
1102
+ insertBefore(container.getState().scene, child, beforeChild);
1103
+ },
1087
1104
  getRootHostContext: () => null,
1088
1105
  getChildHostContext: parentHostContext => parentHostContext,
1089
1106
 
@@ -1175,13 +1192,9 @@ function createRenderer(_roots, _getEventPriority) {
1175
1192
  invalidateInstance(instance);
1176
1193
  },
1177
1194
 
1178
- createTextInstance: () => {
1179
- throw new Error('Text is not allowed in the R3F tree.');
1180
- },
1181
- hideTextInstance: () => {
1182
- throw new Error('Text is not allowed in the R3F tree.');
1183
- },
1184
- unhideTextInstance: () => {},
1195
+ createTextInstance: handleTextInstance,
1196
+ hideTextInstance: handleTextInstance,
1197
+ unhideTextInstance: handleTextInstance,
1185
1198
  // https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874
1186
1199
  // @ts-ignore
1187
1200
  getCurrentEventPriority: () => _getEventPriority ? _getEventPriority() : constants.DefaultEventPriority,
@@ -1687,11 +1700,43 @@ const createRendererInstance = (gl, canvas) => {
1687
1700
  });
1688
1701
  };
1689
1702
 
1703
+ function isCanvas(maybeCanvas) {
1704
+ return maybeCanvas instanceof HTMLCanvasElement;
1705
+ }
1706
+
1707
+ function computeInitialSize(canvas, defaultSize) {
1708
+ if (defaultSize) {
1709
+ return defaultSize;
1710
+ }
1711
+
1712
+ if (isCanvas(canvas) && canvas.parentElement) {
1713
+ const {
1714
+ width,
1715
+ height,
1716
+ top,
1717
+ left
1718
+ } = canvas.parentElement.getBoundingClientRect();
1719
+ return {
1720
+ width,
1721
+ height,
1722
+ top,
1723
+ left
1724
+ };
1725
+ }
1726
+
1727
+ return {
1728
+ width: 0,
1729
+ height: 0,
1730
+ top: 0,
1731
+ left: 0
1732
+ };
1733
+ }
1734
+
1690
1735
  function createRoot(canvas) {
1691
1736
  // Check against mistaken use of createRoot
1692
- let prevRoot = roots.get(canvas);
1693
- let prevFiber = prevRoot == null ? void 0 : prevRoot.fiber;
1694
- let prevStore = prevRoot == null ? void 0 : prevRoot.store;
1737
+ const prevRoot = roots.get(canvas);
1738
+ const prevFiber = prevRoot == null ? void 0 : prevRoot.fiber;
1739
+ const prevStore = prevRoot == null ? void 0 : prevRoot.store;
1695
1740
  if (prevRoot) console.warn('R3F.createRoot should only be called once!'); // Report when an error was detected in a previous render
1696
1741
  // https://github.com/pmndrs/react-three-fiber/pull/2261
1697
1742
 
@@ -1715,7 +1760,7 @@ function createRoot(canvas) {
1715
1760
  configure(props = {}) {
1716
1761
  let {
1717
1762
  gl: glConfig,
1718
- size,
1763
+ size: propsSize,
1719
1764
  events,
1720
1765
  onCreated: onCreatedCallback,
1721
1766
  shadows = false,
@@ -1850,17 +1895,7 @@ function createRoot(canvas) {
1850
1895
 
1851
1896
  if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr); // Check size, allow it to take on container bounds initially
1852
1897
 
1853
- size = size || (canvas.parentElement ? {
1854
- width: canvas.parentElement.clientWidth,
1855
- height: canvas.parentElement.clientHeight,
1856
- top: canvas.parentElement.clientTop,
1857
- left: canvas.parentElement.clientLeft
1858
- } : {
1859
- width: 0,
1860
- height: 0,
1861
- top: 0,
1862
- left: 0
1863
- });
1898
+ const size = computeInitialSize(canvas, propsSize);
1864
1899
 
1865
1900
  if (!is.equ(size, state.size, shallowLoose)) {
1866
1901
  state.setSize(size.width, size.height, size.updateStyle, size.top, size.left);
@@ -10,12 +10,19 @@ var threeTypes = /*#__PURE__*/Object.freeze({
10
10
  __proto__: null
11
11
  });
12
12
 
13
- const isOrthographicCamera = def => def && def.isOrthographicCamera; // React currently throws a warning when using useLayoutEffect on the server.
14
- // To get around it, we can conditionally useEffect on the server (no-op) and
15
- // useLayoutEffect on the client.
13
+ var _window$document, _window$navigator;
14
+ const isOrthographicCamera = def => def && def.isOrthographicCamera;
15
+ /**
16
+ * An SSR-friendly useLayoutEffect.
17
+ *
18
+ * React currently throws a warning when using useLayoutEffect on the server.
19
+ * To get around it, we can conditionally useEffect on the server (no-op) and
20
+ * useLayoutEffect elsewhere.
21
+ *
22
+ * @see https://github.com/facebook/react/issues/14927
23
+ */
16
24
 
17
- const isSSR = typeof window === 'undefined' || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
18
- const useIsomorphicLayoutEffect = isSSR ? React.useEffect : React.useLayoutEffect;
25
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' && ((_window$document = window.document) != null && _window$document.createElement || ((_window$navigator = window.navigator) == null ? void 0 : _window$navigator.product) === 'ReactNative') ? React.useLayoutEffect : React.useEffect;
19
26
  function useMutableCallback(fn) {
20
27
  const ref = React.useRef(fn);
21
28
  useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
@@ -1036,7 +1043,10 @@ function createRenderer(_roots, _getEventPriority) {
1036
1043
  }
1037
1044
  }
1038
1045
  });
1039
- }
1046
+ } // Don't handle text instances, warn on undefined behavior
1047
+
1048
+
1049
+ const handleTextInstance = () => console.warn('Text is not allowed in the R3F tree! This could be stray whitespace or characters.');
1040
1050
 
1041
1051
  const reconciler = Reconciler({
1042
1052
  createInstance,
@@ -1050,13 +1060,20 @@ function createRenderer(_roots, _getEventPriority) {
1050
1060
  supportsHydration: false,
1051
1061
  noTimeout: -1,
1052
1062
  appendChildToContainer: (container, child) => {
1063
+ if (!child) return;
1053
1064
  const scene = container.getState().scene; // Link current root to the default scene
1054
1065
 
1055
1066
  scene.__r3f.root = container;
1056
1067
  appendChild(scene, child);
1057
1068
  },
1058
- removeChildFromContainer: (container, child) => removeChild(container.getState().scene, child),
1059
- insertInContainerBefore: (container, child, beforeChild) => insertBefore(container.getState().scene, child, beforeChild),
1069
+ removeChildFromContainer: (container, child) => {
1070
+ if (!child) return;
1071
+ removeChild(container.getState().scene, child);
1072
+ },
1073
+ insertInContainerBefore: (container, child, beforeChild) => {
1074
+ if (!child || !beforeChild) return;
1075
+ insertBefore(container.getState().scene, child, beforeChild);
1076
+ },
1060
1077
  getRootHostContext: () => null,
1061
1078
  getChildHostContext: parentHostContext => parentHostContext,
1062
1079
 
@@ -1148,13 +1165,9 @@ function createRenderer(_roots, _getEventPriority) {
1148
1165
  invalidateInstance(instance);
1149
1166
  },
1150
1167
 
1151
- createTextInstance: () => {
1152
- throw new Error('Text is not allowed in the R3F tree.');
1153
- },
1154
- hideTextInstance: () => {
1155
- throw new Error('Text is not allowed in the R3F tree.');
1156
- },
1157
- unhideTextInstance: () => {},
1168
+ createTextInstance: handleTextInstance,
1169
+ hideTextInstance: handleTextInstance,
1170
+ unhideTextInstance: handleTextInstance,
1158
1171
  // https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874
1159
1172
  // @ts-ignore
1160
1173
  getCurrentEventPriority: () => _getEventPriority ? _getEventPriority() : DefaultEventPriority,
@@ -1660,11 +1673,43 @@ const createRendererInstance = (gl, canvas) => {
1660
1673
  });
1661
1674
  };
1662
1675
 
1676
+ function isCanvas(maybeCanvas) {
1677
+ return maybeCanvas instanceof HTMLCanvasElement;
1678
+ }
1679
+
1680
+ function computeInitialSize(canvas, defaultSize) {
1681
+ if (defaultSize) {
1682
+ return defaultSize;
1683
+ }
1684
+
1685
+ if (isCanvas(canvas) && canvas.parentElement) {
1686
+ const {
1687
+ width,
1688
+ height,
1689
+ top,
1690
+ left
1691
+ } = canvas.parentElement.getBoundingClientRect();
1692
+ return {
1693
+ width,
1694
+ height,
1695
+ top,
1696
+ left
1697
+ };
1698
+ }
1699
+
1700
+ return {
1701
+ width: 0,
1702
+ height: 0,
1703
+ top: 0,
1704
+ left: 0
1705
+ };
1706
+ }
1707
+
1663
1708
  function createRoot(canvas) {
1664
1709
  // Check against mistaken use of createRoot
1665
- let prevRoot = roots.get(canvas);
1666
- let prevFiber = prevRoot == null ? void 0 : prevRoot.fiber;
1667
- let prevStore = prevRoot == null ? void 0 : prevRoot.store;
1710
+ const prevRoot = roots.get(canvas);
1711
+ const prevFiber = prevRoot == null ? void 0 : prevRoot.fiber;
1712
+ const prevStore = prevRoot == null ? void 0 : prevRoot.store;
1668
1713
  if (prevRoot) console.warn('R3F.createRoot should only be called once!'); // Report when an error was detected in a previous render
1669
1714
  // https://github.com/pmndrs/react-three-fiber/pull/2261
1670
1715
 
@@ -1688,7 +1733,7 @@ function createRoot(canvas) {
1688
1733
  configure(props = {}) {
1689
1734
  let {
1690
1735
  gl: glConfig,
1691
- size,
1736
+ size: propsSize,
1692
1737
  events,
1693
1738
  onCreated: onCreatedCallback,
1694
1739
  shadows = false,
@@ -1823,17 +1868,7 @@ function createRoot(canvas) {
1823
1868
 
1824
1869
  if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr); // Check size, allow it to take on container bounds initially
1825
1870
 
1826
- size = size || (canvas.parentElement ? {
1827
- width: canvas.parentElement.clientWidth,
1828
- height: canvas.parentElement.clientHeight,
1829
- top: canvas.parentElement.clientTop,
1830
- left: canvas.parentElement.clientLeft
1831
- } : {
1832
- width: 0,
1833
- height: 0,
1834
- top: 0,
1835
- left: 0
1836
- });
1871
+ const size = computeInitialSize(canvas, propsSize);
1837
1872
 
1838
1873
  if (!is.equ(size, state.size, shallowLoose)) {
1839
1874
  state.setSize(size.width, size.height, size.updateStyle, size.top, size.left);
@@ -37,12 +37,19 @@ var threeTypes = /*#__PURE__*/Object.freeze({
37
37
  __proto__: null
38
38
  });
39
39
 
40
- const isOrthographicCamera = def => def && def.isOrthographicCamera; // React currently throws a warning when using useLayoutEffect on the server.
41
- // To get around it, we can conditionally useEffect on the server (no-op) and
42
- // useLayoutEffect on the client.
40
+ var _window$document, _window$navigator;
41
+ const isOrthographicCamera = def => def && def.isOrthographicCamera;
42
+ /**
43
+ * An SSR-friendly useLayoutEffect.
44
+ *
45
+ * React currently throws a warning when using useLayoutEffect on the server.
46
+ * To get around it, we can conditionally useEffect on the server (no-op) and
47
+ * useLayoutEffect elsewhere.
48
+ *
49
+ * @see https://github.com/facebook/react/issues/14927
50
+ */
43
51
 
44
- const isSSR = typeof window === 'undefined' || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
45
- const useIsomorphicLayoutEffect = isSSR ? React__namespace.useEffect : React__namespace.useLayoutEffect;
52
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' && ((_window$document = window.document) != null && _window$document.createElement || ((_window$navigator = window.navigator) == null ? void 0 : _window$navigator.product) === 'ReactNative') ? React__namespace.useLayoutEffect : React__namespace.useEffect;
46
53
  function useMutableCallback(fn) {
47
54
  const ref = React__namespace.useRef(fn);
48
55
  useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
@@ -1063,7 +1070,10 @@ function createRenderer(_roots, _getEventPriority) {
1063
1070
  }
1064
1071
  }
1065
1072
  });
1066
- }
1073
+ } // Don't handle text instances, warn on undefined behavior
1074
+
1075
+
1076
+ const handleTextInstance = () => console.warn('Text is not allowed in the R3F tree! This could be stray whitespace or characters.');
1067
1077
 
1068
1078
  const reconciler = Reconciler__default["default"]({
1069
1079
  createInstance,
@@ -1077,13 +1087,20 @@ function createRenderer(_roots, _getEventPriority) {
1077
1087
  supportsHydration: false,
1078
1088
  noTimeout: -1,
1079
1089
  appendChildToContainer: (container, child) => {
1090
+ if (!child) return;
1080
1091
  const scene = container.getState().scene; // Link current root to the default scene
1081
1092
 
1082
1093
  scene.__r3f.root = container;
1083
1094
  appendChild(scene, child);
1084
1095
  },
1085
- removeChildFromContainer: (container, child) => removeChild(container.getState().scene, child),
1086
- insertInContainerBefore: (container, child, beforeChild) => insertBefore(container.getState().scene, child, beforeChild),
1096
+ removeChildFromContainer: (container, child) => {
1097
+ if (!child) return;
1098
+ removeChild(container.getState().scene, child);
1099
+ },
1100
+ insertInContainerBefore: (container, child, beforeChild) => {
1101
+ if (!child || !beforeChild) return;
1102
+ insertBefore(container.getState().scene, child, beforeChild);
1103
+ },
1087
1104
  getRootHostContext: () => null,
1088
1105
  getChildHostContext: parentHostContext => parentHostContext,
1089
1106
 
@@ -1175,13 +1192,9 @@ function createRenderer(_roots, _getEventPriority) {
1175
1192
  invalidateInstance(instance);
1176
1193
  },
1177
1194
 
1178
- createTextInstance: () => {
1179
- throw new Error('Text is not allowed in the R3F tree.');
1180
- },
1181
- hideTextInstance: () => {
1182
- throw new Error('Text is not allowed in the R3F tree.');
1183
- },
1184
- unhideTextInstance: () => {},
1195
+ createTextInstance: handleTextInstance,
1196
+ hideTextInstance: handleTextInstance,
1197
+ unhideTextInstance: handleTextInstance,
1185
1198
  // https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874
1186
1199
  // @ts-ignore
1187
1200
  getCurrentEventPriority: () => _getEventPriority ? _getEventPriority() : constants.DefaultEventPriority,
@@ -1687,11 +1700,43 @@ const createRendererInstance = (gl, canvas) => {
1687
1700
  });
1688
1701
  };
1689
1702
 
1703
+ function isCanvas(maybeCanvas) {
1704
+ return maybeCanvas instanceof HTMLCanvasElement;
1705
+ }
1706
+
1707
+ function computeInitialSize(canvas, defaultSize) {
1708
+ if (defaultSize) {
1709
+ return defaultSize;
1710
+ }
1711
+
1712
+ if (isCanvas(canvas) && canvas.parentElement) {
1713
+ const {
1714
+ width,
1715
+ height,
1716
+ top,
1717
+ left
1718
+ } = canvas.parentElement.getBoundingClientRect();
1719
+ return {
1720
+ width,
1721
+ height,
1722
+ top,
1723
+ left
1724
+ };
1725
+ }
1726
+
1727
+ return {
1728
+ width: 0,
1729
+ height: 0,
1730
+ top: 0,
1731
+ left: 0
1732
+ };
1733
+ }
1734
+
1690
1735
  function createRoot(canvas) {
1691
1736
  // Check against mistaken use of createRoot
1692
- let prevRoot = roots.get(canvas);
1693
- let prevFiber = prevRoot == null ? void 0 : prevRoot.fiber;
1694
- let prevStore = prevRoot == null ? void 0 : prevRoot.store;
1737
+ const prevRoot = roots.get(canvas);
1738
+ const prevFiber = prevRoot == null ? void 0 : prevRoot.fiber;
1739
+ const prevStore = prevRoot == null ? void 0 : prevRoot.store;
1695
1740
  if (prevRoot) console.warn('R3F.createRoot should only be called once!'); // Report when an error was detected in a previous render
1696
1741
  // https://github.com/pmndrs/react-three-fiber/pull/2261
1697
1742
 
@@ -1715,7 +1760,7 @@ function createRoot(canvas) {
1715
1760
  configure(props = {}) {
1716
1761
  let {
1717
1762
  gl: glConfig,
1718
- size,
1763
+ size: propsSize,
1719
1764
  events,
1720
1765
  onCreated: onCreatedCallback,
1721
1766
  shadows = false,
@@ -1850,17 +1895,7 @@ function createRoot(canvas) {
1850
1895
 
1851
1896
  if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr); // Check size, allow it to take on container bounds initially
1852
1897
 
1853
- size = size || (canvas.parentElement ? {
1854
- width: canvas.parentElement.clientWidth,
1855
- height: canvas.parentElement.clientHeight,
1856
- top: canvas.parentElement.clientTop,
1857
- left: canvas.parentElement.clientLeft
1858
- } : {
1859
- width: 0,
1860
- height: 0,
1861
- top: 0,
1862
- left: 0
1863
- });
1898
+ const size = computeInitialSize(canvas, propsSize);
1864
1899
 
1865
1900
  if (!is.equ(size, state.size, shallowLoose)) {
1866
1901
  state.setSize(size.width, size.height, size.updateStyle, size.top, size.left);
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-0499a96a.cjs.dev.js');
5
+ var index = require('./index-942a305b.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-ca47b633.cjs.prod.js');
5
+ var index = require('./index-1be7d4d7.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-6279214a.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-6279214a.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-201bf0bf.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-201bf0bf.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-0499a96a.cjs.dev.js');
5
+ var index = require('../../dist/index-942a305b.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -39,6 +39,8 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
39
39
  var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
40
40
  var Pressability__default = /*#__PURE__*/_interopDefault(Pressability);
41
41
 
42
+ /* eslint-enable import/default, import/no-named-as-default, import/no-named-as-default-member */
43
+
42
44
  const EVENTS = {
43
45
  PRESS: 'onPress',
44
46
  PRESSIN: 'onPressIn',
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-ca47b633.cjs.prod.js');
5
+ var index = require('../../dist/index-1be7d4d7.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -39,6 +39,8 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
39
39
  var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
40
40
  var Pressability__default = /*#__PURE__*/_interopDefault(Pressability);
41
41
 
42
+ /* eslint-enable import/default, import/no-named-as-default, import/no-named-as-default-member */
43
+
42
44
  const EVENTS = {
43
45
  PRESS: 'onPress',
44
46
  PRESSIN: 'onPressIn',
@@ -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-6279214a.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-6279214a.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-201bf0bf.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-201bf0bf.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';
@@ -12,6 +12,8 @@ import 'react-reconciler';
12
12
  import 'scheduler';
13
13
  import 'suspend-react';
14
14
 
15
+ /* eslint-enable import/default, import/no-named-as-default, import/no-named-as-default-member */
16
+
15
17
  const EVENTS = {
16
18
  PRESS: 'onPress',
17
19
  PRESSIN: 'onPressIn',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.2.0",
3
+ "version": "8.2.3",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",