@react-three/fiber 10.0.0-canary.ba354c7 → 10.0.0-canary.c385e9f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/legacy.d.mts CHANGED
@@ -38,9 +38,9 @@ function _mergeNamespaces(n, m) {
38
38
  declare const R3F_BUILD_LEGACY = true;
39
39
  declare const R3F_BUILD_WEBGPU = false;
40
40
 
41
- declare const Inspector: {
42
- new (): {};
43
- };
41
+ type Inspector = never;
42
+ /** Not available on the legacy (WebGL-only) entry. */
43
+ declare function loadInspector(): Promise<never>;
44
44
  declare const WebGPURenderer: {
45
45
  new (): {};
46
46
  };
@@ -58,7 +58,8 @@ var THREE = /*#__PURE__*/_mergeNamespaces({
58
58
  R3F_BUILD_WEBGPU: R3F_BUILD_WEBGPU,
59
59
  RenderTarget: RenderTarget,
60
60
  RenderTargetCompat: WebGLRenderTarget,
61
- WebGPURenderer: WebGPURenderer
61
+ WebGPURenderer: WebGPURenderer,
62
+ loadInspector: loadInspector
62
63
  }, [THREE$1]);
63
64
 
64
65
  //* Utility Types ==============================
@@ -358,6 +359,33 @@ type BufferRecord = Record<string, BufferLike>
358
359
  */
359
360
  type BufferStore = Record<string, BufferLike | BufferRecord>
360
361
 
362
+ //* Node Types (useNodes) ========================================
363
+
364
+ /**
365
+ * Structural shape of a TSL node as stored on `state.nodes`.
366
+ *
367
+ * Deliberately minimal rather than three's nominal `Node`: in @types/three several node classes
368
+ * TSL hands back (OperatorNode, ConstNode, ...) do not extend `Node` cleanly, so a `Node` bound
369
+ * would reject values `useNodes` creators legitimately return. This is the same shape
370
+ * `useNodes` already constrains creators to (`TSLNodeLike`).
371
+ */
372
+ interface NodeLike {
373
+ uuid?: string
374
+ nodeType?: string | null
375
+ /** label method for chaining - sets the node's label and returns self */
376
+ label?: ((label: string) => NodeLike) | string
377
+ setName?: (name: string) => this
378
+ }
379
+
380
+ /** Flat record of TSL nodes (no nested scopes) */
381
+ type NodeRecord = Record<string, NodeLike>
382
+
383
+ /**
384
+ * Node store that can contain both root-level nodes and scoped node objects.
385
+ * Structure: { wobble: OperatorNode, fx: { blur: ShaderCallable } }
386
+ */
387
+ type NodeStore = Record<string, NodeLike | NodeRecord>
388
+
361
389
  //* Storage Types (useGPUStorage) ========================================
362
390
 
363
391
  /**
@@ -496,6 +524,18 @@ interface InternalState {
496
524
  * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
497
525
  */
498
526
  canvasTarget?: CanvasTarget
527
+ /**
528
+ * Set when this root's canvas target has been resized and the backend's cached render pass
529
+ * descriptor (which holds a depth-stencil view built once per canvas) is therefore stale.
530
+ *
531
+ * Flushed by the canvas-target job in the `start` phase, which is the only place this root's
532
+ * target is guaranteed to be the renderer's active one — `backend.updateSize()` operates on
533
+ * whatever `getCanvasTarget()` returns, so calling it from the resize subscription would
534
+ * invalidate some other canvas's descriptor instead.
535
+ *
536
+ * @see https://github.com/pmndrs/react-three-fiber/issues/3847
537
+ */
538
+ canvasTargetSizeDirty?: boolean
499
539
  /**
500
540
  * Whether multi-canvas rendering is active.
501
541
  * True when any canvas uses `renderer={{ primaryCanvas: 'id' }}` to share a renderer.
@@ -605,7 +645,7 @@ interface RootState {
605
645
  /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
606
646
  uniforms: UniformStore
607
647
  /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
608
- nodes: Record<string, any>
648
+ nodes: NodeStore
609
649
  /** Global TSL buffer nodes - root-level buffers + scoped sub-objects. Use useBuffers() hook */
610
650
  buffers: BufferStore
611
651
  /** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
@@ -617,7 +657,7 @@ interface RootState {
617
657
  /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
618
658
  renderPipeline: ThreeRenderPipeline | null
619
659
  /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
620
- passes: Record<string, any>
660
+ passes: PassRecord
621
661
  /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
622
662
  _hmrVersion: number
623
663
  /** Internal: whether setSize() has taken ownership of canvas dimensions */
@@ -705,12 +745,19 @@ type DefaultRendererProps = {
705
745
  */
706
746
  interface CanvasSchedulerConfig {
707
747
  /**
708
- * Render this canvas after another canvas completes.
709
- * Pass the `id` of another canvas.
748
+ * Run this Canvas root before the referenced Canvas root id(s).
749
+ */
750
+ before?: string | string[]
751
+ /**
752
+ * Run this Canvas root after the referenced Canvas root id(s).
710
753
  */
711
- after?: string
754
+ after?: string | string[]
712
755
  /**
713
- * Limit this canvas's render rate (frames per second).
756
+ * Numeric root order. Lower values run first.
757
+ */
758
+ order?: number
759
+ /**
760
+ * Limit this Canvas's default render job (frames per second).
714
761
  */
715
762
  fps?: number
716
763
  }
@@ -1158,7 +1205,33 @@ declare global {
1158
1205
  * ergonomics. The result is three's structural type, so members stay in sync with the
1159
1206
  * installed three instead of needing to be mirrored by hand.
1160
1207
  */
1161
- type UniformNode<T = unknown> = three_webgpu.UniformNode<unknown, T>
1208
+ type UniformNode<T = unknown> = three_webgpu.UniformNode<UniformNodeTypeFor<T>, T>
1209
+
1210
+ /**
1211
+ * three's node type name for a uniform value type, mirroring the `uniform()` overloads.
1212
+ * A `UniformNode<number>` is a `Node<'float'>`, so TSL math (`.mul`, `.add`, ...) accepts it.
1213
+ * Unknown or unlisted value types resolve to `unknown`, which TSL math rejects: narrow with
1214
+ * `as UniformNode<number>` (or the matching value type) at the call site.
1215
+ */
1216
+ type UniformNodeTypeFor<T> = T extends number
1217
+ ? 'float'
1218
+ : T extends boolean
1219
+ ? 'bool'
1220
+ : T extends three_webgpu.Color
1221
+ ? 'color'
1222
+ : T extends three_webgpu.Vector2
1223
+ ? 'vec2'
1224
+ : T extends three_webgpu.Vector3
1225
+ ? 'vec3'
1226
+ : T extends three_webgpu.Vector4
1227
+ ? 'vec4'
1228
+ : T extends three_webgpu.Matrix2
1229
+ ? 'mat2'
1230
+ : T extends three_webgpu.Matrix3
1231
+ ? 'mat3'
1232
+ : T extends three_webgpu.Matrix4
1233
+ ? 'mat4'
1234
+ : unknown
1162
1235
 
1163
1236
  /**
1164
1237
  * ShaderCallable - the return type of Fn()
@@ -1311,30 +1384,97 @@ declare global {
1311
1384
  */
1312
1385
  type ThreeRenderPipeline = three_webgpu.RenderPipeline
1313
1386
 
1314
- /** Pass record - stores TSL pass nodes for render pipeline */
1315
- type PassRecord = Record<string, any>
1387
+ /**
1388
+ * The pass `useRenderPipeline` creates for you: three's own `PassNode`, as returned by
1389
+ * `pass(scene, camera)` from `three/tsl`. Referenced from three so members like
1390
+ * `getTextureNode`, `setMRT` and `dispose` track the installed version.
1391
+ */
1392
+ type ScenePassNode = three_webgpu.PassNode
1393
+
1394
+ /**
1395
+ * Pass record - stores TSL pass nodes for render pipeline.
1396
+ *
1397
+ * `scenePass` is the only key the library owns. It is optional here because this is also the
1398
+ * shape of `state.passes`, which is `{}` before the pipeline exists and again after `reset()`
1399
+ * or `clearPasses()`. Inside the callbacks it is always present; see
1400
+ * {@link RenderPipelineCallbackState}.
1401
+ *
1402
+ * Every other key is user-registered, via a callback's return value. Those are TSL nodes of
1403
+ * any kind, not only passes: texture reads of an MRT attachment, effect nodes, extra
1404
+ * `pass()` instances. `Node` is the common base, so that is the bound. Narrow at the call
1405
+ * site when you need a member, e.g. `passes.velocity as TextureNode`.
1406
+ */
1407
+ interface PassRecord {
1408
+ scenePass?: ScenePassNode
1409
+ [key: string]: three_webgpu.Node
1410
+ }
1411
+
1412
+ /**
1413
+ * State passed to pipeline callbacks after the active pipeline has been created.
1414
+ *
1415
+ * `passes.scenePass` is required here: the hook installs the default scene pass before either
1416
+ * callback runs, so callbacks can use it without a guard or a cast.
1417
+ *
1418
+ * `renderer` is narrowed to `WebGPURenderer` and `isLegacy` to `false`: the hook throws under
1419
+ * the legacy renderer before either callback can run, so a callback never sees WebGL.
1420
+ */
1421
+ type RenderPipelineCallbackState = RootState & {
1422
+ renderPipeline: ThreeRenderPipeline
1423
+ passes: PassRecord & { scenePass: ScenePassNode }
1424
+ renderer: three_webgpu.WebGPURenderer
1425
+ isLegacy: false
1426
+ }
1427
+
1428
+ /**
1429
+ * What a callback may return to register entries into `state.passes`.
1430
+ *
1431
+ * `scenePass` is reserved. The hook owns that entry and its lifecycle: it caches the pass it
1432
+ * created, and `rebuild()` / `reset()` dispose that cached pass. A callback overwriting the
1433
+ * store entry would leave the store pointing at a node the hook never disposes, and the hook
1434
+ * disposing a pass nothing references. So returning it is a type error.
1435
+ */
1436
+ type RegisteredPasses = Record<string, three_webgpu.Node> & { scenePass?: never }
1316
1437
 
1317
1438
  /** Setup callback - runs first to configure MRT, create additional passes */
1318
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1439
+ type RenderPipelineSetupCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1319
1440
 
1320
1441
  /** Main callback - runs second to configure outputNode, create effect passes */
1321
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1442
+ type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1322
1443
 
1323
- /** Return type for useRenderPipeline hook */
1324
- interface UseRenderPipelineReturn {
1444
+ /** The imperative half of useRenderPipeline's return value, present in every state */
1445
+ interface UseRenderPipelineActions {
1325
1446
  /** Current passes from state */
1326
1447
  passes: PassRecord
1327
- /** RenderPipeline instance (null if not initialized) */
1328
- renderPipeline: ThreeRenderPipeline | null
1329
1448
  /** Clear all passes from state */
1330
1449
  clearPasses: () => void
1331
1450
  /** Reset RenderPipeline entirely (clears PP + passes) */
1332
1451
  reset: () => void
1333
1452
  /** Re-run setup/main callbacks with current closure values */
1334
1453
  rebuild: () => void
1335
- /** True when RenderPipeline is configured and ready */
1336
- isReady: boolean
1337
1454
  }
1455
+
1456
+ /**
1457
+ * Return type for useRenderPipeline hook, discriminated on `isReady`.
1458
+ *
1459
+ * `if (isReady)` narrows `renderPipeline` to non-null, which is what the docs already tell
1460
+ * callers to check. `passes.scenePass` deliberately stays optional in the ready branch:
1461
+ * `clearPasses()` empties the record while leaving the pipeline in place.
1462
+ */
1463
+ type UseRenderPipelineReturn = UseRenderPipelineActions &
1464
+ (
1465
+ | {
1466
+ /** True when RenderPipeline is configured and ready */
1467
+ isReady: true
1468
+ /** RenderPipeline instance */
1469
+ renderPipeline: ThreeRenderPipeline
1470
+ }
1471
+ | {
1472
+ /** False until the pipeline has been created */
1473
+ isReady: false
1474
+ /** Not initialized yet, or torn down by reset() */
1475
+ renderPipeline: null
1476
+ }
1477
+ )
1338
1478
  }
1339
1479
 
1340
1480
  type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
@@ -1878,7 +2018,7 @@ declare namespace useLoader {
1878
2018
  *
1879
2019
  * @param callback - Function called each frame with (state, delta). Optional if you only need scheduler access.
1880
2020
  * @param priorityOrOptions - Either a priority number (backwards compat) or options object
1881
- * @returns Controls object with step(), stepAll(), pause(), resume(), isPaused, id, scheduler
2021
+ * @returns Controls object with step(), stepAll(), invalidate(), pause(), resume(), isPaused, id, rootId, scheduler
1882
2022
  *
1883
2023
  * @example
1884
2024
  * // Simple priority (backwards compat)
@@ -2174,7 +2314,10 @@ declare function addTail(callback: GlobalRenderCallback): () => void;
2174
2314
  * Invalidates the view, requesting a frame to be rendered.
2175
2315
  * In demand mode, this triggers the scheduler to run frames.
2176
2316
  *
2177
- * @param state - Optional root state (ignored in new scheduler, kept for backwards compat)
2317
+ * With a state argument, only that root's jobs run on the requested frames; other
2318
+ * roots on 'demand' stay idle. Without one, every registered root is invalidated.
2319
+ *
2320
+ * @param state - Optional root state; targets the invalidation at that root
2178
2321
  * @param frames - Number of frames to request (default: 1)
2179
2322
  * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
2180
2323
  *
@@ -2185,14 +2328,16 @@ declare function invalidate(state?: RootState, frames?: number, stackFrames?: bo
2185
2328
  * Advances the frameloop and runs render effects.
2186
2329
  * Useful for when manually rendering via `frameloop="never"`.
2187
2330
  *
2331
+ * With a state argument, only that root is stepped. Without one, every
2332
+ * registered root is stepped for backwards compatibility.
2333
+ *
2188
2334
  * @param timestamp - The timestamp to use for this frame
2189
2335
  * @param runGlobalEffects - Ignored (kept for backwards compat, global effects always run)
2190
- * @param state - Ignored (kept for backwards compat)
2191
- * @param frame - Ignored (kept for backwards compat)
2336
+ * @param state - Optional root state; targets the manual step at that root
2192
2337
  *
2193
2338
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2194
2339
  */
2195
- declare function advance(timestamp: number): void;
2340
+ declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState): void;
2196
2341
 
2197
2342
  /* eslint-disable @definitelytyped/no-unnecessary-generics */
2198
2343
  declare function ReactReconciler<
@@ -3747,4 +3892,4 @@ declare function isOnce(value: unknown): value is {
3747
3892
  declare function Canvas(props: CanvasProps): react_jsx_runtime.JSX.Element;
3748
3893
 
3749
3894
  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, context, createEvents, createPointerEvents, createPortal, createRoot, createStore, 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, reconciler, registerPrimary, removeInteractivity, resolve, swapInteractivity, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useEnvironment, useFrame, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useMutableCallback, useRenderTarget, useStore, useTexture, useTextures, useThree, waitForPrimary };
3750
- export type { Act, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferLike, BufferRecord, BufferStore, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, DefaultGLProps, DefaultRendererProps, Disposable, DisposeOptions, 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, LegacyInternalState as InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeProps, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, LegacyRenderer as R3FRenderer, RaycastableRepresentation, ReactProps, ReconcilerRoot, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, LegacyRootState as RootState, RootStore, SetBlock, Size, StorageLike, StorageRecord, StorageStore, Subscription, TSLNodeInput, TextureInput, TextureResult, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, XRManager, XRPointerConfig };
3895
+ export type { Act, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferLike, BufferRecord, BufferStore, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, DefaultGLProps, DefaultRendererProps, Disposable, DisposeOptions, 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, LegacyInternalState as InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeLike, NodeProps, NodeRecord, NodeStore, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, LegacyRenderer as R3FRenderer, RaycastableRepresentation, ReactProps, ReconcilerRoot, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, LegacyRootState as RootState, RootStore, SetBlock, Size, StorageLike, StorageRecord, StorageStore, Subscription, TSLNodeInput, TextureInput, TextureResult, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, XRManager, XRPointerConfig };
package/dist/legacy.d.ts CHANGED
@@ -38,9 +38,9 @@ function _mergeNamespaces(n, m) {
38
38
  declare const R3F_BUILD_LEGACY = true;
39
39
  declare const R3F_BUILD_WEBGPU = false;
40
40
 
41
- declare const Inspector: {
42
- new (): {};
43
- };
41
+ type Inspector = never;
42
+ /** Not available on the legacy (WebGL-only) entry. */
43
+ declare function loadInspector(): Promise<never>;
44
44
  declare const WebGPURenderer: {
45
45
  new (): {};
46
46
  };
@@ -58,7 +58,8 @@ var THREE = /*#__PURE__*/_mergeNamespaces({
58
58
  R3F_BUILD_WEBGPU: R3F_BUILD_WEBGPU,
59
59
  RenderTarget: RenderTarget,
60
60
  RenderTargetCompat: WebGLRenderTarget,
61
- WebGPURenderer: WebGPURenderer
61
+ WebGPURenderer: WebGPURenderer,
62
+ loadInspector: loadInspector
62
63
  }, [THREE$1]);
63
64
 
64
65
  //* Utility Types ==============================
@@ -358,6 +359,33 @@ type BufferRecord = Record<string, BufferLike>
358
359
  */
359
360
  type BufferStore = Record<string, BufferLike | BufferRecord>
360
361
 
362
+ //* Node Types (useNodes) ========================================
363
+
364
+ /**
365
+ * Structural shape of a TSL node as stored on `state.nodes`.
366
+ *
367
+ * Deliberately minimal rather than three's nominal `Node`: in @types/three several node classes
368
+ * TSL hands back (OperatorNode, ConstNode, ...) do not extend `Node` cleanly, so a `Node` bound
369
+ * would reject values `useNodes` creators legitimately return. This is the same shape
370
+ * `useNodes` already constrains creators to (`TSLNodeLike`).
371
+ */
372
+ interface NodeLike {
373
+ uuid?: string
374
+ nodeType?: string | null
375
+ /** label method for chaining - sets the node's label and returns self */
376
+ label?: ((label: string) => NodeLike) | string
377
+ setName?: (name: string) => this
378
+ }
379
+
380
+ /** Flat record of TSL nodes (no nested scopes) */
381
+ type NodeRecord = Record<string, NodeLike>
382
+
383
+ /**
384
+ * Node store that can contain both root-level nodes and scoped node objects.
385
+ * Structure: { wobble: OperatorNode, fx: { blur: ShaderCallable } }
386
+ */
387
+ type NodeStore = Record<string, NodeLike | NodeRecord>
388
+
361
389
  //* Storage Types (useGPUStorage) ========================================
362
390
 
363
391
  /**
@@ -496,6 +524,18 @@ interface InternalState {
496
524
  * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
497
525
  */
498
526
  canvasTarget?: CanvasTarget
527
+ /**
528
+ * Set when this root's canvas target has been resized and the backend's cached render pass
529
+ * descriptor (which holds a depth-stencil view built once per canvas) is therefore stale.
530
+ *
531
+ * Flushed by the canvas-target job in the `start` phase, which is the only place this root's
532
+ * target is guaranteed to be the renderer's active one — `backend.updateSize()` operates on
533
+ * whatever `getCanvasTarget()` returns, so calling it from the resize subscription would
534
+ * invalidate some other canvas's descriptor instead.
535
+ *
536
+ * @see https://github.com/pmndrs/react-three-fiber/issues/3847
537
+ */
538
+ canvasTargetSizeDirty?: boolean
499
539
  /**
500
540
  * Whether multi-canvas rendering is active.
501
541
  * True when any canvas uses `renderer={{ primaryCanvas: 'id' }}` to share a renderer.
@@ -605,7 +645,7 @@ interface RootState {
605
645
  /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
606
646
  uniforms: UniformStore
607
647
  /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
608
- nodes: Record<string, any>
648
+ nodes: NodeStore
609
649
  /** Global TSL buffer nodes - root-level buffers + scoped sub-objects. Use useBuffers() hook */
610
650
  buffers: BufferStore
611
651
  /** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
@@ -617,7 +657,7 @@ interface RootState {
617
657
  /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
618
658
  renderPipeline: ThreeRenderPipeline | null
619
659
  /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
620
- passes: Record<string, any>
660
+ passes: PassRecord
621
661
  /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
622
662
  _hmrVersion: number
623
663
  /** Internal: whether setSize() has taken ownership of canvas dimensions */
@@ -705,12 +745,19 @@ type DefaultRendererProps = {
705
745
  */
706
746
  interface CanvasSchedulerConfig {
707
747
  /**
708
- * Render this canvas after another canvas completes.
709
- * Pass the `id` of another canvas.
748
+ * Run this Canvas root before the referenced Canvas root id(s).
749
+ */
750
+ before?: string | string[]
751
+ /**
752
+ * Run this Canvas root after the referenced Canvas root id(s).
710
753
  */
711
- after?: string
754
+ after?: string | string[]
712
755
  /**
713
- * Limit this canvas's render rate (frames per second).
756
+ * Numeric root order. Lower values run first.
757
+ */
758
+ order?: number
759
+ /**
760
+ * Limit this Canvas's default render job (frames per second).
714
761
  */
715
762
  fps?: number
716
763
  }
@@ -1158,7 +1205,33 @@ declare global {
1158
1205
  * ergonomics. The result is three's structural type, so members stay in sync with the
1159
1206
  * installed three instead of needing to be mirrored by hand.
1160
1207
  */
1161
- type UniformNode<T = unknown> = three_webgpu.UniformNode<unknown, T>
1208
+ type UniformNode<T = unknown> = three_webgpu.UniformNode<UniformNodeTypeFor<T>, T>
1209
+
1210
+ /**
1211
+ * three's node type name for a uniform value type, mirroring the `uniform()` overloads.
1212
+ * A `UniformNode<number>` is a `Node<'float'>`, so TSL math (`.mul`, `.add`, ...) accepts it.
1213
+ * Unknown or unlisted value types resolve to `unknown`, which TSL math rejects: narrow with
1214
+ * `as UniformNode<number>` (or the matching value type) at the call site.
1215
+ */
1216
+ type UniformNodeTypeFor<T> = T extends number
1217
+ ? 'float'
1218
+ : T extends boolean
1219
+ ? 'bool'
1220
+ : T extends three_webgpu.Color
1221
+ ? 'color'
1222
+ : T extends three_webgpu.Vector2
1223
+ ? 'vec2'
1224
+ : T extends three_webgpu.Vector3
1225
+ ? 'vec3'
1226
+ : T extends three_webgpu.Vector4
1227
+ ? 'vec4'
1228
+ : T extends three_webgpu.Matrix2
1229
+ ? 'mat2'
1230
+ : T extends three_webgpu.Matrix3
1231
+ ? 'mat3'
1232
+ : T extends three_webgpu.Matrix4
1233
+ ? 'mat4'
1234
+ : unknown
1162
1235
 
1163
1236
  /**
1164
1237
  * ShaderCallable - the return type of Fn()
@@ -1311,30 +1384,97 @@ declare global {
1311
1384
  */
1312
1385
  type ThreeRenderPipeline = three_webgpu.RenderPipeline
1313
1386
 
1314
- /** Pass record - stores TSL pass nodes for render pipeline */
1315
- type PassRecord = Record<string, any>
1387
+ /**
1388
+ * The pass `useRenderPipeline` creates for you: three's own `PassNode`, as returned by
1389
+ * `pass(scene, camera)` from `three/tsl`. Referenced from three so members like
1390
+ * `getTextureNode`, `setMRT` and `dispose` track the installed version.
1391
+ */
1392
+ type ScenePassNode = three_webgpu.PassNode
1393
+
1394
+ /**
1395
+ * Pass record - stores TSL pass nodes for render pipeline.
1396
+ *
1397
+ * `scenePass` is the only key the library owns. It is optional here because this is also the
1398
+ * shape of `state.passes`, which is `{}` before the pipeline exists and again after `reset()`
1399
+ * or `clearPasses()`. Inside the callbacks it is always present; see
1400
+ * {@link RenderPipelineCallbackState}.
1401
+ *
1402
+ * Every other key is user-registered, via a callback's return value. Those are TSL nodes of
1403
+ * any kind, not only passes: texture reads of an MRT attachment, effect nodes, extra
1404
+ * `pass()` instances. `Node` is the common base, so that is the bound. Narrow at the call
1405
+ * site when you need a member, e.g. `passes.velocity as TextureNode`.
1406
+ */
1407
+ interface PassRecord {
1408
+ scenePass?: ScenePassNode
1409
+ [key: string]: three_webgpu.Node
1410
+ }
1411
+
1412
+ /**
1413
+ * State passed to pipeline callbacks after the active pipeline has been created.
1414
+ *
1415
+ * `passes.scenePass` is required here: the hook installs the default scene pass before either
1416
+ * callback runs, so callbacks can use it without a guard or a cast.
1417
+ *
1418
+ * `renderer` is narrowed to `WebGPURenderer` and `isLegacy` to `false`: the hook throws under
1419
+ * the legacy renderer before either callback can run, so a callback never sees WebGL.
1420
+ */
1421
+ type RenderPipelineCallbackState = RootState & {
1422
+ renderPipeline: ThreeRenderPipeline
1423
+ passes: PassRecord & { scenePass: ScenePassNode }
1424
+ renderer: three_webgpu.WebGPURenderer
1425
+ isLegacy: false
1426
+ }
1427
+
1428
+ /**
1429
+ * What a callback may return to register entries into `state.passes`.
1430
+ *
1431
+ * `scenePass` is reserved. The hook owns that entry and its lifecycle: it caches the pass it
1432
+ * created, and `rebuild()` / `reset()` dispose that cached pass. A callback overwriting the
1433
+ * store entry would leave the store pointing at a node the hook never disposes, and the hook
1434
+ * disposing a pass nothing references. So returning it is a type error.
1435
+ */
1436
+ type RegisteredPasses = Record<string, three_webgpu.Node> & { scenePass?: never }
1316
1437
 
1317
1438
  /** Setup callback - runs first to configure MRT, create additional passes */
1318
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1439
+ type RenderPipelineSetupCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1319
1440
 
1320
1441
  /** Main callback - runs second to configure outputNode, create effect passes */
1321
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1442
+ type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1322
1443
 
1323
- /** Return type for useRenderPipeline hook */
1324
- interface UseRenderPipelineReturn {
1444
+ /** The imperative half of useRenderPipeline's return value, present in every state */
1445
+ interface UseRenderPipelineActions {
1325
1446
  /** Current passes from state */
1326
1447
  passes: PassRecord
1327
- /** RenderPipeline instance (null if not initialized) */
1328
- renderPipeline: ThreeRenderPipeline | null
1329
1448
  /** Clear all passes from state */
1330
1449
  clearPasses: () => void
1331
1450
  /** Reset RenderPipeline entirely (clears PP + passes) */
1332
1451
  reset: () => void
1333
1452
  /** Re-run setup/main callbacks with current closure values */
1334
1453
  rebuild: () => void
1335
- /** True when RenderPipeline is configured and ready */
1336
- isReady: boolean
1337
1454
  }
1455
+
1456
+ /**
1457
+ * Return type for useRenderPipeline hook, discriminated on `isReady`.
1458
+ *
1459
+ * `if (isReady)` narrows `renderPipeline` to non-null, which is what the docs already tell
1460
+ * callers to check. `passes.scenePass` deliberately stays optional in the ready branch:
1461
+ * `clearPasses()` empties the record while leaving the pipeline in place.
1462
+ */
1463
+ type UseRenderPipelineReturn = UseRenderPipelineActions &
1464
+ (
1465
+ | {
1466
+ /** True when RenderPipeline is configured and ready */
1467
+ isReady: true
1468
+ /** RenderPipeline instance */
1469
+ renderPipeline: ThreeRenderPipeline
1470
+ }
1471
+ | {
1472
+ /** False until the pipeline has been created */
1473
+ isReady: false
1474
+ /** Not initialized yet, or torn down by reset() */
1475
+ renderPipeline: null
1476
+ }
1477
+ )
1338
1478
  }
1339
1479
 
1340
1480
  type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
@@ -1878,7 +2018,7 @@ declare namespace useLoader {
1878
2018
  *
1879
2019
  * @param callback - Function called each frame with (state, delta). Optional if you only need scheduler access.
1880
2020
  * @param priorityOrOptions - Either a priority number (backwards compat) or options object
1881
- * @returns Controls object with step(), stepAll(), pause(), resume(), isPaused, id, scheduler
2021
+ * @returns Controls object with step(), stepAll(), invalidate(), pause(), resume(), isPaused, id, rootId, scheduler
1882
2022
  *
1883
2023
  * @example
1884
2024
  * // Simple priority (backwards compat)
@@ -2174,7 +2314,10 @@ declare function addTail(callback: GlobalRenderCallback): () => void;
2174
2314
  * Invalidates the view, requesting a frame to be rendered.
2175
2315
  * In demand mode, this triggers the scheduler to run frames.
2176
2316
  *
2177
- * @param state - Optional root state (ignored in new scheduler, kept for backwards compat)
2317
+ * With a state argument, only that root's jobs run on the requested frames; other
2318
+ * roots on 'demand' stay idle. Without one, every registered root is invalidated.
2319
+ *
2320
+ * @param state - Optional root state; targets the invalidation at that root
2178
2321
  * @param frames - Number of frames to request (default: 1)
2179
2322
  * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
2180
2323
  *
@@ -2185,14 +2328,16 @@ declare function invalidate(state?: RootState, frames?: number, stackFrames?: bo
2185
2328
  * Advances the frameloop and runs render effects.
2186
2329
  * Useful for when manually rendering via `frameloop="never"`.
2187
2330
  *
2331
+ * With a state argument, only that root is stepped. Without one, every
2332
+ * registered root is stepped for backwards compatibility.
2333
+ *
2188
2334
  * @param timestamp - The timestamp to use for this frame
2189
2335
  * @param runGlobalEffects - Ignored (kept for backwards compat, global effects always run)
2190
- * @param state - Ignored (kept for backwards compat)
2191
- * @param frame - Ignored (kept for backwards compat)
2336
+ * @param state - Optional root state; targets the manual step at that root
2192
2337
  *
2193
2338
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2194
2339
  */
2195
- declare function advance(timestamp: number): void;
2340
+ declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState): void;
2196
2341
 
2197
2342
  /* eslint-disable @definitelytyped/no-unnecessary-generics */
2198
2343
  declare function ReactReconciler<
@@ -3747,4 +3892,4 @@ declare function isOnce(value: unknown): value is {
3747
3892
  declare function Canvas(props: CanvasProps): react_jsx_runtime.JSX.Element;
3748
3893
 
3749
3894
  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, context, createEvents, createPointerEvents, createPortal, createRoot, createStore, 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, reconciler, registerPrimary, removeInteractivity, resolve, swapInteractivity, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useEnvironment, useFrame, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useMutableCallback, useRenderTarget, useStore, useTexture, useTextures, useThree, waitForPrimary };
3750
- export type { Act, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferLike, BufferRecord, BufferStore, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, DefaultGLProps, DefaultRendererProps, Disposable, DisposeOptions, 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, LegacyInternalState as InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeProps, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, LegacyRenderer as R3FRenderer, RaycastableRepresentation, ReactProps, ReconcilerRoot, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, LegacyRootState as RootState, RootStore, SetBlock, Size, StorageLike, StorageRecord, StorageStore, Subscription, TSLNodeInput, TextureInput, TextureResult, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, XRManager, XRPointerConfig };
3895
+ export type { Act, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferLike, BufferRecord, BufferStore, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, DefaultGLProps, DefaultRendererProps, Disposable, DisposeOptions, 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, LegacyInternalState as InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeLike, NodeProps, NodeRecord, NodeStore, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, LegacyRenderer as R3FRenderer, RaycastableRepresentation, ReactProps, ReconcilerRoot, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, LegacyRootState as RootState, RootStore, SetBlock, Size, StorageLike, StorageRecord, StorageStore, Subscription, TSLNodeInput, TextureInput, TextureResult, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, XRManager, XRPointerConfig };