@react-three/fiber 10.0.0-canary.ac30da2 → 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.
@@ -365,6 +365,33 @@ type BufferRecord = Record<string, BufferLike>
365
365
  */
366
366
  type BufferStore = Record<string, BufferLike | BufferRecord>
367
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
+
368
395
  //* Storage Types (useGPUStorage) ========================================
369
396
 
370
397
  /**
@@ -498,8 +525,13 @@ interface InternalState {
498
525
  /** Container for child attachment (scene for root, original container for portals) */
499
526
  container?: THREE$1.Object3D
500
527
  /**
501
- * CanvasTarget for multi-canvas WebGPU rendering.
502
- * 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.
503
535
  * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
504
536
  */
505
537
  canvasTarget?: CanvasTarget
@@ -624,7 +656,7 @@ interface RootState {
624
656
  /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
625
657
  uniforms: UniformStore
626
658
  /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
627
- nodes: Record<string, any>
659
+ nodes: NodeStore
628
660
  /** Global TSL buffer nodes - root-level buffers + scoped sub-objects. Use useBuffers() hook */
629
661
  buffers: BufferStore
630
662
  /** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
@@ -636,7 +668,7 @@ interface RootState {
636
668
  /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
637
669
  renderPipeline: ThreeRenderPipeline | null
638
670
  /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
639
- passes: Record<string, any>
671
+ passes: PassRecord
640
672
  /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
641
673
  _hmrVersion: number
642
674
  /** Internal: whether setSize() has taken ownership of canvas dimensions */
@@ -724,12 +756,19 @@ type DefaultRendererProps = {
724
756
  */
725
757
  interface CanvasSchedulerConfig {
726
758
  /**
727
- * Render this canvas after another canvas completes.
728
- * Pass the `id` of another canvas.
759
+ * Run this Canvas root before the referenced Canvas root id(s).
729
760
  */
730
- after?: string
761
+ before?: string | string[]
731
762
  /**
732
- * Limit this canvas's render rate (frames per second).
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.
768
+ */
769
+ order?: number
770
+ /**
771
+ * Limit this Canvas's default render job (frames per second).
733
772
  */
734
773
  fps?: number
735
774
  }
@@ -1177,7 +1216,33 @@ declare global {
1177
1216
  * ergonomics. The result is three's structural type, so members stay in sync with the
1178
1217
  * installed three instead of needing to be mirrored by hand.
1179
1218
  */
1180
- type UniformNode<T = unknown> = three_webgpu.UniformNode<unknown, T>
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
1181
1246
 
1182
1247
  /**
1183
1248
  * ShaderCallable - the return type of Fn()
@@ -1330,30 +1395,97 @@ declare global {
1330
1395
  */
1331
1396
  type ThreeRenderPipeline = three_webgpu.RenderPipeline
1332
1397
 
1333
- /** Pass record - stores TSL pass nodes for render pipeline */
1334
- type PassRecord = Record<string, any>
1398
+ /**
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.
1402
+ */
1403
+ type ScenePassNode = three_webgpu.PassNode
1404
+
1405
+ /**
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`.
1417
+ */
1418
+ interface PassRecord {
1419
+ scenePass?: ScenePassNode
1420
+ [key: string]: three_webgpu.Node
1421
+ }
1422
+
1423
+ /**
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.
1431
+ */
1432
+ type RenderPipelineCallbackState = RootState & {
1433
+ renderPipeline: ThreeRenderPipeline
1434
+ passes: PassRecord & { scenePass: ScenePassNode }
1435
+ renderer: three_webgpu.WebGPURenderer
1436
+ isLegacy: false
1437
+ }
1438
+
1439
+ /**
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.
1446
+ */
1447
+ type RegisteredPasses = Record<string, three_webgpu.Node> & { scenePass?: never }
1335
1448
 
1336
1449
  /** Setup callback - runs first to configure MRT, create additional passes */
1337
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1450
+ type RenderPipelineSetupCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1338
1451
 
1339
1452
  /** Main callback - runs second to configure outputNode, create effect passes */
1340
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1453
+ type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1341
1454
 
1342
- /** Return type for useRenderPipeline hook */
1343
- interface UseRenderPipelineReturn {
1455
+ /** The imperative half of useRenderPipeline's return value, present in every state */
1456
+ interface UseRenderPipelineActions {
1344
1457
  /** Current passes from state */
1345
1458
  passes: PassRecord
1346
- /** RenderPipeline instance (null if not initialized) */
1347
- renderPipeline: ThreeRenderPipeline | null
1348
1459
  /** Clear all passes from state */
1349
1460
  clearPasses: () => void
1350
1461
  /** Reset RenderPipeline entirely (clears PP + passes) */
1351
1462
  reset: () => void
1352
1463
  /** Re-run setup/main callbacks with current closure values */
1353
1464
  rebuild: () => void
1354
- /** True when RenderPipeline is configured and ready */
1355
- isReady: boolean
1356
1465
  }
1466
+
1467
+ /**
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.
1473
+ */
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
+ )
1357
1489
  }
1358
1490
 
1359
1491
  type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
@@ -2144,7 +2276,10 @@ declare function addTail(callback: GlobalRenderCallback): () => void;
2144
2276
  * Invalidates the view, requesting a frame to be rendered.
2145
2277
  * In demand mode, this triggers the scheduler to run frames.
2146
2278
  *
2147
- * @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
2148
2283
  * @param frames - Number of frames to request (default: 1)
2149
2284
  * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
2150
2285
  *
@@ -2155,14 +2290,16 @@ declare function invalidate(state?: RootState, frames?: number, stackFrames?: bo
2155
2290
  * Advances the frameloop and runs render effects.
2156
2291
  * Useful for when manually rendering via `frameloop="never"`.
2157
2292
  *
2293
+ * With a state argument, only that root is stepped. Without one, every
2294
+ * registered root is stepped for backwards compatibility.
2295
+ *
2158
2296
  * @param timestamp - The timestamp to use for this frame
2159
2297
  * @param runGlobalEffects - Ignored (kept for backwards compat, global effects always run)
2160
- * @param state - Ignored (kept for backwards compat)
2161
- * @param frame - Ignored (kept for backwards compat)
2298
+ * @param state - Optional root state; targets the manual step at that root
2162
2299
  *
2163
2300
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2164
2301
  */
2165
- declare function advance(timestamp: number): void;
2302
+ declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState): void;
2166
2303
 
2167
2304
  /* eslint-disable @definitelytyped/no-unnecessary-generics */
2168
2305
  declare function ReactReconciler<
@@ -3846,25 +3983,13 @@ declare function useUniform<T extends UniformValue>(name: string): UniformNode<T
3846
3983
  declare function useUniform<T extends UniformValue>(name: string, value: T): UniformNode<Widen<T>>;
3847
3984
 
3848
3985
  /**
3849
- * Minimal interface for TSL nodes.
3850
- * Used instead of Three.js's Node type because the @types/three definitions
3851
- * have inconsistencies where OperatorNode, ConstNode, etc. don't properly
3852
- * 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`.
3853
3989
  */
3854
- interface TSLNodeLike {
3855
- uuid?: string;
3856
- nodeType?: string | null;
3857
- /** label method for chaining - sets the node's label and returns self */
3858
- label?: ((label: string) => TSLNodeLike) | string;
3859
- setName?: (name: string) => this;
3860
- }
3990
+ type TSLNodeLike = NodeLike;
3861
3991
  /** TSL node type - alias for compatibility */
3862
3992
  type TSLNode = TSLNodeLike;
3863
- /**
3864
- * A record of TSL nodes - allows mixed node types (OperatorNode, ConstNode, etc.)
3865
- * Uses TSLNodeLike for broader compatibility with Three.js's TSL type definitions.
3866
- */
3867
- type NodeRecord<T extends TSLNodeLike = TSLNodeLike> = Record<string, T>;
3868
3993
  /**
3869
3994
  * Creator function that returns a record of nodes.
3870
3995
  * Uses TSLNodeLike constraint to allow mixed node types
@@ -4153,4 +4278,4 @@ declare const useThree: UseThreeWebGPU;
4153
4278
  declare const useFrame: UseFrameWebGPU;
4154
4279
 
4155
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 };
4156
- 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, 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, 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 };
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 };
@@ -365,6 +365,33 @@ type BufferRecord = Record<string, BufferLike>
365
365
  */
366
366
  type BufferStore = Record<string, BufferLike | BufferRecord>
367
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
+
368
395
  //* Storage Types (useGPUStorage) ========================================
369
396
 
370
397
  /**
@@ -498,8 +525,13 @@ interface InternalState {
498
525
  /** Container for child attachment (scene for root, original container for portals) */
499
526
  container?: THREE$1.Object3D
500
527
  /**
501
- * CanvasTarget for multi-canvas WebGPU rendering.
502
- * 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.
503
535
  * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
504
536
  */
505
537
  canvasTarget?: CanvasTarget
@@ -624,7 +656,7 @@ interface RootState {
624
656
  /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
625
657
  uniforms: UniformStore
626
658
  /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
627
- nodes: Record<string, any>
659
+ nodes: NodeStore
628
660
  /** Global TSL buffer nodes - root-level buffers + scoped sub-objects. Use useBuffers() hook */
629
661
  buffers: BufferStore
630
662
  /** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
@@ -636,7 +668,7 @@ interface RootState {
636
668
  /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
637
669
  renderPipeline: ThreeRenderPipeline | null
638
670
  /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
639
- passes: Record<string, any>
671
+ passes: PassRecord
640
672
  /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
641
673
  _hmrVersion: number
642
674
  /** Internal: whether setSize() has taken ownership of canvas dimensions */
@@ -724,12 +756,19 @@ type DefaultRendererProps = {
724
756
  */
725
757
  interface CanvasSchedulerConfig {
726
758
  /**
727
- * Render this canvas after another canvas completes.
728
- * Pass the `id` of another canvas.
759
+ * Run this Canvas root before the referenced Canvas root id(s).
729
760
  */
730
- after?: string
761
+ before?: string | string[]
731
762
  /**
732
- * Limit this canvas's render rate (frames per second).
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.
768
+ */
769
+ order?: number
770
+ /**
771
+ * Limit this Canvas's default render job (frames per second).
733
772
  */
734
773
  fps?: number
735
774
  }
@@ -1177,7 +1216,33 @@ declare global {
1177
1216
  * ergonomics. The result is three's structural type, so members stay in sync with the
1178
1217
  * installed three instead of needing to be mirrored by hand.
1179
1218
  */
1180
- type UniformNode<T = unknown> = three_webgpu.UniformNode<unknown, T>
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
1181
1246
 
1182
1247
  /**
1183
1248
  * ShaderCallable - the return type of Fn()
@@ -1330,30 +1395,97 @@ declare global {
1330
1395
  */
1331
1396
  type ThreeRenderPipeline = three_webgpu.RenderPipeline
1332
1397
 
1333
- /** Pass record - stores TSL pass nodes for render pipeline */
1334
- type PassRecord = Record<string, any>
1398
+ /**
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.
1402
+ */
1403
+ type ScenePassNode = three_webgpu.PassNode
1404
+
1405
+ /**
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`.
1417
+ */
1418
+ interface PassRecord {
1419
+ scenePass?: ScenePassNode
1420
+ [key: string]: three_webgpu.Node
1421
+ }
1422
+
1423
+ /**
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.
1431
+ */
1432
+ type RenderPipelineCallbackState = RootState & {
1433
+ renderPipeline: ThreeRenderPipeline
1434
+ passes: PassRecord & { scenePass: ScenePassNode }
1435
+ renderer: three_webgpu.WebGPURenderer
1436
+ isLegacy: false
1437
+ }
1438
+
1439
+ /**
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.
1446
+ */
1447
+ type RegisteredPasses = Record<string, three_webgpu.Node> & { scenePass?: never }
1335
1448
 
1336
1449
  /** Setup callback - runs first to configure MRT, create additional passes */
1337
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1450
+ type RenderPipelineSetupCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1338
1451
 
1339
1452
  /** Main callback - runs second to configure outputNode, create effect passes */
1340
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1453
+ type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1341
1454
 
1342
- /** Return type for useRenderPipeline hook */
1343
- interface UseRenderPipelineReturn {
1455
+ /** The imperative half of useRenderPipeline's return value, present in every state */
1456
+ interface UseRenderPipelineActions {
1344
1457
  /** Current passes from state */
1345
1458
  passes: PassRecord
1346
- /** RenderPipeline instance (null if not initialized) */
1347
- renderPipeline: ThreeRenderPipeline | null
1348
1459
  /** Clear all passes from state */
1349
1460
  clearPasses: () => void
1350
1461
  /** Reset RenderPipeline entirely (clears PP + passes) */
1351
1462
  reset: () => void
1352
1463
  /** Re-run setup/main callbacks with current closure values */
1353
1464
  rebuild: () => void
1354
- /** True when RenderPipeline is configured and ready */
1355
- isReady: boolean
1356
1465
  }
1466
+
1467
+ /**
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.
1473
+ */
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
+ )
1357
1489
  }
1358
1490
 
1359
1491
  type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
@@ -2144,7 +2276,10 @@ declare function addTail(callback: GlobalRenderCallback): () => void;
2144
2276
  * Invalidates the view, requesting a frame to be rendered.
2145
2277
  * In demand mode, this triggers the scheduler to run frames.
2146
2278
  *
2147
- * @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
2148
2283
  * @param frames - Number of frames to request (default: 1)
2149
2284
  * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
2150
2285
  *
@@ -2155,14 +2290,16 @@ declare function invalidate(state?: RootState, frames?: number, stackFrames?: bo
2155
2290
  * Advances the frameloop and runs render effects.
2156
2291
  * Useful for when manually rendering via `frameloop="never"`.
2157
2292
  *
2293
+ * With a state argument, only that root is stepped. Without one, every
2294
+ * registered root is stepped for backwards compatibility.
2295
+ *
2158
2296
  * @param timestamp - The timestamp to use for this frame
2159
2297
  * @param runGlobalEffects - Ignored (kept for backwards compat, global effects always run)
2160
- * @param state - Ignored (kept for backwards compat)
2161
- * @param frame - Ignored (kept for backwards compat)
2298
+ * @param state - Optional root state; targets the manual step at that root
2162
2299
  *
2163
2300
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2164
2301
  */
2165
- declare function advance(timestamp: number): void;
2302
+ declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState): void;
2166
2303
 
2167
2304
  /* eslint-disable @definitelytyped/no-unnecessary-generics */
2168
2305
  declare function ReactReconciler<
@@ -3846,25 +3983,13 @@ declare function useUniform<T extends UniformValue>(name: string): UniformNode<T
3846
3983
  declare function useUniform<T extends UniformValue>(name: string, value: T): UniformNode<Widen<T>>;
3847
3984
 
3848
3985
  /**
3849
- * Minimal interface for TSL nodes.
3850
- * Used instead of Three.js's Node type because the @types/three definitions
3851
- * have inconsistencies where OperatorNode, ConstNode, etc. don't properly
3852
- * 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`.
3853
3989
  */
3854
- interface TSLNodeLike {
3855
- uuid?: string;
3856
- nodeType?: string | null;
3857
- /** label method for chaining - sets the node's label and returns self */
3858
- label?: ((label: string) => TSLNodeLike) | string;
3859
- setName?: (name: string) => this;
3860
- }
3990
+ type TSLNodeLike = NodeLike;
3861
3991
  /** TSL node type - alias for compatibility */
3862
3992
  type TSLNode = TSLNodeLike;
3863
- /**
3864
- * A record of TSL nodes - allows mixed node types (OperatorNode, ConstNode, etc.)
3865
- * Uses TSLNodeLike for broader compatibility with Three.js's TSL type definitions.
3866
- */
3867
- type NodeRecord<T extends TSLNodeLike = TSLNodeLike> = Record<string, T>;
3868
3993
  /**
3869
3994
  * Creator function that returns a record of nodes.
3870
3995
  * Uses TSLNodeLike constraint to allow mixed node types
@@ -4153,4 +4278,4 @@ declare const useThree: UseThreeWebGPU;
4153
4278
  declare const useFrame: UseFrameWebGPU;
4154
4279
 
4155
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 };
4156
- 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, 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, 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 };
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 };