@react-three/fiber 10.0.0-canary.2c50459 → 10.0.0-canary.4a21acb

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/dist/legacy.cjs CHANGED
@@ -62,9 +62,12 @@ const WebGPURenderer = class WebGPURenderer2 {
62
62
  }
63
63
  };
64
64
  const RenderTarget = null;
65
+ const CubeRenderTarget = null;
65
66
 
66
67
  const THREE = /*#__PURE__*/_mergeNamespaces({
67
68
  __proto__: null,
69
+ CubeRenderTarget: CubeRenderTarget,
70
+ CubeRenderTargetCompat: three.WebGLCubeRenderTarget,
68
71
  Inspector: Inspector,
69
72
  R3F_BUILD_LEGACY: R3F_BUILD_LEGACY,
70
73
  R3F_BUILD_WEBGPU: R3F_BUILD_WEBGPU,
@@ -342,15 +345,16 @@ function EnvironmentPortal({
342
345
  preset = void 0,
343
346
  extensions
344
347
  }) {
345
- const gl = fiber.useThree((state) => state.gl);
348
+ const renderer = fiber.useThree((state) => state.renderer);
349
+ const isLegacy = fiber.useThree((state) => state.isLegacy);
346
350
  const defaultScene = fiber.useThree((state) => state.scene);
347
351
  const camera = React__namespace.useRef(null);
348
352
  const [virtualScene] = React__namespace.useState(() => new three.Scene());
349
353
  const fbo = React__namespace.useMemo(() => {
350
- const fbo2 = new three.WebGLCubeRenderTarget(resolution);
354
+ const fbo2 = isLegacy ? new three.WebGLCubeRenderTarget(resolution) : new CubeRenderTarget(resolution);
351
355
  fbo2.texture.type = three.HalfFloatType;
352
356
  return fbo2;
353
- }, [resolution]);
357
+ }, [resolution, isLegacy]);
354
358
  React__namespace.useEffect(() => {
355
359
  return () => {
356
360
  fbo.dispose();
@@ -358,10 +362,10 @@ function EnvironmentPortal({
358
362
  }, [fbo]);
359
363
  React__namespace.useLayoutEffect(() => {
360
364
  if (frames === 1) {
361
- const autoClear = gl.autoClear;
362
- gl.autoClear = true;
363
- camera.current.update(gl, virtualScene);
364
- gl.autoClear = autoClear;
365
+ const autoClear = renderer.autoClear;
366
+ renderer.autoClear = true;
367
+ camera.current.update(renderer, virtualScene);
368
+ renderer.autoClear = autoClear;
365
369
  }
366
370
  return setEnvProps(background, scene, defaultScene, fbo.texture, {
367
371
  backgroundBlurriness: blur ?? backgroundBlurriness,
@@ -378,7 +382,7 @@ function EnvironmentPortal({
378
382
  defaultScene,
379
383
  background,
380
384
  frames,
381
- gl,
385
+ renderer,
382
386
  blur,
383
387
  backgroundBlurriness,
384
388
  backgroundIntensity,
@@ -389,10 +393,10 @@ function EnvironmentPortal({
389
393
  let count = 1;
390
394
  fiber.useFrame(() => {
391
395
  if (frames === Infinity || count < frames) {
392
- const autoClear = gl.autoClear;
393
- gl.autoClear = true;
394
- camera.current.update(gl, virtualScene);
395
- gl.autoClear = autoClear;
396
+ const autoClear = renderer.autoClear;
397
+ renderer.autoClear = true;
398
+ camera.current.update(renderer, virtualScene);
399
+ renderer.autoClear = autoClear;
396
400
  count++;
397
401
  }
398
402
  });
@@ -635,8 +639,7 @@ function prepare(target, root, type, props) {
635
639
  object,
636
640
  eventCount: 0,
637
641
  handlers: {},
638
- isHidden: false,
639
- deferredRefs: []
642
+ isHidden: false
640
643
  };
641
644
  if (object) object.__r3f = instance;
642
645
  }
@@ -793,6 +796,17 @@ function unregisterVisibility(store, object) {
793
796
  internal.visibilityRegistry.delete(object.uuid);
794
797
  internal.occlusionCache.delete(object);
795
798
  }
799
+ function updateVisibilityHandlers(store, object, handlers) {
800
+ const { internal } = store.getState();
801
+ const entry = internal.visibilityRegistry.get(object.uuid);
802
+ if (!entry) return false;
803
+ entry.handlers = handlers;
804
+ if ((handlers.onOccluded || handlers.onVisible) && !internal.occlusionEnabled) {
805
+ object.occlusionTest = true;
806
+ enableOcclusion(store);
807
+ }
808
+ return true;
809
+ }
796
810
  function checkVisibility(state) {
797
811
  const { internal, camera } = state;
798
812
  const registry = internal.visibilityRegistry;
@@ -980,10 +994,7 @@ function applyProps(object, props) {
980
994
  continue;
981
995
  }
982
996
  if (value === void 0) continue;
983
- if (isFromRef(value)) {
984
- instance?.deferredRefs?.push({ prop, ref: value[FROM_REF] });
985
- continue;
986
- }
997
+ if (isFromRef(value)) continue;
987
998
  if (isOnce(value)) {
988
999
  if (instance?.appliedOnce?.has(prop)) continue;
989
1000
  if (instance) {
@@ -1019,6 +1030,19 @@ function applyProps(object, props) {
1019
1030
  } else if (isVectorLike(target) && is.num(value)) {
1020
1031
  if ("setScalar" in target && typeof target.setScalar === "function") target.setScalar(value);
1021
1032
  else target.set(value);
1033
+ } else if (root instanceof three.ShaderMaterial && key === "uniforms" && is.obj(value)) {
1034
+ if (!is.obj(root.uniforms)) root.uniforms = {};
1035
+ const uniforms = root.uniforms;
1036
+ const nextUniforms = value;
1037
+ for (const name in nextUniforms) {
1038
+ const uniform = nextUniforms[name];
1039
+ const targetUniform = uniforms[name];
1040
+ if (targetUniform) Object.assign(targetUniform, uniform);
1041
+ else {
1042
+ const nextUniform = uniform instanceof three.Uniform ? uniform.clone() : new three.Uniform(uniform.value);
1043
+ uniforms[name] = nextUniform;
1044
+ }
1045
+ }
1022
1046
  } else {
1023
1047
  root[key] = value;
1024
1048
  if (key.endsWith("Node") && root.isMaterial) {
@@ -1037,6 +1061,9 @@ function applyProps(object, props) {
1037
1061
  if (instance.eventCount && object2.raycast !== null) {
1038
1062
  rootState.internal.interaction.push(object2);
1039
1063
  }
1064
+ }
1065
+ if (instance?.parent && rootState?.internal && instance.object?.isObject3D) {
1066
+ const object2 = instance.object;
1040
1067
  const root = findInitialRoot(instance);
1041
1068
  const visibilityHandlers = {
1042
1069
  onFramed: instance.handlers.onFramed,
@@ -1044,7 +1071,9 @@ function applyProps(object, props) {
1044
1071
  onVisible: instance.handlers.onVisible
1045
1072
  };
1046
1073
  if (hasVisibilityHandlers(visibilityHandlers)) {
1047
- registerVisibility(root, object2, visibilityHandlers);
1074
+ if (!updateVisibilityHandlers(root, object2, visibilityHandlers)) {
1075
+ registerVisibility(root, object2, visibilityHandlers);
1076
+ }
1048
1077
  } else {
1049
1078
  unregisterVisibility(root, object2);
1050
1079
  }
@@ -1572,6 +1601,7 @@ function createPointerEvents(store) {
1572
1601
  set((state) => ({ events: { ...state.events, connected: void 0 } }));
1573
1602
  }
1574
1603
  },
1604
+ // PREVIEW (A8): the XR pointer registration API may change before stable.
1575
1605
  registerPointer: (config) => {
1576
1606
  const pointerId = nextXRPointerId++;
1577
1607
  xrPointers.set(pointerId, config);
@@ -1658,6 +1688,13 @@ function notifyAlpha({ message, link }) {
1658
1688
  }
1659
1689
  }
1660
1690
 
1691
+ const INTERNAL_LIB_MARKERS = ["zustand", "setState", "Object.assign"];
1692
+ function isInternalRendererAccess(stack, callerDepth = 2) {
1693
+ if (!stack) return false;
1694
+ const caller = stack.split("\n")[callerDepth] ?? "";
1695
+ return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
1696
+ }
1697
+
1661
1698
  const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
1662
1699
  const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React__namespace.createContext(null));
1663
1700
  const createStore = (invalidate, advance) => {
@@ -1790,6 +1827,7 @@ const createStore = (invalidate, advance) => {
1790
1827
  }),
1791
1828
  setFrameloop: (frameloop = "always") => {
1792
1829
  set(() => ({ frameloop }));
1830
+ scheduler.getScheduler().frameloop = frameloop;
1793
1831
  },
1794
1832
  setError: (error) => set(() => ({ error })),
1795
1833
  error: null,
@@ -1857,8 +1895,7 @@ const createStore = (invalidate, advance) => {
1857
1895
  const currentState = rootStore.getState();
1858
1896
  if (!currentState.isLegacy && currentState.internal.actualRenderer) {
1859
1897
  const stack = new Error().stack || "";
1860
- const isInternalAccess = stack.includes("zustand") || stack.includes("setState") || stack.includes("Object.assign") || stack.includes("react-three-fiber/packages/fiber/src/core");
1861
- if (!isInternalAccess) {
1898
+ if (!isInternalRendererAccess(stack)) {
1862
1899
  const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
1863
1900
  notifyDepreciated({
1864
1901
  heading: "Accessing state.gl in WebGPU mode",
@@ -1971,19 +2008,25 @@ function loadingFn(extensions, onProgress) {
1971
2008
  );
1972
2009
  };
1973
2010
  }
1974
- function useLoader(loader, input, extensions, onProgress) {
1975
- const keys = Array.isArray(input) ? input : [input];
2011
+ function useLoader(loader, input, extensions, onProgress, cacheKey) {
2012
+ const inputs = Array.isArray(input) ? input : [input];
2013
+ const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
1976
2014
  const fn = loadingFn(extensions, onProgress);
1977
- const results = keys.map((key) => suspendReact.suspend(fn, [loader, key], { equal: is.equ }));
2015
+ const results = cacheKeys.map(
2016
+ (key, index) => suspendReact.suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
2017
+ );
1978
2018
  return Array.isArray(input) ? results : results[0];
1979
2019
  }
1980
- useLoader.preload = function(loader, input, extensions, onProgress) {
1981
- const keys = Array.isArray(input) ? input : [input];
1982
- keys.forEach((key) => suspendReact.preload(loadingFn(extensions, onProgress), [loader, key]));
2020
+ useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
2021
+ const inputs = Array.isArray(input) ? input : [input];
2022
+ const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
2023
+ cacheKeys.forEach(
2024
+ (key, index) => suspendReact.preload(() => loadingFn(extensions, onProgress)(loader, inputs[index]), [loader, key])
2025
+ );
1983
2026
  };
1984
- useLoader.clear = function(loader, input) {
1985
- const keys = Array.isArray(input) ? input : [input];
1986
- keys.forEach((key) => suspendReact.clear([loader, key]));
2027
+ useLoader.clear = function(loader, input, cacheKey) {
2028
+ const cacheKeys = Array.isArray(cacheKey ?? input) ? cacheKey ?? input : [cacheKey ?? input];
2029
+ cacheKeys.forEach((key) => suspendReact.clear([loader, key]));
1987
2030
  };
1988
2031
  useLoader.loader = getLoader;
1989
2032
 
@@ -2403,7 +2446,7 @@ function advance(timestamp) {
2403
2446
  scheduler.getScheduler().step(timestamp);
2404
2447
  }
2405
2448
 
2406
- const version = "10.0.0-alpha.2";
2449
+ const version = "10.0.0-alpha.3";
2407
2450
  const packageData = {
2408
2451
  version: version};
2409
2452
 
@@ -13842,6 +13885,7 @@ function swapInstances() {
13842
13885
  }
13843
13886
  }
13844
13887
  if (instance.isHidden) unhideInstance(instance);
13888
+ if (isObject3D(instance.object)) removeInteractivity(findInitialRoot(instance), instance.object);
13845
13889
  if (instance.object.__r3f) delete instance.object.__r3f;
13846
13890
  if (instance.type !== "primitive") disposeOnIdle(instance.object);
13847
13891
  }
@@ -13854,6 +13898,8 @@ function swapInstances() {
13854
13898
  instance.object.__r3f = instance;
13855
13899
  setFiberRef(fiber, instance.object);
13856
13900
  delete instance.appliedOnce;
13901
+ instance.eventCount = 0;
13902
+ instance.handlers = {};
13857
13903
  applyProps(instance.object, instance.props);
13858
13904
  if (instance.props.attach) {
13859
13905
  attach(parent, instance);
@@ -14069,11 +14115,15 @@ const reconciler = /* @__PURE__ */ createReconciler({
14069
14115
  cloneMutableTextInstance(textInstance) {
14070
14116
  return textInstance;
14071
14117
  },
14118
+ // React 19.2 added these for root-level view transitions. They only run for hosts that opt into
14119
+ // view transitions by returning a container from cloneRootViewTransitionContainer; R3F renders
14120
+ // into a WebGL/WebGPU canvas, where cloning the root has no meaning, so we never opt in and
14121
+ // React never calls them. They stay as no-ops rather than throws: the host config is shared by
14122
+ // every root, and a throw here would turn a React-internal probe into a hard crash for users.
14123
+ // Guarded by a test asserting a full render + unmount never reaches them.
14072
14124
  cloneRootViewTransitionContainer(_rootContainer) {
14073
- throw new Error("Not implemented.");
14074
14125
  },
14075
14126
  removeRootViewTransitionClone(_rootContainer, _clone) {
14076
- throw new Error("Not implemented.");
14077
14127
  },
14078
14128
  // https://github.com/facebook/react/pull/32465
14079
14129
  createFragmentInstance: (_fiber) => null,
@@ -14158,6 +14208,7 @@ function createRoot(canvas) {
14158
14208
  const lastConfiguredProps = {};
14159
14209
  let configured = false;
14160
14210
  let pending = null;
14211
+ let rendererSetup = null;
14161
14212
  return {
14162
14213
  async configure(props = {}) {
14163
14214
  let resolve;
@@ -14188,7 +14239,7 @@ function createRoot(canvas) {
14188
14239
  forceEven
14189
14240
  } = props;
14190
14241
  const textureColorSpace = is.obj(glConfig) && !is.fun(glConfig) && !isRenderer(glConfig) && glConfig.textureColorSpace || is.obj(rendererConfig) && !is.fun(rendererConfig) && !isRenderer(rendererConfig) && rendererConfig.textureColorSpace || three.SRGBColorSpace;
14191
- const state = store.getState();
14242
+ let state = store.getState();
14192
14243
  const defaultGLProps = {
14193
14244
  canvas,
14194
14245
  powerPreference: "high-performance",
@@ -14216,9 +14267,21 @@ function createRoot(canvas) {
14216
14267
  );
14217
14268
  }
14218
14269
  if (!state.internal.actualRenderer) {
14219
- renderer = await resolveRenderer(glConfig, defaultGLProps, three.WebGLRenderer);
14220
- state.internal.actualRenderer = renderer;
14221
- state.set({ isLegacy: true, gl: renderer, renderer, primaryStore: store });
14270
+ if (!rendererSetup) {
14271
+ rendererSetup = (async () => {
14272
+ {
14273
+ renderer = await resolveRenderer(glConfig, defaultGLProps, three.WebGLRenderer);
14274
+ state.internal.actualRenderer = renderer;
14275
+ state.set({ isLegacy: true, gl: renderer, renderer, primaryStore: store });
14276
+ }
14277
+ })().catch((err) => {
14278
+ rendererSetup = null;
14279
+ throw err;
14280
+ });
14281
+ }
14282
+ await rendererSetup;
14283
+ state = store.getState();
14284
+ renderer = state.internal.actualRenderer;
14222
14285
  }
14223
14286
  let raycaster = state.raycaster;
14224
14287
  if (!raycaster) state.set({ raycaster: raycaster = new three.Raycaster() });
@@ -14568,7 +14631,8 @@ function unmountComponentAtNode(canvas, callback) {
14568
14631
  dispose(state.scene);
14569
14632
  _roots.delete(canvas);
14570
14633
  if (callback) callback(canvas);
14571
- } catch {
14634
+ } catch (error) {
14635
+ console.warn("[R3F] Error while unmounting root; teardown may be incomplete:", error);
14572
14636
  }
14573
14637
  }, 500);
14574
14638
  }
@@ -14631,6 +14695,7 @@ function PortalInner({ state = {}, children, container }) {
14631
14695
  viewport = rootState.viewport.getCurrentViewport(camera, new three.Vector3(), resolvedSize);
14632
14696
  if (camera !== rootState.camera) updateCamera(camera, resolvedSize);
14633
14697
  }
14698
+ const set = injectState.set;
14634
14699
  return {
14635
14700
  // The intersect consists of the previous root state
14636
14701
  ...rootState,
@@ -14649,7 +14714,7 @@ function PortalInner({ state = {}, children, container }) {
14649
14714
  size: resolvedSize,
14650
14715
  viewport: { ...rootState.viewport, ...viewport },
14651
14716
  // Layers are allowed to override events
14652
- setEvents: (events2) => injectState.set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
14717
+ setEvents: (events2) => set((state2) => ({ ...state2, events: { ...state2.events, ...events2 } })),
14653
14718
  // Container for child attachment - the portalScene (injected or container itself)
14654
14719
  internal: { ...rootState.internal, ...injectState.internal, container: portalScene }
14655
14720
  };
@@ -14708,14 +14773,49 @@ function parseBackground(background) {
14708
14773
  return null;
14709
14774
  }
14710
14775
 
14776
+ function parseRendererConfig(rendererProp) {
14777
+ const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
14778
+ if (isRendererConfig) {
14779
+ const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
14780
+ return {
14781
+ primaryCanvas: pc,
14782
+ scheduler: sc,
14783
+ renderer: Object.keys(rest).length > 0 ? rest : rendererProp
14784
+ };
14785
+ }
14786
+ return { primaryCanvas: void 0, scheduler: void 0, renderer: rendererProp };
14787
+ }
14788
+
14789
+ const RESOURCE_KINDS = ["nodes", "uniforms", "buffers", "gpuStorage"];
14790
+ const registries = /* @__PURE__ */ new WeakMap();
14791
+ function getKindRegistry(store, kind) {
14792
+ let registry = registries.get(store);
14793
+ if (!registry) {
14794
+ registry = {
14795
+ nodes: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
14796
+ uniforms: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
14797
+ buffers: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() },
14798
+ gpuStorage: { valid: /* @__PURE__ */ new Set(), staged: /* @__PURE__ */ new Map() }
14799
+ };
14800
+ registries.set(store, registry);
14801
+ }
14802
+ return registry[kind];
14803
+ }
14804
+ function invalidateResource(store, kind, scopeKey) {
14805
+ const registry = getKindRegistry(store, kind);
14806
+ {
14807
+ registry.valid.clear();
14808
+ registry.staged.clear();
14809
+ }
14810
+ }
14811
+ function invalidateAllResources(store) {
14812
+ for (const kind of RESOURCE_KINDS) invalidateResource(store, kind);
14813
+ }
14814
+
14711
14815
  function clearHmrCaches(store) {
14712
- store.setState((state) => ({
14713
- nodes: {},
14714
- uniforms: {},
14715
- buffers: {},
14716
- gpuStorage: {},
14717
- _hmrVersion: state._hmrVersion + 1
14718
- }));
14816
+ const primary = store.getState().primaryStore ?? store;
14817
+ invalidateAllResources(primary);
14818
+ primary.setState((state) => ({ _hmrVersion: state._hmrVersion + 1 }));
14719
14819
  }
14720
14820
 
14721
14821
  function CanvasImpl({
@@ -14751,18 +14851,7 @@ function CanvasImpl({
14751
14851
  forceEven,
14752
14852
  ...props
14753
14853
  }) {
14754
- const isRendererConfig = typeof rendererProp === "object" && rendererProp !== null && !("render" in rendererProp) && ("primaryCanvas" in rendererProp || "scheduler" in rendererProp);
14755
- let primaryCanvas;
14756
- let scheduler;
14757
- let renderer;
14758
- if (isRendererConfig) {
14759
- const { primaryCanvas: pc, scheduler: sc, ...rest } = rendererProp;
14760
- primaryCanvas = pc;
14761
- scheduler = sc;
14762
- renderer = Object.keys(rest).length > 0 ? rest : rendererProp;
14763
- } else {
14764
- renderer = rendererProp;
14765
- }
14854
+ const { primaryCanvas, scheduler, renderer } = parseRendererConfig(rendererProp);
14766
14855
  React__namespace.useMemo(() => extend(THREE), []);
14767
14856
  const Bridge = useBridge();
14768
14857
  const backgroundProps = React__namespace.useMemo(() => parseBackground(background), [background]);
@@ -14807,6 +14896,7 @@ function CanvasImpl({
14807
14896
  const handleDropMissed = useMutableCallback(onDropMissed);
14808
14897
  const [block, setBlock] = React__namespace.useState(false);
14809
14898
  const [error, setError] = React__namespace.useState(false);
14899
+ const [fallbackVisible, setFallbackVisible] = React__namespace.useState(false);
14810
14900
  if (block) throw block;
14811
14901
  if (error) throw error;
14812
14902
  const root = React__namespace.useRef(null);
@@ -14814,6 +14904,7 @@ function CanvasImpl({
14814
14904
  const unsubscribeErrorRef = React__namespace.useRef(null);
14815
14905
  useIsomorphicLayoutEffect(() => {
14816
14906
  effectActiveRef.current = true;
14907
+ if (fallbackVisible) return;
14817
14908
  const canvas = canvasRef.current;
14818
14909
  if (effectiveSize.width > 0 && effectiveSize.height > 0 && canvas) {
14819
14910
  if (!root.current) {
@@ -14834,7 +14925,7 @@ function CanvasImpl({
14834
14925
  }
14835
14926
  async function run() {
14836
14927
  if (!effectActiveRef.current || !root.current) return;
14837
- await root.current.configure({
14928
+ const configured = await root.current.configure({
14838
14929
  id,
14839
14930
  primaryCanvas,
14840
14931
  scheduler,
@@ -14875,8 +14966,20 @@ function CanvasImpl({
14875
14966
  }
14876
14967
  onCreated?.(state);
14877
14968
  }
14878
- });
14879
- if (!effectActiveRef.current || !root.current) return;
14969
+ }).then(
14970
+ () => true,
14971
+ // Renderer setup failed (e.g. no WebGL/WebGPU support). The `fallback` prop lives
14972
+ // inside <canvas>, which browsers don't display, so surface it as visible DOM
14973
+ // instead; with no fallback, rethrow to an external error boundary. (#3757)
14974
+ (setupError) => {
14975
+ if (effectActiveRef.current) {
14976
+ if (fallback != null) setFallbackVisible(true);
14977
+ else setError(setupError);
14978
+ }
14979
+ return false;
14980
+ }
14981
+ );
14982
+ if (!configured || !effectActiveRef.current || !root.current) return;
14880
14983
  root.current.render(
14881
14984
  /* @__PURE__ */ jsxRuntime.jsx(Bridge, { children: /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary, { set: setError, children: /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(Block, { set: setBlock }), children: [
14882
14985
  backgroundProps && /* @__PURE__ */ jsxRuntime.jsx(Environment, { ...backgroundProps }),
@@ -14939,7 +15042,11 @@ function CanvasImpl({
14939
15042
  ...style
14940
15043
  },
14941
15044
  ...props,
14942
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
15045
+ children: fallbackVisible ? (
15046
+ // Renderer setup failed: render the fallback as visible DOM. Inside <canvas> (below)
15047
+ // it exists in the tree but browsers never paint it, which is the whole bug (#3757).
15048
+ fallback
15049
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "r3f-canvas-container", style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
14943
15050
  "canvas",
14944
15051
  {
14945
15052
  ref: canvasRef,
package/dist/legacy.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as THREE$1 from 'three';
2
- import { WebGLRenderTarget, Color as Color$1, ColorRepresentation, Euler as Euler$1, Loader, RenderTargetOptions as RenderTargetOptions$1, Layers as Layers$1, Raycaster, Intersection as Intersection$1, BufferGeometry, Matrix4 as Matrix4$1, Quaternion as Quaternion$1, Node as Node$1, Vector2 as Vector2$1, Vector3 as Vector3$1, Vector4 as Vector4$1, Matrix3 as Matrix3$1, ColorSpace, Texture as Texture$1, CubeTexture, Scene, Object3D, Frustum, OrthographicCamera } from 'three';
2
+ import { WebGLCubeRenderTarget, WebGLRenderTarget, Color as Color$1, ColorRepresentation, Euler as Euler$1, Loader, RenderTargetOptions as RenderTargetOptions$1, Layers as Layers$1, Raycaster, Intersection as Intersection$1, BufferGeometry, Matrix4 as Matrix4$1, Quaternion as Quaternion$1, Node as Node$1, Vector2 as Vector2$1, Vector3 as Vector3$1, Vector4 as Vector4$1, Matrix3 as Matrix3$1, ColorSpace, Texture as Texture$1, CubeTexture, Scene, Object3D, Frustum, OrthographicCamera } from 'three';
3
3
  import * as React$1 from 'react';
4
4
  import { ReactNode, Component, RefObject, JSX } from 'react';
5
5
  import * as three_webgpu from 'three/webgpu';
@@ -48,8 +48,12 @@ declare const WebGPURenderer: {
48
48
 
49
49
  declare const RenderTarget: any;
50
50
 
51
+ declare const CubeRenderTarget: any;
52
+
51
53
  var THREE = /*#__PURE__*/_mergeNamespaces({
52
54
  __proto__: null,
55
+ CubeRenderTarget: CubeRenderTarget,
56
+ CubeRenderTargetCompat: WebGLCubeRenderTarget,
53
57
  Inspector: Inspector,
54
58
  R3F_BUILD_LEGACY: R3F_BUILD_LEGACY,
55
59
  R3F_BUILD_WEBGPU: R3F_BUILD_WEBGPU,
@@ -495,7 +499,7 @@ interface InternalState {
495
499
  canvasTarget?: CanvasTarget
496
500
  /**
497
501
  * Whether multi-canvas rendering is active.
498
- * True when any canvas uses `target` prop to share a renderer.
502
+ * True when any canvas uses `renderer={{ primaryCanvas: 'id' }}` to share a renderer.
499
503
  * When true, setCanvasTarget is called before each render.
500
504
  */
501
505
  isMultiCanvas?: boolean
@@ -593,8 +597,8 @@ interface RootState {
593
597
  setSize: (width?: number, height?: number, top?: number, left?: number) => void
594
598
  /** Shortcut to manual setting the pixel ratio */
595
599
  setDpr: (dpr: Dpr) => void
596
- /** Shortcut to setting frameloop flags */
597
- setFrameloop: (frameloop: Frameloop) => void
600
+ /** Shortcut to setting frameloop flags. No args resets to 'always'. */
601
+ setFrameloop: (frameloop?: Frameloop) => void
598
602
  /** Set error state to propagate to error boundary */
599
603
  setError: (error: Error | null) => void
600
604
  /** Current error state (null when no error) */
@@ -612,7 +616,7 @@ interface RootState {
612
616
  /** Internal: refcount per texture key, driven by mounted useTexture consumers (registry enrollment is on by default) */
613
617
  _textureRefs: Map<string, number>
614
618
  /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
615
- renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
619
+ renderPipeline: ThreeRenderPipeline | null
616
620
  /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
617
621
  passes: Record<string, any>
618
622
  /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
@@ -905,8 +909,6 @@ interface Instance<O = any> {
905
909
  attach?: AttachType<O>
906
910
  previousAttach?: any
907
911
  isHidden: boolean
908
- /** Deferred ref props to apply in commitMount */
909
- deferredRefs?: Array<{ prop: string; ref: React$1.RefObject<any> }>
910
912
  /** Set of props that have been applied via once() */
911
913
  appliedOnce?: Set<string>
912
914
  }
@@ -1143,10 +1145,21 @@ type RenderTargetOptions = RenderTargetOptions$1
1143
1145
  //* Global Types ==============================
1144
1146
 
1145
1147
  declare global {
1146
- /** Uniform node type - a Node with a value property (matches Three.js UniformNode) */
1147
- interface UniformNode<T = unknown> extends Node {
1148
- value: T
1149
- }
1148
+ /**
1149
+ * Uniform node type.
1150
+ *
1151
+ * This is three's own `UniformNode`, not a re-declaration of it. It previously was a
1152
+ * hand-rolled `interface UniformNode<T> extends Node { value: T }`, which shadowed the real
1153
+ * exported type globally — so R3F's ~58 references resolved to an approximation that was
1154
+ * missing members three actually ships (`setName` among them) and had drifted to the wrong
1155
+ * arity when three made `UniformNode` two-parameter.
1156
+ *
1157
+ * three's signature is `UniformNode<TNodeType, TValue>`. R3F only ever varies the value type,
1158
+ * so the node type is fixed to `unknown` and the single parameter is kept for call-site
1159
+ * ergonomics. The result is three's structural type, so members stay in sync with the
1160
+ * installed three instead of needing to be mirrored by hand.
1161
+ */
1162
+ type UniformNode<T = unknown> = three_webgpu.UniformNode<unknown, T>
1150
1163
 
1151
1164
  /**
1152
1165
  * ShaderCallable - the return type of Fn()
@@ -1291,13 +1304,14 @@ declare module 'three/tsl' {
1291
1304
  ): ShaderCallable<R>
1292
1305
  }
1293
1306
 
1294
- /**
1295
- * RenderPipeline Types for useRenderPipeline hook (WebGPU only)
1296
- */
1297
-
1298
-
1299
-
1300
1307
  declare global {
1308
+ /**
1309
+ * three's own render pipeline type. Named here so the rest of R3F refers to three's shape
1310
+ * rather than `any`. three r183 renamed `PostProcessing` to `RenderPipeline`; our peer floor
1311
+ * is r185, so the new name is the only one.
1312
+ */
1313
+ type ThreeRenderPipeline = three_webgpu.RenderPipeline
1314
+
1301
1315
  /** Pass record - stores TSL pass nodes for render pipeline */
1302
1316
  type PassRecord = Record<string, any>
1303
1317
 
@@ -1312,7 +1326,7 @@ declare global {
1312
1326
  /** Current passes from state */
1313
1327
  passes: PassRecord
1314
1328
  /** RenderPipeline instance (null if not initialized) */
1315
- renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
1329
+ renderPipeline: ThreeRenderPipeline | null
1316
1330
  /** Clear all passes from state */
1317
1331
  clearPasses: () => void
1318
1332
  /** Reset RenderPipeline entirely (clears PP + passes) */
@@ -1493,7 +1507,7 @@ declare namespace three_d {
1493
1507
  * a single WebGPURenderer using Three.js CanvasTarget API.
1494
1508
  *
1495
1509
  * Primary canvas: Has `id` prop, creates its own renderer, registers here
1496
- * Secondary canvas: Has `target="id"` prop, shares primary's renderer via CanvasTarget
1510
+ * Secondary canvas: Has `renderer={{ primaryCanvas: 'id' }}`, shares primary's renderer via CanvasTarget
1497
1511
  */
1498
1512
 
1499
1513
  interface PrimaryCanvasEntry {
@@ -1561,12 +1575,23 @@ type EnvironmentLoaderProps = {
1561
1575
  * const texture = useEnvironment({ preset: 'sunset' })
1562
1576
  * ```
1563
1577
  */
1564
- declare function useEnvironment({ files, path, preset, colorSpace, extensions, }?: Partial<EnvironmentLoaderProps>): Texture$1<unknown> | CubeTexture;
1578
+ declare function useEnvironment({ files, path, preset, colorSpace, extensions, }?: Partial<EnvironmentLoaderProps>): Texture$1<unknown, THREE$1.TextureEventMap> | CubeTexture<unknown>;
1565
1579
  declare namespace useEnvironment {
1566
1580
  var preload: (preloadOptions?: EnvironmentLoaderPreloadOptions) => void;
1567
1581
  var clear: (clearOptions?: EnvironmentLoaderClearOptions) => void;
1568
1582
  }
1569
- type EnvironmentLoaderPreloadOptions = Omit<EnvironmentLoaderProps, 'encoding'>;
1583
+ /**
1584
+ * Options accepted by `useEnvironment.preload`.
1585
+ *
1586
+ * `colorSpace` is deliberately omitted: preload only warms the loader cache, and colorSpace is
1587
+ * applied to the texture by `useEnvironment()` at use time, per consumer. Accepting it here would
1588
+ * advertise an option this function silently ignores.
1589
+ *
1590
+ * This previously read `Omit<…, 'encoding'>` — omitting a key that does not exist on
1591
+ * `EnvironmentLoaderProps`, a leftover from three's pre-`colorSpace` `encoding` API. That made the
1592
+ * type equivalent to the full props, so `colorSpace` was accepted and then dropped on the floor.
1593
+ */
1594
+ type EnvironmentLoaderPreloadOptions = Omit<EnvironmentLoaderProps, 'colorSpace'>;
1570
1595
  type EnvironmentLoaderClearOptions = Pick<EnvironmentLoaderProps, 'files' | 'preset'>;
1571
1596
 
1572
1597
  /**
@@ -1816,10 +1841,10 @@ declare function getLoader<L extends LoaderLike | ConstructorRepresentation<Load
1816
1841
  * Note: this hook's caller must be wrapped with `React.Suspense`
1817
1842
  * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1818
1843
  */
1819
- declare function useLoader<I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void): I extends any[] ? LoaderResult<L>[] : LoaderResult<L>;
1844
+ declare function useLoader<I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void, cacheKey?: InputLike): I extends any[] ? LoaderResult<L>[] : LoaderResult<L>;
1820
1845
  declare namespace useLoader {
1821
- var preload: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void) => void;
1822
- var clear: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I) => void;
1846
+ var preload: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void, cacheKey?: InputLike) => void;
1847
+ var clear: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, cacheKey?: InputLike) => void;
1823
1848
  var loader: typeof getLoader;
1824
1849
  }
1825
1850