@react-three/fiber 10.0.0-canary.aecbafb → 10.0.0-canary.af75fd4

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.
@@ -1,5 +1,6 @@
1
+ import * as three_examples_jsm_inspector_Inspector_js from 'three/examples/jsm/inspector/Inspector.js';
1
2
  import * as three_webgpu from 'three/webgpu';
2
- import { RenderTarget, WebGPURenderer, Node, StorageTexture, Data3DTexture, CanvasTarget, ShaderNodeObject, Euler as Euler$2, Color as Color$2, ColorRepresentation as ColorRepresentation$1, Layers as Layers$1, Raycaster, Intersection as Intersection$1, BufferGeometry, Matrix4 as Matrix4$1, Quaternion as Quaternion$1, Vector2 as Vector2$1, Vector3 as Vector3$1, Vector4 as Vector4$1, Matrix3 as Matrix3$1, Loader as Loader$1, ColorSpace, Texture as Texture$1, CubeTexture, Scene, Object3D, Frustum, OrthographicCamera, WebGPURendererParameters } from 'three/webgpu';
3
+ import { CubeRenderTarget, RenderTarget, WebGPURenderer, Node, StorageTexture, Data3DTexture, CanvasTarget, ShaderNodeObject, Euler as Euler$2, Color as Color$2, ColorRepresentation as ColorRepresentation$1, Layers as Layers$1, Raycaster, Intersection as Intersection$1, BufferGeometry, Matrix4 as Matrix4$1, Quaternion as Quaternion$1, Vector2 as Vector2$1, Vector3 as Vector3$1, Vector4 as Vector4$1, Matrix3 as Matrix3$1, Loader as Loader$1, ColorSpace, Texture as Texture$1, CubeTexture, Scene, Object3D, Frustum, OrthographicCamera, WebGPURendererParameters } from 'three/webgpu';
3
4
  import { Inspector } from 'three/addons/inspector/Inspector.js';
4
5
  import * as THREE$1 from 'three';
5
6
  import { Color as Color$1, ColorRepresentation, Euler as Euler$1, Loader, RenderTargetOptions as RenderTargetOptions$1 } from 'three';
@@ -7,9 +8,10 @@ import * as React$1 from 'react';
7
8
  import { ReactNode, Component, RefObject, JSX } from 'react';
8
9
  import { StoreApi } from 'zustand';
9
10
  import { UseBoundStoreWithEqualityFn } from 'zustand/traditional';
11
+ import { FrameTimingState, FrameCallback as FrameCallback$1, SchedulerApi, UseFrameNextOptions, FrameNextControls } from '@pmndrs/scheduler';
12
+ export { AddPhaseOptions, FrameControls, FrameNextControls, FrameTimingState, RootOptions, Scheduler, SchedulerApi, UseFrameNextOptions, UseFrameOptions, getScheduler } from '@pmndrs/scheduler';
10
13
  import { Options } from 'react-use-measure';
11
14
  import * as react_jsx_runtime from 'react/jsx-runtime';
12
- import { ThreeElement as ThreeElement$1, Euler as Euler$3 } from '@react-three/fiber';
13
15
  import { GroundedSkybox } from 'three/examples/jsm/objects/GroundedSkybox.js';
14
16
 
15
17
  function _mergeNamespaces(n, m) {
@@ -39,6 +41,8 @@ function _mergeNamespaces(n, m) {
39
41
  declare const R3F_BUILD_LEGACY = false;
40
42
  declare const R3F_BUILD_WEBGPU = true;
41
43
 
44
+ /** Lazily load the three Inspector. Keeps it out of the eager module graph — see note above. */
45
+ declare function loadInspector(): Promise<typeof three_examples_jsm_inspector_Inspector_js.Inspector>;
42
46
  declare const WebGLRenderer: {
43
47
  new (): {};
44
48
  };
@@ -47,16 +51,21 @@ type WebGLShadowMap = never;
47
51
 
48
52
  declare const WebGLRenderTarget: any;
49
53
 
54
+ declare const WebGLCubeRenderTarget: any;
55
+
50
56
  var THREE = /*#__PURE__*/_mergeNamespaces({
51
57
  __proto__: null,
58
+ CubeRenderTargetCompat: CubeRenderTarget,
52
59
  Inspector: Inspector,
53
60
  R3F_BUILD_LEGACY: R3F_BUILD_LEGACY,
54
61
  R3F_BUILD_WEBGPU: R3F_BUILD_WEBGPU,
55
62
  RenderTargetCompat: RenderTarget,
63
+ WebGLCubeRenderTarget: WebGLCubeRenderTarget,
56
64
  WebGLRenderTarget: WebGLRenderTarget,
57
65
  WebGLRenderer: WebGLRenderer,
58
66
  WebGLRendererParameters: WebGLRendererParameters,
59
- WebGLShadowMap: WebGLShadowMap
67
+ WebGLShadowMap: WebGLShadowMap,
68
+ loadInspector: loadInspector
60
69
  }, [three_webgpu]);
61
70
 
62
71
  //* Utility Types ==============================
@@ -294,228 +303,33 @@ interface VisibilityEntry {
294
303
  }
295
304
 
296
305
  //* Scheduler Types (useFrame) ==============================
306
+ //
307
+ // The generic, framework-agnostic scheduler types now live in @pmndrs/scheduler.
308
+ // This file re-exports them and layers r3f's RootState-aware frame state on top,
309
+ // so existing `#types` imports across the codebase keep resolving unchanged.
297
310
 
298
311
 
299
312
 
300
- // Public Options --------------------------------
301
-
302
- /**
303
- * Options for useFrame hook
304
- */
305
- interface UseFrameNextOptions {
306
- /** Optional stable id for the job. Auto-generated if not provided */
307
- id?: string
308
- /** Named phase to run in. Default: 'update' */
309
- phase?: string
310
- /** Run before this phase or job id */
311
- before?: string | string[]
312
- /** Run after this phase or job id */
313
- after?: string | string[]
314
- /** Priority within phase. Higher runs first. Default: 0 */
315
- priority?: number
316
- /** Max frames per second for this job */
317
- fps?: number
318
- /** If true, skip frames when behind. If false, try to catch up. Default: true */
319
- drop?: boolean
320
- /** Enable/disable without unregistering. Default: true */
321
- enabled?: boolean
322
- }
323
-
324
- /** Alias for UseFrameNextOptions */
325
- type UseFrameOptions = UseFrameNextOptions
326
-
327
- /**
328
- * Options for addPhase
329
- */
330
- interface AddPhaseOptions {
331
- /** Insert this phase before the specified phase */
332
- before?: string
333
- /** Insert this phase after the specified phase */
334
- after?: string
335
- }
336
-
337
- // Frame State --------------------------------
338
-
339
- /**
340
- * Timing-only state for independent/outside mode (no RootState)
341
- */
342
- interface FrameTimingState {
343
- /** High-resolution timestamp from RAF (ms) */
344
- time: number
345
- /** Time since last frame in seconds (for legacy compatibility with THREE.Clock) */
346
- delta: number
347
- /** Elapsed time since first frame in seconds (for legacy compatibility with THREE.Clock) */
348
- elapsed: number
349
- /** Incrementing frame counter */
350
- frame: number
351
- }
313
+ // Frame State (r3f-specific) --------------------------------
352
314
 
353
315
  /**
354
- * State passed to useFrame callbacks (extends RootState with timing)
316
+ * State passed to useFrame callbacks (extends RootState with timing).
355
317
  */
356
318
  interface FrameNextState extends RootState, FrameTimingState {}
357
319
 
358
320
  /** Alias for FrameNextState */
359
321
  type FrameState = FrameNextState
360
322
 
361
- // Root Options --------------------------------
362
-
363
- /**
364
- * Options for registerRoot
365
- */
366
- interface RootOptions {
367
- /** State provider for callbacks. Optional in independent mode. */
368
- getState?: () => any
369
- /** Error handler for job errors. Falls back to console.error if not provided. */
370
- onError?: (error: Error) => void
371
- }
372
-
373
- // Callback Types --------------------------------
323
+ // Callback Types (r3f-specific) --------------------------------
374
324
 
375
325
  /**
376
- * Callback function for useFrame
326
+ * Callback function for useFrame. Receives the full r3f RootState plus timing.
377
327
  */
378
- type FrameNextCallback = (state: FrameNextState, delta: number) => void
328
+ type FrameNextCallback = FrameCallback$1<RootState>
379
329
 
380
330
  /** Alias for FrameNextCallback */
381
331
  type FrameCallback = FrameNextCallback
382
332
 
383
- // Controls returned from useFrame --------------------------------
384
-
385
- /**
386
- * Controls object returned from useFrame hook
387
- */
388
- interface FrameNextControls {
389
- /** The job's unique ID */
390
- id: string
391
- /** Access to the global scheduler for frame loop control */
392
- scheduler: SchedulerApi
393
- /** Manually step this job only (bypasses FPS limiting) */
394
- step(timestamp?: number): void
395
- /** Manually step ALL jobs in the scheduler */
396
- stepAll(timestamp?: number): void
397
- /** Pause this job (set enabled=false) */
398
- pause(): void
399
- /** Resume this job (set enabled=true) */
400
- resume(): void
401
- /** Reactive paused state - automatically triggers re-render when changed */
402
- isPaused: boolean
403
- }
404
-
405
- /** Alias for FrameNextControls */
406
- type FrameControls = FrameNextControls
407
-
408
- // Scheduler Interface --------------------------------
409
-
410
- /**
411
- * Public interface for the global Scheduler
412
- */
413
- interface SchedulerApi {
414
- //* Phase Management --------------------------------
415
-
416
- /** Add a named phase to the scheduler */
417
- addPhase(name: string, options?: AddPhaseOptions): void
418
- /** Get the ordered list of phase names */
419
- readonly phases: string[]
420
- /** Check if a phase exists */
421
- hasPhase(name: string): boolean
422
-
423
- //* Root Management --------------------------------
424
-
425
- /** Register a root (Canvas) with the scheduler. Returns unsubscribe function. */
426
- registerRoot(id: string, options?: RootOptions): () => void
427
- /** Unregister a root */
428
- unregisterRoot(id: string): void
429
- /** Generate a unique root ID */
430
- generateRootId(): string
431
- /** Get the number of registered roots */
432
- getRootCount(): number
433
- /** Check if any root is registered and ready */
434
- readonly isReady: boolean
435
- /** Subscribe to root-ready event. Fires immediately if already ready. Returns unsubscribe. */
436
- onRootReady(callback: () => void): () => void
437
-
438
- //* Job Registration --------------------------------
439
-
440
- /** Register a job with the scheduler (returns unsubscribe function) */
441
- register(
442
- callback: FrameNextCallback,
443
- options?: {
444
- id?: string
445
- rootId?: string
446
- phase?: string
447
- before?: string | string[]
448
- after?: string | string[]
449
- priority?: number
450
- fps?: number
451
- drop?: boolean
452
- enabled?: boolean
453
- },
454
- ): () => void
455
- /** Update a job's options */
456
- updateJob(
457
- id: string,
458
- options: {
459
- priority?: number
460
- fps?: number
461
- drop?: boolean
462
- enabled?: boolean
463
- phase?: string
464
- before?: string | string[]
465
- after?: string | string[]
466
- },
467
- ): void
468
- /** Unregister a job by ID */
469
- unregister(id: string, rootId?: string): void
470
- /** Get the number of registered jobs */
471
- getJobCount(): number
472
- /** Get all job IDs */
473
- getJobIds(): string[]
474
-
475
- //* Global Jobs (for legacy addEffect/addAfterEffect) --------------------------------
476
-
477
- /** Register a global job (runs once per frame, not per-root). Returns unsubscribe function. */
478
- registerGlobal(phase: 'before' | 'after', id: string, callback: (timestamp: number) => void): () => void
479
-
480
- //* Idle Callbacks (for legacy addTail) --------------------------------
481
-
482
- /** Register an idle callback (fires when loop stops). Returns unsubscribe function. */
483
- onIdle(callback: (timestamp: number) => void): () => void
484
-
485
- //* Frame Loop Control --------------------------------
486
-
487
- /** Start the scheduler loop */
488
- start(): void
489
- /** Stop the scheduler loop */
490
- stop(): void
491
- /** Check if the scheduler is running */
492
- readonly isRunning: boolean
493
- /** Get/set the frameloop mode ('always', 'demand', 'never') */
494
- frameloop: Frameloop
495
- /** Independent mode - runs without Canvas, callbacks receive timing-only state */
496
- independent: boolean
497
-
498
- //* Manual Stepping --------------------------------
499
-
500
- /** Manually step all jobs once (for frameloop='never' or testing) */
501
- step(timestamp?: number): void
502
- /** Manually step a single job by ID */
503
- stepJob(id: string, timestamp?: number): void
504
- /** Request frame(s) to be rendered (for frameloop='demand') */
505
- invalidate(frames?: number): void
506
-
507
- //* Per-Job Control --------------------------------
508
-
509
- /** Check if a job is paused */
510
- isJobPaused(id: string): boolean
511
- /** Pause a job */
512
- pauseJob(id: string): void
513
- /** Resume a job */
514
- resumeJob(id: string): void
515
- /** Subscribe to job state changes (for reactive isPaused). Returns unsubscribe function. */
516
- subscribeJobState(id: string, listener: () => void): () => void
517
- }
518
-
519
333
  //* Buffer Types (useBuffers) ========================================
520
334
 
521
335
  /**
@@ -551,6 +365,33 @@ type BufferRecord = Record<string, BufferLike>
551
365
  */
552
366
  type BufferStore = Record<string, BufferLike | BufferRecord>
553
367
 
368
+ //* Node Types (useNodes) ========================================
369
+
370
+ /**
371
+ * Structural shape of a TSL node as stored on `state.nodes`.
372
+ *
373
+ * Deliberately minimal rather than three's nominal `Node`: in @types/three several node classes
374
+ * TSL hands back (OperatorNode, ConstNode, ...) do not extend `Node` cleanly, so a `Node` bound
375
+ * would reject values `useNodes` creators legitimately return. This is the same shape
376
+ * `useNodes` already constrains creators to (`TSLNodeLike`).
377
+ */
378
+ interface NodeLike {
379
+ uuid?: string
380
+ nodeType?: string | null
381
+ /** label method for chaining - sets the node's label and returns self */
382
+ label?: ((label: string) => NodeLike) | string
383
+ setName?: (name: string) => this
384
+ }
385
+
386
+ /** Flat record of TSL nodes (no nested scopes) */
387
+ type NodeRecord = Record<string, NodeLike>
388
+
389
+ /**
390
+ * Node store that can contain both root-level nodes and scoped node objects.
391
+ * Structure: { wobble: OperatorNode, fx: { blur: ShaderCallable } }
392
+ */
393
+ type NodeStore = Record<string, NodeLike | NodeRecord>
394
+
554
395
  //* Storage Types (useGPUStorage) ========================================
555
396
 
556
397
  /**
@@ -684,14 +525,31 @@ interface InternalState {
684
525
  /** Container for child attachment (scene for root, original container for portals) */
685
526
  container?: THREE$1.Object3D
686
527
  /**
687
- * CanvasTarget for multi-canvas WebGPU rendering.
688
- * Created for all WebGPU canvases to support renderer sharing.
528
+ * The CanvasTarget this root sizes and renders through.
529
+ *
530
+ * A primary (`<Canvas id>`) owns the renderer's default target -- the one three itself built
531
+ * around the canvas element -- so sizing it is sizing the renderer. A secondary owns a target
532
+ * R3F created for its own element. Either way there is exactly one target per canvas element,
533
+ * and the canvas-target job makes it the renderer's active one before this root renders.
534
+ * Absent on WebGL and on an id-less WebGPU canvas, where the renderer is sized directly.
689
535
  * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
690
536
  */
691
537
  canvasTarget?: CanvasTarget
538
+ /**
539
+ * Set when this root's canvas target has been resized and the backend's cached render pass
540
+ * descriptor (which holds a depth-stencil view built once per canvas) is therefore stale.
541
+ *
542
+ * Flushed by the canvas-target job in the `start` phase, which is the only place this root's
543
+ * target is guaranteed to be the renderer's active one — `backend.updateSize()` operates on
544
+ * whatever `getCanvasTarget()` returns, so calling it from the resize subscription would
545
+ * invalidate some other canvas's descriptor instead.
546
+ *
547
+ * @see https://github.com/pmndrs/react-three-fiber/issues/3847
548
+ */
549
+ canvasTargetSizeDirty?: boolean
692
550
  /**
693
551
  * Whether multi-canvas rendering is active.
694
- * True when any canvas uses `target` prop to share a renderer.
552
+ * True when any canvas uses `renderer={{ primaryCanvas: 'id' }}` to share a renderer.
695
553
  * When true, setCanvasTarget is called before each render.
696
554
  */
697
555
  isMultiCanvas?: boolean
@@ -789,8 +647,8 @@ interface RootState {
789
647
  setSize: (width?: number, height?: number, top?: number, left?: number) => void
790
648
  /** Shortcut to manual setting the pixel ratio */
791
649
  setDpr: (dpr: Dpr) => void
792
- /** Shortcut to setting frameloop flags */
793
- setFrameloop: (frameloop: Frameloop) => void
650
+ /** Shortcut to setting frameloop flags. No args resets to 'always'. */
651
+ setFrameloop: (frameloop?: Frameloop) => void
794
652
  /** Set error state to propagate to error boundary */
795
653
  setError: (error: Error | null) => void
796
654
  /** Current error state (null when no error) */
@@ -798,17 +656,19 @@ interface RootState {
798
656
  /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
799
657
  uniforms: UniformStore
800
658
  /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
801
- nodes: Record<string, any>
659
+ nodes: NodeStore
802
660
  /** Global TSL buffer nodes - root-level buffers + scoped sub-objects. Use useBuffers() hook */
803
661
  buffers: BufferStore
804
662
  /** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
805
663
  gpuStorage: StorageStore
806
- /** Global TSL texture nodes - use useTextures() hook for operations */
807
- textures: Map<string, any>
664
+ /** Global Texture registry (key → Texture, usually keyed by URL) - use useTextures() hook for access + lifecycle */
665
+ textures: Map<string, THREE$1.Texture>
666
+ /** Internal: refcount per texture key, driven by mounted useTexture consumers (registry enrollment is on by default) */
667
+ _textureRefs: Map<string, number>
808
668
  /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
809
- renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
669
+ renderPipeline: ThreeRenderPipeline | null
810
670
  /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
811
- passes: Record<string, any>
671
+ passes: PassRecord
812
672
  /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
813
673
  _hmrVersion: number
814
674
  /** Internal: whether setSize() has taken ownership of canvas dimensions */
@@ -857,6 +717,20 @@ interface Renderer {
857
717
  render: (scene: THREE$1.Scene, camera: THREE$1.Camera) => any
858
718
  }
859
719
 
720
+ //* Color Management Config ==============================
721
+
722
+ /**
723
+ * Color management configuration shared by both WebGL and WebGPU renderers.
724
+ */
725
+ interface ColorManagementConfig {
726
+ /**
727
+ * Color space assigned to 8-bit input textures (color maps).
728
+ * Defaults to sRGB. Most textures are authored in sRGB.
729
+ * @default THREE.SRGBColorSpace
730
+ */
731
+ textureColorSpace?: THREE$1.ColorSpace
732
+ }
733
+
860
734
  //* WebGL Renderer Props ==============================
861
735
 
862
736
  type DefaultGLProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & {
@@ -867,7 +741,7 @@ type GLProps =
867
741
  | Renderer
868
742
  | ((defaultProps: DefaultGLProps) => Renderer)
869
743
  | ((defaultProps: DefaultGLProps) => Promise<Renderer>)
870
- | Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters>
744
+ | (Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters> & ColorManagementConfig)
871
745
 
872
746
  //* WebGPU Renderer Props ==============================
873
747
 
@@ -882,20 +756,27 @@ type DefaultRendererProps = {
882
756
  */
883
757
  interface CanvasSchedulerConfig {
884
758
  /**
885
- * Render this canvas after another canvas completes.
886
- * Pass the `id` of another canvas.
759
+ * Run this Canvas root before the referenced Canvas root id(s).
760
+ */
761
+ before?: string | string[]
762
+ /**
763
+ * Run this Canvas root after the referenced Canvas root id(s).
764
+ */
765
+ after?: string | string[]
766
+ /**
767
+ * Numeric root order. Lower values run first.
887
768
  */
888
- after?: string
769
+ order?: number
889
770
  /**
890
- * Limit this canvas's render rate (frames per second).
771
+ * Limit this Canvas's default render job (frames per second).
891
772
  */
892
773
  fps?: number
893
774
  }
894
775
 
895
776
  /**
896
- * Extended renderer configuration for multi-canvas support.
777
+ * Extended renderer configuration for multi-canvas support and color management.
897
778
  */
898
- interface RendererConfigExtended {
779
+ interface RendererConfigExtended extends ColorManagementConfig {
899
780
  /** Share renderer from another canvas (WebGPU only) */
900
781
  primaryCanvas?: string
901
782
  /** Canvas-level scheduler options */
@@ -960,8 +841,6 @@ interface RenderProps<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
960
841
  * @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.shadowMap
961
842
  */
962
843
  shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
963
- /** Color space assigned to 8-bit input textures (color maps). Defaults to sRGB. Most textures are authored in sRGB. */
964
- textureColorSpace?: THREE$1.ColorSpace
965
844
  /** Creates an orthographic camera */
966
845
  orthographic?: boolean
967
846
  /**
@@ -1087,8 +966,6 @@ interface Instance<O = any> {
1087
966
  attach?: AttachType<O>
1088
967
  previousAttach?: any
1089
968
  isHidden: boolean
1090
- /** Deferred ref props to apply in commitMount */
1091
- deferredRefs?: Array<{ prop: string; ref: React$1.RefObject<any> }>
1092
969
  /** Set of props that have been applied via once() */
1093
970
  appliedOnce?: Set<string>
1094
971
  }
@@ -1214,7 +1091,7 @@ interface CanvasProps
1214
1091
  */
1215
1092
  resize?: Options
1216
1093
  /** The target where events are being subscribed to, default: the div that wraps canvas */
1217
- eventSource?: HTMLElement | React$1.RefObject<HTMLElement>
1094
+ eventSource?: HTMLElement | React$1.RefObject<HTMLElement | null>
1218
1095
  /** The event prefix that is cast into canvas pointer x/y events, default: "offset" */
1219
1096
  eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen'
1220
1097
  /** Enable/disable automatic HMR refresh for TSL nodes and uniforms, default: true in dev */
@@ -1325,10 +1202,47 @@ type RenderTargetOptions = RenderTargetOptions$1
1325
1202
  //* Global Types ==============================
1326
1203
 
1327
1204
  declare global {
1328
- /** Uniform node type - a Node with a value property (matches Three.js UniformNode) */
1329
- interface UniformNode<T = unknown> extends Node {
1330
- value: T
1331
- }
1205
+ /**
1206
+ * Uniform node type.
1207
+ *
1208
+ * This is three's own `UniformNode`, not a re-declaration of it. It previously was a
1209
+ * hand-rolled `interface UniformNode<T> extends Node { value: T }`, which shadowed the real
1210
+ * exported type globally — so R3F's ~58 references resolved to an approximation that was
1211
+ * missing members three actually ships (`setName` among them) and had drifted to the wrong
1212
+ * arity when three made `UniformNode` two-parameter.
1213
+ *
1214
+ * three's signature is `UniformNode<TNodeType, TValue>`. R3F only ever varies the value type,
1215
+ * so the node type is fixed to `unknown` and the single parameter is kept for call-site
1216
+ * ergonomics. The result is three's structural type, so members stay in sync with the
1217
+ * installed three instead of needing to be mirrored by hand.
1218
+ */
1219
+ type UniformNode<T = unknown> = three_webgpu.UniformNode<UniformNodeTypeFor<T>, T>
1220
+
1221
+ /**
1222
+ * three's node type name for a uniform value type, mirroring the `uniform()` overloads.
1223
+ * A `UniformNode<number>` is a `Node<'float'>`, so TSL math (`.mul`, `.add`, ...) accepts it.
1224
+ * Unknown or unlisted value types resolve to `unknown`, which TSL math rejects: narrow with
1225
+ * `as UniformNode<number>` (or the matching value type) at the call site.
1226
+ */
1227
+ type UniformNodeTypeFor<T> = T extends number
1228
+ ? 'float'
1229
+ : T extends boolean
1230
+ ? 'bool'
1231
+ : T extends three_webgpu.Color
1232
+ ? 'color'
1233
+ : T extends three_webgpu.Vector2
1234
+ ? 'vec2'
1235
+ : T extends three_webgpu.Vector3
1236
+ ? 'vec3'
1237
+ : T extends three_webgpu.Vector4
1238
+ ? 'vec4'
1239
+ : T extends three_webgpu.Matrix2
1240
+ ? 'mat2'
1241
+ : T extends three_webgpu.Matrix3
1242
+ ? 'mat3'
1243
+ : T extends three_webgpu.Matrix4
1244
+ ? 'mat4'
1245
+ : unknown
1332
1246
 
1333
1247
  /**
1334
1248
  * ShaderCallable - the return type of Fn()
@@ -1473,177 +1387,105 @@ declare module 'three/tsl' {
1473
1387
  ): ShaderCallable<R>
1474
1388
  }
1475
1389
 
1476
- /**
1477
- * RenderPipeline Types for useRenderPipeline hook (WebGPU only)
1478
- */
1479
-
1480
-
1481
-
1482
1390
  declare global {
1483
- /** Pass record - stores TSL pass nodes for render pipeline */
1484
- type PassRecord = Record<string, any>
1485
-
1486
- /** Setup callback - runs first to configure MRT, create additional passes */
1487
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1488
-
1489
- /** Main callback - runs second to configure outputNode, create effect passes */
1490
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1491
-
1492
- /** Return type for useRenderPipeline hook */
1493
- interface UseRenderPipelineReturn {
1494
- /** Current passes from state */
1495
- passes: PassRecord
1496
- /** RenderPipeline instance (null if not initialized) */
1497
- renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
1498
- /** Clear all passes from state */
1499
- clearPasses: () => void
1500
- /** Reset RenderPipeline entirely (clears PP + passes) */
1501
- reset: () => void
1502
- /** Re-run setup/main callbacks with current closure values */
1503
- rebuild: () => void
1504
- /** True when RenderPipeline is configured and ready */
1505
- isReady: boolean
1506
- }
1507
- }
1508
-
1509
- //* useFrameNext Types ==============================
1510
-
1511
-
1512
-
1513
- //* Global Type Declarations ==============================
1514
-
1515
- declare global {
1516
- // Job --------------------------------
1517
-
1518
1391
  /**
1519
- * Internal job representation in the scheduler
1392
+ * three's own render pipeline type. Named here so the rest of R3F refers to three's shape
1393
+ * rather than `any`. three r183 renamed `PostProcessing` to `RenderPipeline`; our peer floor
1394
+ * is r185, so the new name is the only one.
1520
1395
  */
1521
- interface Job {
1522
- /** Unique identifier */
1523
- id: string
1524
- /** The callback to execute */
1525
- callback: FrameNextCallback
1526
- /** Phase this job belongs to */
1527
- phase: string
1528
- /** Run before these phases/job ids */
1529
- before: Set<string>
1530
- /** Run after these phases/job ids */
1531
- after: Set<string>
1532
- /** Priority within phase (higher first) */
1533
- priority: number
1534
- /** Insertion order for deterministic tie-breaking */
1535
- index: number
1536
- /** Max FPS for this job (undefined = no limit) */
1537
- fps?: number
1538
- /** Drop frames when behind (true) or catch up (false) */
1539
- drop: boolean
1540
- /** Last run timestamp (ms) */
1541
- lastRun?: number
1542
- /** Whether job is enabled */
1543
- enabled: boolean
1544
- /** Internal flag: system jobs (like default render) don't block user render takeover */
1545
- system?: boolean
1546
- }
1547
-
1548
- // Phase Graph --------------------------------
1396
+ type ThreeRenderPipeline = three_webgpu.RenderPipeline
1549
1397
 
1550
1398
  /**
1551
- * A node in the phase graph
1399
+ * The pass `useRenderPipeline` creates for you: three's own `PassNode`, as returned by
1400
+ * `pass(scene, camera)` from `three/tsl`. Referenced from three so members like
1401
+ * `getTextureNode`, `setMRT` and `dispose` track the installed version.
1552
1402
  */
1553
- interface PhaseNode {
1554
- /** Phase name */
1555
- name: string
1556
- /** Whether this was auto-generated from a before/after constraint */
1557
- isAutoGenerated: boolean
1558
- }
1403
+ type ScenePassNode = three_webgpu.PassNode
1559
1404
 
1560
1405
  /**
1561
- * Options for creating a job from hook options
1406
+ * Pass record - stores TSL pass nodes for render pipeline.
1407
+ *
1408
+ * `scenePass` is the only key the library owns. It is optional here because this is also the
1409
+ * shape of `state.passes`, which is `{}` before the pipeline exists and again after `reset()`
1410
+ * or `clearPasses()`. Inside the callbacks it is always present; see
1411
+ * {@link RenderPipelineCallbackState}.
1412
+ *
1413
+ * Every other key is user-registered, via a callback's return value. Those are TSL nodes of
1414
+ * any kind, not only passes: texture reads of an MRT attachment, effect nodes, extra
1415
+ * `pass()` instances. `Node` is the common base, so that is the bound. Narrow at the call
1416
+ * site when you need a member, e.g. `passes.velocity as TextureNode`.
1562
1417
  */
1563
- interface JobOptions {
1564
- id?: string
1565
- phase?: string
1566
- before?: string | string[]
1567
- after?: string | string[]
1568
- priority?: number
1569
- fps?: number
1570
- drop?: boolean
1571
- enabled?: boolean
1418
+ interface PassRecord {
1419
+ scenePass?: ScenePassNode
1420
+ [key: string]: three_webgpu.Node
1572
1421
  }
1573
1422
 
1574
- // Frame Loop State --------------------------------
1575
-
1576
1423
  /**
1577
- * Internal frame loop state
1424
+ * State passed to pipeline callbacks after the active pipeline has been created.
1425
+ *
1426
+ * `passes.scenePass` is required here: the hook installs the default scene pass before either
1427
+ * callback runs, so callbacks can use it without a guard or a cast.
1428
+ *
1429
+ * `renderer` is narrowed to `WebGPURenderer` and `isLegacy` to `false`: the hook throws under
1430
+ * the legacy renderer before either callback can run, so a callback never sees WebGL.
1578
1431
  */
1579
- interface FrameLoopState {
1580
- /** Whether the loop is running */
1581
- running: boolean
1582
- /** Current RAF handle */
1583
- rafHandle: number | null
1584
- /** Last frame timestamp in ms (null = uninitialized) */
1585
- lastTime: number | null
1586
- /** Frame counter */
1587
- frameCount: number
1588
- /** Elapsed time since first frame in ms */
1589
- elapsedTime: number
1590
- /** createdAt timestamp in ms */
1591
- createdAt: number
1432
+ type RenderPipelineCallbackState = RootState & {
1433
+ renderPipeline: ThreeRenderPipeline
1434
+ passes: PassRecord & { scenePass: ScenePassNode }
1435
+ renderer: three_webgpu.WebGPURenderer
1436
+ isLegacy: false
1592
1437
  }
1593
1438
 
1594
- // Root Entry --------------------------------
1595
-
1596
1439
  /**
1597
- * Internal representation of a registered root (Canvas).
1598
- * Tracks jobs and manages rebuild state for this root.
1599
- * @internal
1440
+ * What a callback may return to register entries into `state.passes`.
1441
+ *
1442
+ * `scenePass` is reserved. The hook owns that entry and its lifecycle: it caches the pass it
1443
+ * created, and `rebuild()` / `reset()` dispose that cached pass. A callback overwriting the
1444
+ * store entry would leave the store pointing at a node the hook never disposes, and the hook
1445
+ * disposing a pass nothing references. So returning it is a type error.
1600
1446
  */
1601
- interface RootEntry {
1602
- /** Unique identifier for this root */
1603
- id: string
1604
- /** Function to get the root's current state. Returns any to support independent mode. */
1605
- getState: () => any
1606
- /** Map of job IDs to Job objects */
1607
- jobs: Map<string, Job>
1608
- /** Cached sorted job list for execution order */
1609
- sortedJobs: Job[]
1610
- /** Whether sortedJobs needs rebuilding */
1611
- needsRebuild: boolean
1612
- }
1447
+ type RegisteredPasses = Record<string, three_webgpu.Node> & { scenePass?: never }
1613
1448
 
1614
- /**
1615
- * Internal representation of a global job (deprecated API).
1616
- * Global jobs run once per frame, not per-root.
1617
- * Used by legacy addEffect/addAfterEffect APIs.
1618
- * @internal
1619
- * @deprecated Use useFrame with phases instead
1620
- */
1621
- interface GlobalJob {
1622
- /** Unique identifier for this global job */
1623
- id: string
1624
- /** Callback invoked with RAF timestamp in ms */
1625
- callback: (timestamp: number) => void
1626
- }
1449
+ /** Setup callback - runs first to configure MRT, create additional passes */
1450
+ type RenderPipelineSetupCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1627
1451
 
1628
- // HMR Support --------------------------------
1452
+ /** Main callback - runs second to configure outputNode, create effect passes */
1453
+ type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1629
1454
 
1630
- /**
1631
- * Hot Module Replacement data structure for preserving scheduler state
1632
- * @internal
1633
- */
1634
- interface HMRData {
1635
- /** Shared data object for storing values across reloads */
1636
- data: Record<string, any>
1637
- /** Optional function to accept HMR updates */
1638
- accept?: () => void
1455
+ /** The imperative half of useRenderPipeline's return value, present in every state */
1456
+ interface UseRenderPipelineActions {
1457
+ /** Current passes from state */
1458
+ passes: PassRecord
1459
+ /** Clear all passes from state */
1460
+ clearPasses: () => void
1461
+ /** Reset RenderPipeline entirely (clears PP + passes) */
1462
+ reset: () => void
1463
+ /** Re-run setup/main callbacks with current closure values */
1464
+ rebuild: () => void
1639
1465
  }
1640
1466
 
1641
- // Default Phases --------------------------------
1642
-
1643
1467
  /**
1644
- * Default phase names for the scheduler
1468
+ * Return type for useRenderPipeline hook, discriminated on `isReady`.
1469
+ *
1470
+ * `if (isReady)` narrows `renderPipeline` to non-null, which is what the docs already tell
1471
+ * callers to check. `passes.scenePass` deliberately stays optional in the ready branch:
1472
+ * `clearPasses()` empties the record while leaving the pipeline in place.
1645
1473
  */
1646
- type DefaultPhase = 'start' | 'input' | 'physics' | 'update' | 'render' | 'finish'
1474
+ type UseRenderPipelineReturn = UseRenderPipelineActions &
1475
+ (
1476
+ | {
1477
+ /** True when RenderPipeline is configured and ready */
1478
+ isReady: true
1479
+ /** RenderPipeline instance */
1480
+ renderPipeline: ThreeRenderPipeline
1481
+ }
1482
+ | {
1483
+ /** False until the pipeline has been created */
1484
+ isReady: false
1485
+ /** Not initialized yet, or torn down by reset() */
1486
+ renderPipeline: null
1487
+ }
1488
+ )
1647
1489
  }
1648
1490
 
1649
1491
  type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
@@ -1815,7 +1657,7 @@ declare namespace three_d {
1815
1657
  * a single WebGPURenderer using Three.js CanvasTarget API.
1816
1658
  *
1817
1659
  * Primary canvas: Has `id` prop, creates its own renderer, registers here
1818
- * Secondary canvas: Has `target="id"` prop, shares primary's renderer via CanvasTarget
1660
+ * Secondary canvas: Has `renderer={{ primaryCanvas: 'id' }}`, shares primary's renderer via CanvasTarget
1819
1661
  */
1820
1662
 
1821
1663
  interface PrimaryCanvasEntry {
@@ -1883,12 +1725,23 @@ type EnvironmentLoaderProps = {
1883
1725
  * const texture = useEnvironment({ preset: 'sunset' })
1884
1726
  * ```
1885
1727
  */
1886
- declare function useEnvironment({ files, path, preset, colorSpace, extensions, }?: Partial<EnvironmentLoaderProps>): Texture$1<unknown> | CubeTexture;
1728
+ declare function useEnvironment({ files, path, preset, colorSpace, extensions, }?: Partial<EnvironmentLoaderProps>): Texture$1<unknown, THREE$1.TextureEventMap> | CubeTexture<unknown>;
1887
1729
  declare namespace useEnvironment {
1888
1730
  var preload: (preloadOptions?: EnvironmentLoaderPreloadOptions) => void;
1889
1731
  var clear: (clearOptions?: EnvironmentLoaderClearOptions) => void;
1890
1732
  }
1891
- type EnvironmentLoaderPreloadOptions = Omit<EnvironmentLoaderProps, 'encoding'>;
1733
+ /**
1734
+ * Options accepted by `useEnvironment.preload`.
1735
+ *
1736
+ * `colorSpace` is deliberately omitted: preload only warms the loader cache, and colorSpace is
1737
+ * applied to the texture by `useEnvironment()` at use time, per consumer. Accepting it here would
1738
+ * advertise an option this function silently ignores.
1739
+ *
1740
+ * This previously read `Omit<…, 'encoding'>` — omitting a key that does not exist on
1741
+ * `EnvironmentLoaderProps`, a leftover from three's pre-`colorSpace` `encoding` API. That made the
1742
+ * type equivalent to the full props, so `colorSpace` was accepted and then dropped on the floor.
1743
+ */
1744
+ type EnvironmentLoaderPreloadOptions = Omit<EnvironmentLoaderProps, 'colorSpace'>;
1892
1745
  type EnvironmentLoaderClearOptions = Pick<EnvironmentLoaderProps, 'files' | 'preset'>;
1893
1746
 
1894
1747
  /**
@@ -1932,9 +1785,9 @@ type EnvironmentProps = {
1932
1785
  blur?: number;
1933
1786
  backgroundBlurriness?: number;
1934
1787
  backgroundIntensity?: number;
1935
- backgroundRotation?: Euler$3;
1788
+ backgroundRotation?: Euler;
1936
1789
  environmentIntensity?: number;
1937
- environmentRotation?: Euler$3;
1790
+ environmentRotation?: Euler;
1938
1791
  map?: Texture$1;
1939
1792
  preset?: PresetsType;
1940
1793
  scene?: Scene | React$1.RefObject<Scene>;
@@ -2018,7 +1871,7 @@ declare function EnvironmentCube({ background, scene, blur, backgroundBlurriness
2018
1871
  declare function EnvironmentPortal({ children, near, far, resolution, frames, map, background, blur, backgroundBlurriness, backgroundIntensity, backgroundRotation, environmentIntensity, environmentRotation, scene, files, path, preset, extensions, }: EnvironmentProps): react_jsx_runtime.JSX.Element;
2019
1872
  declare module '@react-three/fiber' {
2020
1873
  interface ThreeElements {
2021
- groundProjectedEnvImpl: ThreeElement$1<typeof GroundedSkybox>;
1874
+ groundProjectedEnvImpl: ThreeElement<typeof GroundedSkybox>;
2022
1875
  }
2023
1876
  }
2024
1877
  /**
@@ -2118,6 +1971,24 @@ declare module '@react-three/fiber' {
2118
1971
  */
2119
1972
  declare function Environment(props: EnvironmentProps): react_jsx_runtime.JSX.Element;
2120
1973
 
1974
+ /**
1975
+ * Moves every trace of interactivity from one object to its replacement, for reconstruction.
1976
+ *
1977
+ * When `args` or a `primitive`'s `object` changes, R3F builds a new three object and keeps the same
1978
+ * instance. Removing the old object from the interaction state and registering the new one from
1979
+ * scratch makes events *work* again (#3778), but it forgets what was in flight: a pointer resting on
1980
+ * the object fires a second `onPointerEnter` without ever having left, and an active pointer capture
1981
+ * is dropped mid-drag. Rewriting the references instead keeps the interaction continuous across a
1982
+ * swap the user never asked to see (#3744).
1983
+ *
1984
+ * Captures are re-keyed rather than released, so the DOM-level capture on `captureData.target` is
1985
+ * left alone — releasing and re-acquiring it is precisely the glitch being avoided.
1986
+ *
1987
+ * Visibility handlers are deliberately not transferred: that registry is keyed by `object.uuid`, so
1988
+ * the replacement re-registers itself through `applyProps`. The old entry is dropped here so it
1989
+ * cannot outlive the object it described.
1990
+ */
1991
+ declare function swapInteractivity(store: RootStore, object: Object3D, newObject: Object3D): void;
2121
1992
  declare function removeInteractivity(store: RootStore, object: Object3D): void;
2122
1993
  declare function createEvents(store: RootStore): {
2123
1994
  handlePointer: (name: string) => (event: DomEvent) => void;
@@ -2138,419 +2009,13 @@ declare function getLoader<L extends LoaderLike | ConstructorRepresentation<Load
2138
2009
  * Note: this hook's caller must be wrapped with `React.Suspense`
2139
2010
  * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
2140
2011
  */
2141
- 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>;
2012
+ 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>;
2142
2013
  declare namespace useLoader {
2143
- var preload: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void) => void;
2144
- var clear: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I) => void;
2014
+ 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;
2015
+ var clear: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, cacheKey?: InputLike) => void;
2145
2016
  var loader: typeof getLoader;
2146
2017
  }
2147
2018
 
2148
- /**
2149
- * Global Singleton Scheduler - manages the frame loop and job execution for ALL R3F roots.
2150
- *
2151
- * Features:
2152
- * - Single RAF loop for entire application
2153
- * - Root registration (multiple Canvas support)
2154
- * - Global phases for addEffect/addAfterEffect (deprecated)
2155
- * - Per-root job management with phases, priorities, FPS throttling
2156
- * - onIdle callbacks for addTail (deprecated)
2157
- * - Demand mode support via invalidate()
2158
- */
2159
- declare class Scheduler {
2160
- private static readonly INSTANCE_KEY;
2161
- private static get instance();
2162
- private static set instance(value);
2163
- /**
2164
- * Get the global scheduler instance (creates if doesn't exist).
2165
- * Uses HMR data to preserve instance across hot reloads.
2166
- * @returns {Scheduler} The singleton scheduler instance
2167
- */
2168
- static get(): Scheduler;
2169
- /**
2170
- * Reset the singleton instance. Stops the loop and clears all state.
2171
- * Primarily used for testing to ensure clean state between tests.
2172
- * @returns {void}
2173
- */
2174
- static reset(): void;
2175
- private roots;
2176
- private phaseGraph;
2177
- private loopState;
2178
- private stoppedTime;
2179
- private nextRootIndex;
2180
- private globalBeforeJobs;
2181
- private globalAfterJobs;
2182
- private nextGlobalIndex;
2183
- private idleCallbacks;
2184
- private nextJobIndex;
2185
- private jobStateListeners;
2186
- private pendingFrames;
2187
- private _frameloop;
2188
- private _independent;
2189
- private errorHandler;
2190
- private rootReadyCallbacks;
2191
- get phases(): string[];
2192
- get frameloop(): Frameloop;
2193
- set frameloop(mode: Frameloop);
2194
- get isRunning(): boolean;
2195
- get isReady(): boolean;
2196
- get independent(): boolean;
2197
- set independent(value: boolean);
2198
- constructor();
2199
- /**
2200
- * Register a root (Canvas) with the scheduler.
2201
- * The first root to register starts the RAF loop (if frameloop='always').
2202
- * @param {string} id - Unique identifier for this root
2203
- * @param {RootOptions} [options] - Optional configuration with getState and onError callbacks
2204
- * @returns {() => void} Unsubscribe function to remove this root
2205
- */
2206
- registerRoot(id: string, options?: RootOptions): () => void;
2207
- /**
2208
- * Unregister a root from the scheduler.
2209
- * Cleans up all job state listeners for this root's jobs.
2210
- * The last root to unregister stops the RAF loop.
2211
- * @param {string} id - The root ID to unregister
2212
- * @returns {void}
2213
- */
2214
- unregisterRoot(id: string): void;
2215
- /**
2216
- * Subscribe to be notified when a root becomes available.
2217
- * Fires immediately if a root already exists.
2218
- * @param {() => void} callback - Function called when first root registers
2219
- * @returns {() => void} Unsubscribe function
2220
- */
2221
- onRootReady(callback: () => void): () => void;
2222
- /**
2223
- * Notify all registered root-ready callbacks.
2224
- * Called when the first root registers.
2225
- * @returns {void}
2226
- * @private
2227
- */
2228
- private notifyRootReady;
2229
- /**
2230
- * Ensure a default root exists for independent mode.
2231
- * Creates a minimal root with no state provider.
2232
- * @returns {void}
2233
- * @private
2234
- */
2235
- private ensureDefaultRoot;
2236
- /**
2237
- * Trigger error handling for job errors.
2238
- * Uses the bound error handler if available, otherwise logs to console.
2239
- * @param {Error} error - The error to handle
2240
- * @returns {void}
2241
- */
2242
- triggerError(error: Error): void;
2243
- /**
2244
- * Add a named phase to the scheduler's execution order.
2245
- * Marks all roots for rebuild to incorporate the new phase.
2246
- * @param {string} name - The phase name (e.g., 'physics', 'postprocess')
2247
- * @param {AddPhaseOptions} [options] - Positioning options (before/after other phases)
2248
- * @returns {void}
2249
- * @example
2250
- * scheduler.addPhase('physics', { before: 'update' });
2251
- * scheduler.addPhase('postprocess', { after: 'render' });
2252
- */
2253
- addPhase(name: string, options?: AddPhaseOptions): void;
2254
- /**
2255
- * Check if a phase exists in the scheduler.
2256
- * @param {string} name - The phase name to check
2257
- * @returns {boolean} True if the phase exists
2258
- */
2259
- hasPhase(name: string): boolean;
2260
- /**
2261
- * Register a global job that runs once per frame (not per-root).
2262
- * Used internally by deprecated addEffect/addAfterEffect APIs.
2263
- * @param {'before' | 'after'} phase - When to run: 'before' all roots or 'after' all roots
2264
- * @param {string} id - Unique identifier for this global job
2265
- * @param {(timestamp: number) => void} callback - Function called each frame with RAF timestamp
2266
- * @returns {() => void} Unsubscribe function to remove this global job
2267
- * @deprecated Use useFrame with phases instead
2268
- */
2269
- registerGlobal(phase: 'before' | 'after', id: string, callback: (timestamp: number) => void): () => void;
2270
- /**
2271
- * Register an idle callback that fires when the loop stops.
2272
- * Used internally by deprecated addTail API.
2273
- * @param {(timestamp: number) => void} callback - Function called when loop becomes idle
2274
- * @returns {() => void} Unsubscribe function to remove this idle callback
2275
- * @deprecated Use demand mode with invalidate() instead
2276
- */
2277
- onIdle(callback: (timestamp: number) => void): () => void;
2278
- /**
2279
- * Notify all registered idle callbacks.
2280
- * Called when the loop stops in demand mode.
2281
- * @param {number} timestamp - The RAF timestamp when idle occurred
2282
- * @returns {void}
2283
- * @private
2284
- */
2285
- private notifyIdle;
2286
- /**
2287
- * Register a job (frame callback) with a specific root.
2288
- * This is the core registration method used by useFrame internally.
2289
- * @param {FrameNextCallback} callback - The function to call each frame
2290
- * @param {JobOptions & { rootId?: string; system?: boolean }} [options] - Job configuration
2291
- * @param {string} [options.rootId] - Target root ID (defaults to first registered root)
2292
- * @param {string} [options.id] - Unique job ID (auto-generated if not provided)
2293
- * @param {string} [options.phase] - Execution phase (defaults to 'update')
2294
- * @param {number} [options.priority] - Priority within phase (higher = earlier, default 0)
2295
- * @param {number} [options.fps] - FPS throttle limit
2296
- * @param {boolean} [options.drop] - Drop frames when behind (default true)
2297
- * @param {boolean} [options.enabled] - Whether job is active (default true)
2298
- * @param {boolean} [options.system] - Internal flag for system jobs (not user-facing)
2299
- * @returns {() => void} Unsubscribe function to remove this job
2300
- */
2301
- register(callback: FrameNextCallback, options?: JobOptions & {
2302
- rootId?: string;
2303
- system?: boolean;
2304
- }): () => void;
2305
- /**
2306
- * Unregister a job by its ID.
2307
- * Searches all roots if rootId is not provided.
2308
- * @param {string} id - The job ID to unregister
2309
- * @param {string} [rootId] - Optional root ID to search (searches all if not provided)
2310
- * @returns {void}
2311
- */
2312
- unregister(id: string, rootId?: string): void;
2313
- /**
2314
- * Update a job's options dynamically.
2315
- * Searches all roots to find the job by ID.
2316
- * Phase/constraint changes trigger a rebuild of the sorted job list.
2317
- * @param {string} id - The job ID to update
2318
- * @param {Partial<JobOptions>} options - The options to update
2319
- * @returns {void}
2320
- */
2321
- updateJob(id: string, options: Partial<JobOptions>): void;
2322
- /**
2323
- * Check if a job is currently paused (disabled).
2324
- * @param {string} id - The job ID to check
2325
- * @returns {boolean} True if the job exists and is paused
2326
- */
2327
- isJobPaused(id: string): boolean;
2328
- /**
2329
- * Subscribe to state changes for a specific job.
2330
- * Listener is called when job is paused or resumed.
2331
- * @param {string} id - The job ID to subscribe to
2332
- * @param {() => void} listener - Callback invoked on state changes
2333
- * @returns {() => void} Unsubscribe function
2334
- */
2335
- subscribeJobState(id: string, listener: () => void): () => void;
2336
- /**
2337
- * Notify all listeners that a job's state has changed.
2338
- * @param {string} id - The job ID that changed
2339
- * @returns {void}
2340
- * @private
2341
- */
2342
- private notifyJobStateChange;
2343
- /**
2344
- * Pause a job by ID (sets enabled=false).
2345
- * Notifies any subscribed state listeners.
2346
- * @param {string} id - The job ID to pause
2347
- * @returns {void}
2348
- */
2349
- pauseJob(id: string): void;
2350
- /**
2351
- * Resume a paused job by ID (sets enabled=true).
2352
- * Resets job timing to prevent frame accumulation.
2353
- * Notifies any subscribed state listeners.
2354
- * @param {string} id - The job ID to resume
2355
- * @returns {void}
2356
- */
2357
- resumeJob(id: string): void;
2358
- /**
2359
- * Start the requestAnimationFrame loop.
2360
- * Resets timing state (elapsedTime, frameCount) on start.
2361
- * No-op if already running.
2362
- * @returns {void}
2363
- */
2364
- start(): void;
2365
- /**
2366
- * Stop the requestAnimationFrame loop.
2367
- * Cancels any pending RAF callback.
2368
- * No-op if not running.
2369
- * @returns {void}
2370
- */
2371
- stop(): void;
2372
- /**
2373
- * Request frames to be rendered in demand mode.
2374
- * Accumulates pending frames (capped at 60) and starts the loop if not running.
2375
- * No-op if frameloop is not 'demand'.
2376
- * @param {number} [frames=1] - Number of frames to request
2377
- * @param {boolean} [stackFrames=false] - Whether to add frames to existing pending count
2378
- * - `false` (default): Sets pending frames to the specified value (replaces existing count)
2379
- * - `true`: Adds frames to existing pending count (useful for accumulating invalidations)
2380
- * @returns {void}
2381
- * @example
2382
- * // Request a single frame render
2383
- * scheduler.invalidate();
2384
- *
2385
- * @example
2386
- * // Request 5 frames (e.g., for animations)
2387
- * scheduler.invalidate(5);
2388
- *
2389
- * @example
2390
- * // Set pending frames to exactly 3 (don't stack with existing)
2391
- * scheduler.invalidate(3, false);
2392
- *
2393
- * @example
2394
- * // Add 2 more frames to existing pending count
2395
- * scheduler.invalidate(2, true);
2396
- */
2397
- invalidate(frames?: number, stackFrames?: boolean): void;
2398
- /**
2399
- * Reset timing state for deterministic testing.
2400
- * Preserves jobs and roots but resets lastTime, frameCount, elapsedTime, etc.
2401
- * @returns {void}
2402
- */
2403
- resetTiming(): void;
2404
- /**
2405
- * Manually execute a single frame for all roots.
2406
- * Useful for frameloop='never' mode or testing scenarios.
2407
- * @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
2408
- * @returns {void}
2409
- * @example
2410
- * // Manual control mode
2411
- * scheduler.frameloop = 'never';
2412
- * scheduler.step(); // Execute one frame
2413
- */
2414
- step(timestamp?: number): void;
2415
- /**
2416
- * Manually execute a single job by its ID.
2417
- * Useful for testing individual job callbacks in isolation.
2418
- * @param {string} id - The job ID to step
2419
- * @param {number} [timestamp] - Optional timestamp (defaults to performance.now())
2420
- * @returns {void}
2421
- */
2422
- stepJob(id: string, timestamp?: number): void;
2423
- /**
2424
- * Main RAF loop callback.
2425
- * Executes frame, handles demand mode, and schedules next frame.
2426
- * @param {number} timestamp - RAF timestamp in milliseconds
2427
- * @returns {void}
2428
- * @private
2429
- */
2430
- private loop;
2431
- /**
2432
- * Execute a single frame across all roots.
2433
- * Order: globalBefore → each root's jobs → globalAfter
2434
- * @param {number} timestamp - RAF timestamp in milliseconds
2435
- * @returns {void}
2436
- * @private
2437
- */
2438
- private executeFrame;
2439
- /**
2440
- * Run all global jobs from a job map.
2441
- * Catches and logs errors without stopping execution.
2442
- * @param {Map<string, GlobalJob>} jobs - The global jobs map to execute
2443
- * @param {number} timestamp - RAF timestamp in milliseconds
2444
- * @returns {void}
2445
- * @private
2446
- */
2447
- private runGlobalJobs;
2448
- /**
2449
- * Execute all jobs for a single root in sorted order.
2450
- * Rebuilds sorted job list if needed, then dispatches each job.
2451
- * Errors are caught and propagated via triggerError.
2452
- * @param {RootEntry} root - The root entry to tick
2453
- * @param {number} timestamp - RAF timestamp in milliseconds
2454
- * @param {number} delta - Time since last frame in seconds
2455
- * @returns {void}
2456
- * @private
2457
- */
2458
- private tickRoot;
2459
- /**
2460
- * Get the total number of registered jobs across all roots.
2461
- * Includes both per-root jobs and global before/after jobs.
2462
- * @returns {number} Total job count
2463
- */
2464
- getJobCount(): number;
2465
- /**
2466
- * Get all registered job IDs across all roots.
2467
- * Includes both per-root jobs and global before/after jobs.
2468
- * @returns {string[]} Array of all job IDs
2469
- */
2470
- getJobIds(): string[];
2471
- /**
2472
- * Get the number of registered roots (Canvas instances).
2473
- * @returns {number} Number of registered roots
2474
- */
2475
- getRootCount(): number;
2476
- /**
2477
- * Check if any user (non-system) jobs are registered in a specific phase.
2478
- * Used by the default render job to know if a user has taken over rendering.
2479
- *
2480
- * @param phase The phase to check
2481
- * @param rootId Optional root ID to check (checks all roots if not provided)
2482
- * @returns true if any user jobs exist in the phase
2483
- */
2484
- hasUserJobsInPhase(phase: string, rootId?: string): boolean;
2485
- /**
2486
- * Generate a unique root ID for automatic root registration.
2487
- * @returns {string} A unique root ID in the format 'root_N'
2488
- */
2489
- generateRootId(): string;
2490
- /**
2491
- * Generate a unique job ID.
2492
- * @returns {string} A unique job ID in the format 'job_N'
2493
- * @private
2494
- */
2495
- private generateJobId;
2496
- /**
2497
- * Normalize before/after constraints to a Set.
2498
- * Handles undefined, single string, or array inputs.
2499
- * @param {string | string[] | undefined} value - The constraint value(s)
2500
- * @returns {Set<string>} Normalized Set of constraint strings
2501
- * @private
2502
- */
2503
- private normalizeConstraints;
2504
- }
2505
- /**
2506
- * Get the global scheduler instance.
2507
- * Creates one if it doesn't exist.
2508
- */
2509
- declare const getScheduler: () => Scheduler;
2510
-
2511
- /**
2512
- * Frame hook with phase-based ordering, priority, and FPS throttling.
2513
- *
2514
- * Works both inside and outside Canvas context:
2515
- * - Inside Canvas: Full RootState (gl, scene, camera, etc.)
2516
- * - Outside Canvas (waiting mode): Waits for Canvas to mount, then gets full state
2517
- * - Outside Canvas (independent mode): Fires immediately with timing-only state
2518
- *
2519
- * Returns a controls object for manual stepping, pausing, and resuming.
2520
- *
2521
- * @param callback - Function called each frame with (state, delta). Optional if you only need scheduler access.
2522
- * @param priorityOrOptions - Either a priority number (backwards compat) or options object
2523
- * @returns Controls object with step(), stepAll(), pause(), resume(), isPaused, id, scheduler
2524
- *
2525
- * @example
2526
- * // Simple priority (backwards compat)
2527
- * useFrame((state, delta) => { ... }, 5)
2528
- *
2529
- * @example
2530
- * // With phase-based ordering
2531
- * useFrame((state, delta) => { ... }, { phase: 'physics' })
2532
- *
2533
- * @example
2534
- * // Outside Canvas - waits for Canvas to mount
2535
- * function UI() {
2536
- * useFrame((state, delta) => { syncUI(state.camera) });
2537
- * return <button>...</button>;
2538
- * }
2539
- *
2540
- * @example
2541
- * // Independent mode - no Canvas needed
2542
- * getScheduler().independent = true;
2543
- * useFrame((state, delta) => { updateGame(delta) });
2544
- *
2545
- * @example
2546
- * // Scheduler-only access (no callback)
2547
- * const { scheduler } = useFrame()
2548
- * scheduler.pauseJob('some-job-id')
2549
- *
2550
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
2551
- */
2552
- declare function useFrame(callback?: FrameNextCallback, priorityOrOptions?: number | UseFrameNextOptions): FrameNextControls;
2553
-
2554
2019
  declare const IsObject: (url: unknown) => url is Record<string, string>;
2555
2020
  type TextureArray<T> = T extends string[] ? Texture$1[] : never;
2556
2021
  type TextureRecord<T> = T extends Record<string, string> ? {
@@ -2563,11 +2028,16 @@ type UseTextureOptions<Url extends string[] | string | Record<string, string>> =
2563
2028
  /** Callback when texture(s) finish loading */
2564
2029
  onLoad?: (texture: MappedTextureType<Url>) => void;
2565
2030
  /**
2566
- * Cache the texture in R3F's global state for access via useTextures().
2567
- * When true:
2031
+ * Register the texture(s) in R3F's global texture registry for access via useTextures().
2032
+ * When true (the default):
2568
2033
  * - Textures persist until explicitly disposed
2569
- * - Returns existing cached textures if available (preserving modifications like colorSpace)
2570
- * @default false
2034
+ * - On mount, returns existing registered textures if available (preserving modifications like colorSpace)
2035
+ *
2036
+ * Reads are taken once at mount — a mounted `useTexture` does not re-render when the registry
2037
+ * changes. To react to registry swaps, use `useTextures(s => s.get(key))` instead.
2038
+ *
2039
+ * Pass `false` to opt out of registry enrollment entirely.
2040
+ * @default true
2571
2041
  */
2572
2042
  cache?: boolean;
2573
2043
  };
@@ -2591,15 +2061,18 @@ type UseTextureOptions<Url extends string[] | string | Record<string, string>> =
2591
2061
  * normal: '/normal.png'
2592
2062
  * })
2593
2063
  *
2594
- * // With caching - returns same texture object across components
2595
- * // Modifications (colorSpace, wrapS, etc.) are preserved
2596
- * const diffuse = useTexture('/diffuse.png', { cache: true })
2064
+ * // Textures are registered in the global registry by default — the same texture
2065
+ * // object is shared across components and modifications (colorSpace, wrapS, etc.) are preserved
2066
+ * const diffuse = useTexture('/diffuse.png')
2597
2067
  * diffuse.colorSpace = THREE.SRGBColorSpace
2598
2068
  *
2599
2069
  * // Another component gets the SAME texture with colorSpace already set
2600
- * const sameDiffuse = useTexture('/diffuse.png', { cache: true })
2070
+ * const sameDiffuse = useTexture('/diffuse.png')
2071
+ *
2072
+ * // Opt out of registry enrollment for a one-off texture
2073
+ * const scratch = useTexture('/scratch.png', { cache: false })
2601
2074
  *
2602
- * // Access cache directly
2075
+ * // Access the registry directly
2603
2076
  * const { get } = useTextures()
2604
2077
  * const cached = get('/diffuse.png')
2605
2078
  * ```
@@ -2616,63 +2089,80 @@ declare const Texture: ({ children, input, onLoad, cache, }: {
2616
2089
  cache?: boolean;
2617
2090
  }) => react_jsx_runtime.JSX.Element;
2618
2091
 
2619
- type TextureEntry = Texture$1 | {
2620
- value: Texture$1;
2621
- [key: string]: any;
2092
+ /** Accepted shapes for a registry read: a single key, a list of keys, or a name→key map. */
2093
+ type TextureInput = string | string[] | Record<string, string>;
2094
+ /** Result of a `get()` read, mirroring the input shape. */
2095
+ type TextureResult<Input extends TextureInput> = Input extends string ? Texture$1 | undefined : Input extends string[] ? (Texture$1 | undefined)[] : {
2096
+ [K in keyof Input]: Texture$1 | undefined;
2622
2097
  };
2098
+ /** Options for `dispose()`. */
2099
+ interface DisposeOptions {
2100
+ /** Dispose even if the texture still has active references (default false). */
2101
+ force?: boolean;
2102
+ }
2623
2103
  interface UseTexturesReturn {
2624
- /** Map of all textures currently in cache */
2625
- textures: Map<string, TextureEntry>;
2626
- /** Get a specific texture by key (usually URL) */
2627
- get: (key: string) => TextureEntry | undefined;
2628
- /** Check if a texture exists in cache */
2629
- has: (key: string) => boolean;
2630
- /** Add a texture to the cache */
2631
- add: (key: string, value: TextureEntry) => void;
2632
- /** Add multiple textures to the cache */
2633
- addMultiple: (items: Map<string, TextureEntry> | Record<string, TextureEntry>) => void;
2634
- /** Remove a texture from cache (does NOT dispose GPU resources) */
2635
- remove: (key: string) => void;
2636
- /** Remove multiple textures from cache */
2637
- removeMultiple: (keys: string[]) => void;
2638
- /** Dispose a texture's GPU resources and remove from cache */
2639
- dispose: (key: string) => void;
2640
- /** Dispose multiple textures */
2641
- disposeMultiple: (keys: string[]) => void;
2642
- /** Dispose ALL cached textures - use with caution */
2643
- disposeAll: () => void;
2104
+ /** The live registry Map (key → Texture). Treat as read-only. */
2105
+ readonly all: Map<string, Texture$1>;
2106
+ /** Read one texture, an array of textures, or a name→texture record (mirrors the input shape). */
2107
+ get<Input extends TextureInput>(input: Input): TextureResult<Input>;
2108
+ /** Check whether a key exists in the registry. */
2109
+ has(key: string): boolean;
2110
+ /**
2111
+ * Register a texture (or a record of textures) that has no URL — e.g. a render
2112
+ * target or procedural texture. URL-loaded textures are registered automatically
2113
+ * by `useTexture` (registry enrollment is on by default).
2114
+ */
2115
+ add(key: string, texture: Texture$1): void;
2116
+ add(record: Record<string, Texture$1>): void;
2117
+ /**
2118
+ * Dispose a texture's GPU resources and remove it from the registry.
2119
+ * Refcount-aware: if the key is still in use by a mounted `useTexture` consumer it is
2120
+ * skipped (with a warning) unless `{ force: true }` is passed.
2121
+ * @returns true if disposed, false if skipped.
2122
+ */
2123
+ dispose(key: string, options?: DisposeOptions): boolean;
2124
+ /** Dispose every texture in the registry and clear it. Use on scene teardown. */
2125
+ disposeAll(): void;
2644
2126
  }
2645
2127
  /**
2646
- * Hook for managing the global texture cache in R3F state.
2128
+ * Reactive Texture registry — load once with `useTexture`, reach the textures from anywhere.
2129
+ *
2130
+ * This is a registry of plain `Texture` objects (not TSL nodes), so the same texture can feed
2131
+ * a material map, a heightmap sampler, or anything else. It does **not** load — pair it with
2132
+ * `useTexture` for loading (registry enrollment is on by default); `useTextures` is for access and lifecycle.
2647
2133
  *
2648
- * Textures are stored in a Map with URL/path keys for efficient lookup.
2649
- * Useful for sharing texture references across materials and components.
2134
+ * The returned handle is **reactive**: the calling component re-renders when the registry
2135
+ * changes. Pass a selector to scope the subscription to a single read.
2650
2136
  *
2651
2137
  * @example
2652
2138
  * ```tsx
2653
- * const { textures, add, get, remove, has, dispose } = useTextures()
2139
+ * // Load + register once (anywhere in the tree) — registered by default
2140
+ * useTexture({ map: '/diffuse.jpg', normalMap: '/normal.jpg' })
2654
2141
  *
2655
- * // Check if texture is already cached
2656
- * if (!has('/textures/diffuse.png')) {
2657
- * // Load with useTexture and cache: true, or manually add
2658
- * const tex = useTexture('/textures/diffuse.png', { cache: true })
2659
- * }
2660
- *
2661
- * // Access cached texture from anywhere
2662
- * const diffuse = get('/textures/diffuse.png')
2663
- * if (diffuse) material.map = diffuse
2142
+ * // Reach them from another component — record form lands straight into a material
2143
+ * const { map, normalMap } = useTextures().get({ map: '/diffuse.jpg', normalMap: '/normal.jpg' })
2144
+ * return <meshStandardMaterial map={map} normalMap={normalMap} />
2664
2145
  *
2665
- * // Remove from cache only (texture still in GPU memory)
2666
- * remove('/textures/old.png')
2146
+ * // A set of heightmaps at once
2147
+ * const [a, b, c] = useTextures().get(['/h0.png', '/h1.png', '/h2.png'])
2667
2148
  *
2668
- * // Fully dispose (frees GPU memory + removes from cache)
2669
- * dispose('/textures/unused.png')
2149
+ * // Register a non-URL texture (render target / procedural)
2150
+ * useTextures().add('rt-main', renderTarget.texture)
2670
2151
  *
2671
- * // Nuclear option - dispose everything
2672
- * disposeAll()
2152
+ * // Deliberate GPU cleanup (refcount-aware; force to override)
2153
+ * useTextures().dispose('/diffuse.jpg')
2154
+ * useTextures().disposeAll() // scene teardown
2673
2155
  * ```
2156
+ *
2157
+ * @remarks
2158
+ * **Future expansion:** an imperative async loader (e.g. `await useTextures().load('/x.jpg')`) is
2159
+ * intentionally not included yet. It would let non-React code (loading screens, dynamic streaming)
2160
+ * populate the registry without Suspense, at the cost of putting loading back into this hook. It
2161
+ * will be added only if a concrete consumer needs imperative loading; for now, loading lives in
2162
+ * `useTexture`.
2674
2163
  */
2675
2164
  declare function useTextures(): UseTexturesReturn;
2165
+ declare function useTextures<T>(selector: (registry: UseTexturesReturn) => T): T;
2676
2166
 
2677
2167
  /**
2678
2168
  * Creates a render target compatible with the current renderer.
@@ -2711,11 +2201,6 @@ declare function useRenderTarget(width: number, height: number, options?: Render
2711
2201
  * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
2712
2202
  */
2713
2203
  declare function useStore(): RootStore;
2714
- /**
2715
- * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
2716
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
2717
- */
2718
- declare function useThree<T = RootState>(selector?: (state: RootState) => T, equalityFn?: <T>(state: T, newState: T) => boolean): T;
2719
2204
  /**
2720
2205
  * Exposes an object's {@link Instance}.
2721
2206
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
@@ -2791,7 +2276,10 @@ declare function addTail(callback: GlobalRenderCallback): () => void;
2791
2276
  * Invalidates the view, requesting a frame to be rendered.
2792
2277
  * In demand mode, this triggers the scheduler to run frames.
2793
2278
  *
2794
- * @param state - Optional root state (ignored in new scheduler, kept for backwards compat)
2279
+ * With a state argument, only that root's jobs run on the requested frames; other
2280
+ * roots on 'demand' stay idle. Without one, every registered root is invalidated.
2281
+ *
2282
+ * @param state - Optional root state; targets the invalidation at that root
2795
2283
  * @param frames - Number of frames to request (default: 1)
2796
2284
  * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
2797
2285
  *
@@ -2802,14 +2290,16 @@ declare function invalidate(state?: RootState, frames?: number, stackFrames?: bo
2802
2290
  * Advances the frameloop and runs render effects.
2803
2291
  * Useful for when manually rendering via `frameloop="never"`.
2804
2292
  *
2293
+ * With a state argument, only that root is stepped. Without one, every
2294
+ * registered root is stepped for backwards compatibility.
2295
+ *
2805
2296
  * @param timestamp - The timestamp to use for this frame
2806
2297
  * @param runGlobalEffects - Ignored (kept for backwards compat, global effects always run)
2807
- * @param state - Ignored (kept for backwards compat)
2808
- * @param frame - Ignored (kept for backwards compat)
2298
+ * @param state - Optional root state; targets the manual step at that root
2809
2299
  *
2810
2300
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2811
2301
  */
2812
- declare function advance(timestamp: number): void;
2302
+ declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState): void;
2813
2303
 
2814
2304
  /* eslint-disable @definitelytyped/no-unnecessary-generics */
2815
2305
  declare function ReactReconciler<
@@ -3880,11 +3370,6 @@ declare function flushSync<R>(fn: () => R): R;
3880
3370
  declare const context: React$1.Context<RootStore>;
3881
3371
  declare const createStore: (invalidate: (state?: RootState, frames?: number, stackFrames?: boolean) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState, frame?: XRFrame) => void) => RootStore;
3882
3372
 
3883
- /**
3884
- * Safely flush async effects when testing, simulating a legacy root.
3885
- * @deprecated Import from React instead. import { act } from 'react'
3886
- */
3887
- declare const act: typeof React$1.act;
3888
3373
  /**
3889
3374
  * An SSR-friendly useLayoutEffect.
3890
3375
  *
@@ -4452,9 +3937,12 @@ declare function useUniforms<T extends UniformInputRecord>(uniforms: T): Uniform
4452
3937
  declare function useUniforms<T extends UniformInputRecord>(uniforms: T, scope: string): UniformsWithUtils<UniformRecord<UniformNode>>;
4453
3938
  /**
4454
3939
  * Global rebuildUniforms function for HMR integration.
4455
- * Clears cached uniforms and increments _hmrVersion to trigger re-creation.
3940
+ * Invalidates cached uniforms and increments _hmrVersion to trigger re-creation.
4456
3941
  * Call this when HMR is detected to refresh all uniform creators.
4457
3942
  *
3943
+ * Resolves to the primary store so shared TSL resources rebuild on the
3944
+ * authoritative store.
3945
+ *
4458
3946
  * @param store - The R3F store (from useStore or context)
4459
3947
  * @param scope - Optional scope to rebuild ('root' for root only, string for specific scope, undefined for all)
4460
3948
  */
@@ -4495,25 +3983,13 @@ declare function useUniform<T extends UniformValue>(name: string): UniformNode<T
4495
3983
  declare function useUniform<T extends UniformValue>(name: string, value: T): UniformNode<Widen<T>>;
4496
3984
 
4497
3985
  /**
4498
- * Minimal interface for TSL nodes.
4499
- * Used instead of Three.js's Node type because the @types/three definitions
4500
- * have inconsistencies where OperatorNode, ConstNode, etc. don't properly
4501
- * extend Node with all required properties.
3986
+ * Minimal interface for TSL nodes. The definition lives with the store types as `NodeLike`, so
3987
+ * the shape creators may return and the shape `state.nodes` holds are the same type by
3988
+ * construction. See `NodeLike` for why this is structural rather than three's `Node`.
4502
3989
  */
4503
- interface TSLNodeLike {
4504
- uuid?: string;
4505
- nodeType?: string | null;
4506
- /** label method for chaining - sets the node's label and returns self */
4507
- label?: ((label: string) => TSLNodeLike) | string;
4508
- setName?: (name: string) => this;
4509
- }
3990
+ type TSLNodeLike = NodeLike;
4510
3991
  /** TSL node type - alias for compatibility */
4511
3992
  type TSLNode = TSLNodeLike;
4512
- /**
4513
- * A record of TSL nodes - allows mixed node types (OperatorNode, ConstNode, etc.)
4514
- * Uses TSLNodeLike for broader compatibility with Three.js's TSL type definitions.
4515
- */
4516
- type NodeRecord<T extends TSLNodeLike = TSLNodeLike> = Record<string, T>;
4517
3993
  /**
4518
3994
  * Creator function that returns a record of nodes.
4519
3995
  * Uses TSLNodeLike constraint to allow mixed node types
@@ -4538,9 +4014,12 @@ declare function useNodes<T extends Record<string, TSLNodeLike>>(creator: NodeCr
4538
4014
  declare function useNodes<T extends Record<string, TSLNodeLike>>(creator: NodeCreator<T>, scope: string): NodesWithUtils<T>;
4539
4015
  /**
4540
4016
  * Global rebuildNodes function for HMR integration.
4541
- * Clears cached nodes and increments _hmrVersion to trigger re-creation.
4017
+ * Invalidates cached nodes and increments _hmrVersion to trigger re-creation.
4542
4018
  * Call this when HMR is detected to refresh all node creators.
4543
4019
  *
4020
+ * Resolves to the primary store so shared TSL resources rebuild on the
4021
+ * authoritative store.
4022
+ *
4544
4023
  * @param store - The R3F store (from useStore or context)
4545
4024
  * @param scope - Optional scope to rebuild ('root' for root only, string for specific scope, undefined for all)
4546
4025
  */
@@ -4617,9 +4096,12 @@ declare function useBuffers<T extends Record<string, BufferLike>>(creator: Buffe
4617
4096
  declare function useBuffers<T extends Record<string, BufferLike>>(creator: BufferCreator<T>, scope: string): BuffersWithUtils<T>;
4618
4097
  /**
4619
4098
  * Global rebuildBuffers function for HMR integration.
4620
- * Clears cached buffers and increments _hmrVersion to trigger re-creation.
4099
+ * Invalidates cached buffers and increments _hmrVersion to trigger re-creation.
4621
4100
  * Call this when HMR is detected to refresh all buffer creators.
4622
4101
  *
4102
+ * Resolves to the primary store so shared TSL resources rebuild on the
4103
+ * authoritative store.
4104
+ *
4623
4105
  * @param store - The R3F store (from useStore or context)
4624
4106
  * @param scope - Optional scope to rebuild ('root' for root only, string for specific scope, undefined for all)
4625
4107
  */
@@ -4651,14 +4133,34 @@ declare function useGPUStorage<T extends Record<string, StorageLike>>(creator: S
4651
4133
  declare function useGPUStorage<T extends Record<string, StorageLike>>(creator: StorageCreator<T>, scope: string): StorageWithUtils<T>;
4652
4134
  /**
4653
4135
  * Global rebuildStorage function for HMR integration.
4654
- * Clears cached storage and increments _hmrVersion to trigger re-creation.
4136
+ * Invalidates cached storage and increments _hmrVersion to trigger re-creation.
4655
4137
  * Call this when HMR is detected to refresh all storage creators.
4656
4138
  *
4139
+ * Resolves to the primary store so shared TSL resources rebuild on the
4140
+ * authoritative store.
4141
+ *
4657
4142
  * @param store - The R3F store (from useStore or context)
4658
4143
  * @param scope - Optional scope to rebuild ('root' for root only, string for specific scope, undefined for all)
4659
4144
  */
4660
4145
  declare function rebuildAllStorage(store: ReturnType<typeof useStore>, scope?: string): void;
4661
4146
 
4147
+ /**
4148
+ * Re-export from core - useTextures is now a core R3F hook (a reactive Texture registry).
4149
+ *
4150
+ * This file maintains backwards compatibility for existing webgpu imports.
4151
+ */
4152
+
4153
+ /**
4154
+ * @deprecated The registry now stores plain `Texture` objects, not TSL nodes. Use `Texture` directly.
4155
+ * Kept as an alias for backwards compatibility.
4156
+ */
4157
+ type TextureEntry = Texture$1;
4158
+ /**
4159
+ * @deprecated The registry now stores plain `Texture` objects, not TSL nodes. Use `Texture` directly.
4160
+ * Kept as an alias for backwards compatibility.
4161
+ */
4162
+ type TextureNode = Texture$1;
4163
+
4662
4164
  interface TextureOperations {
4663
4165
  add: (key: string, value: any) => void;
4664
4166
  addMultiple: (items: Map<string, any> | Record<string, any>) => void;
@@ -4676,6 +4178,10 @@ declare function createTextureOperations(set: StoreApi<RootState>['setState']):
4676
4178
  * - Callbacks receive full RootState for flexibility
4677
4179
  * - No auto-cleanup on unmount - use reset() for explicit cleanup
4678
4180
  * - Scene/camera changes trigger scenePass recreation
4181
+ * - A replaced scenePass is disposed once the new graph is installed, so rebuild() does not
4182
+ * strand its render target (and MRT attachments) on the GPU
4183
+ * - Any run that changes the output node sets RenderPipeline.needsUpdate, so rebuild() actually
4184
+ * recompiles instead of silently keeping the first compiled graph
4679
4185
  *
4680
4186
  * @param mainCB - Main callback to configure outputNode and create effect passes
4681
4187
  * @param setupCB - Optional setup callback to configure MRT on scenePass
@@ -4753,5 +4259,23 @@ interface WebGPURootState extends Omit<RootState, 'renderer' | 'gl' | 'internal'
4753
4259
  internal: WebGPUInternalState
4754
4260
  }
4755
4261
 
4756
- export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, three_d as ReactThreeFiber, Scheduler, Texture, _roots, act, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, clearNodeScope, clearRootNodes, clearRootUniforms, clearScope, context, createEvents, createPointerEvents, createPortal, createRoot, createScopedStore, createStore, createTextureOperations, detach, diffProps, dispose, createPointerEvents as events, extend, findInitialRoot, flushSync, fromRef, getInstanceProps, getPrimary, getPrimaryIds, getRootState, getScheduler, getUuidPrefix, hasConstructor, hasPrimary, invalidate, invalidateInstance, is, isColorRepresentation, isCopyable, isFromRef, isObject3D, isOnce, isOrthographicCamera, isRef, isRenderer, isTexture, isVectorLike, once, prepare, presetsObj, rebuildAllBuffers, rebuildAllNodes, rebuildAllStorage, rebuildAllUniforms, reconciler, registerPrimary, removeInteractivity, removeNodes, removeUniforms, resolve, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useBuffers, useEnvironment, useFrame, useGPUStorage, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useLocalNodes, useMutableCallback, useNodes, useRenderPipeline, useRenderTarget, useStore, useTexture, useTextures, useThree, useUniform, useUniforms, waitForPrimary };
4757
- export type { Act, AddPhaseOptions, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferCreator, BufferLike, BufferRecord, BufferStore, BuffersWithUtils, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, ClearBuffersFn, ClearNodesFn, ClearStorageFn, ClearUniformsFn, Color, ComputeFunction, ConstructorRepresentation, CreatorState, DefaultGLProps, DefaultRendererProps, Disposable, DisposeBuffersFn, DisposeStorageFn, DomEvent, Dpr, ElementProps, EnvironmentLoaderProps, EnvironmentProps, EquConfig, Euler, EventHandlers, EventManager, EventProps, Events, Extensions, FiberRoot, FilterFunction, FrameCallback, FrameControls, FrameNextCallback, FrameNextControls, FrameNextState, FrameState, FrameTimingState, Frameloop, GLProps, GLTFLike, GeometryProps, GeometryTransformProps, GlobalEffectType, GlobalRenderCallback, HostConfig, InferLoadResult, InjectState, InputLike, Instance, InstanceProps, WebGPUInternalState as InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, LocalNodeCreator, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeCreator, NodeProps, NodeRecord, NodesWithUtils, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, WebGPUR3FRenderer as R3FRenderer, RaycastableRepresentation, ReactProps, RebuildBuffersFn, RebuildNodesFn, RebuildStorageFn, RebuildUniformsFn, ReconcilerRoot, RemoveBuffersFn, RemoveNodesFn, RemoveStorageFn, RemoveUniformsFn, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, RootOptions, WebGPURootState as RootState, RootStore, SchedulerApi, ScopedStoreType, SetBlock, Size, StorageCreator, StorageLike, StorageRecord, StorageStore, StorageWithUtils, Subscription, TSLNode, TSLNodeInput, TextureEntry, TextureOperations, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UniformCreator, UniformValue, UniformsWithUtils, UseFrameNextOptions, UseFrameOptions, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, WebGPUDefaultProps, WebGPUProps, WebGPUShadowConfig, XRManager, XRPointerConfig };
4262
+ /**
4263
+ * @fileoverview WebGPU entry point - WebGPU only, no legacy WebGL
4264
+ *
4265
+ * This entry point is for apps that want to use ONLY WebGPURenderer.
4266
+ * Includes WebGPU-specific hooks (useUniforms, useNodes, useTextures).
4267
+ * Auto-extends THREE with WebGPU node materials (MeshBasicNodeMaterial, etc.)
4268
+ *
4269
+ * Usage:
4270
+ * import { Canvas, useFrame, useUniforms } from '@react-three/fiber/webgpu'
4271
+ */
4272
+
4273
+ /** `useThree` narrowed to WebGPU state — `state.renderer` is a `WebGPURenderer`. */
4274
+ type UseThreeWebGPU = <T = WebGPURootState>(selector?: (state: WebGPURootState) => T, equalityFn?: <U>(state: U, newState: U) => boolean) => T;
4275
+ /** `useFrame` narrowed to WebGPU state — the callback's `state.renderer` is a `WebGPURenderer`. */
4276
+ type UseFrameWebGPU = (callback?: FrameCallback$1<WebGPURootState>, priorityOrOptions?: number | UseFrameNextOptions) => FrameNextControls;
4277
+ declare const useThree: UseThreeWebGPU;
4278
+ declare const useFrame: UseFrameWebGPU;
4279
+
4280
+ export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, three_d as ReactThreeFiber, Texture, _roots, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, clearNodeScope, clearRootNodes, clearRootUniforms, clearScope, context, createEvents, createPointerEvents, createPortal, createRoot, createScopedStore, createStore, createTextureOperations, detach, diffProps, dispose, createPointerEvents as events, extend, findInitialRoot, flushSync, fromRef, getInstanceProps, getPrimary, getPrimaryIds, getRootState, getUuidPrefix, hasConstructor, hasPrimary, invalidate, invalidateInstance, is, isColorRepresentation, isCopyable, isFromRef, isObject3D, isOnce, isOrthographicCamera, isRef, isRenderer, isTexture, isVectorLike, once, prepare, presetsObj, rebuildAllBuffers, rebuildAllNodes, rebuildAllStorage, rebuildAllUniforms, reconciler, registerPrimary, removeInteractivity, removeNodes, removeUniforms, resolve, swapInteractivity, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useBuffers, useEnvironment, useFrame, useGPUStorage, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useLocalNodes, useMutableCallback, useNodes, useRenderPipeline, useRenderTarget, useStore, useTexture, useTextures, useThree, useUniform, useUniforms, waitForPrimary };
4281
+ export type { Act, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferCreator, BufferLike, BufferRecord, BufferStore, BuffersWithUtils, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, ClearBuffersFn, ClearNodesFn, ClearStorageFn, ClearUniformsFn, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, CreatorState, DefaultGLProps, DefaultRendererProps, Disposable, DisposeBuffersFn, DisposeOptions, DisposeStorageFn, DomEvent, Dpr, ElementProps, EnvironmentLoaderProps, EnvironmentProps, EquConfig, Euler, EventHandlers, EventManager, EventProps, Events, Extensions, FiberRoot, FilterFunction, FrameCallback, FrameNextCallback, FrameNextState, FrameState, Frameloop, GLProps, GLTFLike, GeometryProps, GeometryTransformProps, GlobalEffectType, GlobalRenderCallback, HostConfig, InferLoadResult, InjectState, InputLike, Instance, InstanceProps, WebGPUInternalState as InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, LocalNodeCreator, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeCreator, NodeLike, NodeProps, NodeStore, NodesWithUtils, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, WebGPUR3FRenderer as R3FRenderer, RaycastableRepresentation, ReactProps, RebuildBuffersFn, RebuildNodesFn, RebuildStorageFn, RebuildUniformsFn, ReconcilerRoot, RemoveBuffersFn, RemoveNodesFn, RemoveStorageFn, RemoveUniformsFn, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, WebGPURootState as RootState, RootStore, ScopedStoreType, SetBlock, Size, StorageCreator, StorageLike, StorageRecord, StorageStore, StorageWithUtils, Subscription, TSLNode, TSLNodeInput, TextureEntry, TextureInput, TextureNode, TextureOperations, TextureResult, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UniformCreator, UniformValue, UniformsWithUtils, UseFrameWebGPU, UseTextureOptions, UseTexturesReturn, UseThreeWebGPU, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, WebGPUDefaultProps, WebGPUProps, WebGPUShadowConfig, XRManager, XRPointerConfig };