@react-three/fiber 10.0.0-canary.8f5b4d3 → 10.0.0-canary.979dc2d

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.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
  /**
@@ -491,11 +519,28 @@ interface InternalState {
491
519
  /** Container for child attachment (scene for root, original container for portals) */
492
520
  container?: THREE$1.Object3D
493
521
  /**
494
- * CanvasTarget for multi-canvas WebGPU rendering.
495
- * Created for all WebGPU canvases to support renderer sharing.
522
+ * The CanvasTarget this root sizes and renders through.
523
+ *
524
+ * A primary (`<Canvas id>`) owns the renderer's default target -- the one three itself built
525
+ * around the canvas element -- so sizing it is sizing the renderer. A secondary owns a target
526
+ * R3F created for its own element. Either way there is exactly one target per canvas element,
527
+ * and the canvas-target job makes it the renderer's active one before this root renders.
528
+ * Absent on WebGL and on an id-less WebGPU canvas, where the renderer is sized directly.
496
529
  * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
497
530
  */
498
531
  canvasTarget?: CanvasTarget
532
+ /**
533
+ * Set when this root's canvas target has been resized and the backend's cached render pass
534
+ * descriptor (which holds a depth-stencil view built once per canvas) is therefore stale.
535
+ *
536
+ * Flushed by the canvas-target job in the `start` phase, which is the only place this root's
537
+ * target is guaranteed to be the renderer's active one — `backend.updateSize()` operates on
538
+ * whatever `getCanvasTarget()` returns, so calling it from the resize subscription would
539
+ * invalidate some other canvas's descriptor instead.
540
+ *
541
+ * @see https://github.com/pmndrs/react-three-fiber/issues/3847
542
+ */
543
+ canvasTargetSizeDirty?: boolean
499
544
  /**
500
545
  * Whether multi-canvas rendering is active.
501
546
  * True when any canvas uses `renderer={{ primaryCanvas: 'id' }}` to share a renderer.
@@ -605,7 +650,7 @@ interface RootState {
605
650
  /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
606
651
  uniforms: UniformStore
607
652
  /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
608
- nodes: Record<string, any>
653
+ nodes: NodeStore
609
654
  /** Global TSL buffer nodes - root-level buffers + scoped sub-objects. Use useBuffers() hook */
610
655
  buffers: BufferStore
611
656
  /** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
@@ -617,7 +662,7 @@ interface RootState {
617
662
  /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
618
663
  renderPipeline: ThreeRenderPipeline | null
619
664
  /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
620
- passes: Record<string, any>
665
+ passes: PassRecord
621
666
  /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
622
667
  _hmrVersion: number
623
668
  /** Internal: whether setSize() has taken ownership of canvas dimensions */
@@ -705,12 +750,19 @@ type DefaultRendererProps = {
705
750
  */
706
751
  interface CanvasSchedulerConfig {
707
752
  /**
708
- * Render this canvas after another canvas completes.
709
- * Pass the `id` of another canvas.
753
+ * Run this Canvas root before the referenced Canvas root id(s).
754
+ */
755
+ before?: string | string[]
756
+ /**
757
+ * Run this Canvas root after the referenced Canvas root id(s).
758
+ */
759
+ after?: string | string[]
760
+ /**
761
+ * Numeric root order. Lower values run first.
710
762
  */
711
- after?: string
763
+ order?: number
712
764
  /**
713
- * Limit this canvas's render rate (frames per second).
765
+ * Limit this Canvas's default render job (frames per second).
714
766
  */
715
767
  fps?: number
716
768
  }
@@ -1158,7 +1210,33 @@ declare global {
1158
1210
  * ergonomics. The result is three's structural type, so members stay in sync with the
1159
1211
  * installed three instead of needing to be mirrored by hand.
1160
1212
  */
1161
- type UniformNode<T = unknown> = three_webgpu.UniformNode<unknown, T>
1213
+ type UniformNode<T = unknown> = three_webgpu.UniformNode<UniformNodeTypeFor<T>, T>
1214
+
1215
+ /**
1216
+ * three's node type name for a uniform value type, mirroring the `uniform()` overloads.
1217
+ * A `UniformNode<number>` is a `Node<'float'>`, so TSL math (`.mul`, `.add`, ...) accepts it.
1218
+ * Unknown or unlisted value types resolve to `unknown`, which TSL math rejects: narrow with
1219
+ * `as UniformNode<number>` (or the matching value type) at the call site.
1220
+ */
1221
+ type UniformNodeTypeFor<T> = T extends number
1222
+ ? 'float'
1223
+ : T extends boolean
1224
+ ? 'bool'
1225
+ : T extends three_webgpu.Color
1226
+ ? 'color'
1227
+ : T extends three_webgpu.Vector2
1228
+ ? 'vec2'
1229
+ : T extends three_webgpu.Vector3
1230
+ ? 'vec3'
1231
+ : T extends three_webgpu.Vector4
1232
+ ? 'vec4'
1233
+ : T extends three_webgpu.Matrix2
1234
+ ? 'mat2'
1235
+ : T extends three_webgpu.Matrix3
1236
+ ? 'mat3'
1237
+ : T extends three_webgpu.Matrix4
1238
+ ? 'mat4'
1239
+ : unknown
1162
1240
 
1163
1241
  /**
1164
1242
  * ShaderCallable - the return type of Fn()
@@ -1311,30 +1389,97 @@ declare global {
1311
1389
  */
1312
1390
  type ThreeRenderPipeline = three_webgpu.RenderPipeline
1313
1391
 
1314
- /** Pass record - stores TSL pass nodes for render pipeline */
1315
- type PassRecord = Record<string, any>
1392
+ /**
1393
+ * The pass `useRenderPipeline` creates for you: three's own `PassNode`, as returned by
1394
+ * `pass(scene, camera)` from `three/tsl`. Referenced from three so members like
1395
+ * `getTextureNode`, `setMRT` and `dispose` track the installed version.
1396
+ */
1397
+ type ScenePassNode = three_webgpu.PassNode
1398
+
1399
+ /**
1400
+ * Pass record - stores TSL pass nodes for render pipeline.
1401
+ *
1402
+ * `scenePass` is the only key the library owns. It is optional here because this is also the
1403
+ * shape of `state.passes`, which is `{}` before the pipeline exists and again after `reset()`
1404
+ * or `clearPasses()`. Inside the callbacks it is always present; see
1405
+ * {@link RenderPipelineCallbackState}.
1406
+ *
1407
+ * Every other key is user-registered, via a callback's return value. Those are TSL nodes of
1408
+ * any kind, not only passes: texture reads of an MRT attachment, effect nodes, extra
1409
+ * `pass()` instances. `Node` is the common base, so that is the bound. Narrow at the call
1410
+ * site when you need a member, e.g. `passes.velocity as TextureNode`.
1411
+ */
1412
+ interface PassRecord {
1413
+ scenePass?: ScenePassNode
1414
+ [key: string]: three_webgpu.Node
1415
+ }
1416
+
1417
+ /**
1418
+ * State passed to pipeline callbacks after the active pipeline has been created.
1419
+ *
1420
+ * `passes.scenePass` is required here: the hook installs the default scene pass before either
1421
+ * callback runs, so callbacks can use it without a guard or a cast.
1422
+ *
1423
+ * `renderer` is narrowed to `WebGPURenderer` and `isLegacy` to `false`: the hook throws under
1424
+ * the legacy renderer before either callback can run, so a callback never sees WebGL.
1425
+ */
1426
+ type RenderPipelineCallbackState = RootState & {
1427
+ renderPipeline: ThreeRenderPipeline
1428
+ passes: PassRecord & { scenePass: ScenePassNode }
1429
+ renderer: three_webgpu.WebGPURenderer
1430
+ isLegacy: false
1431
+ }
1432
+
1433
+ /**
1434
+ * What a callback may return to register entries into `state.passes`.
1435
+ *
1436
+ * `scenePass` is reserved. The hook owns that entry and its lifecycle: it caches the pass it
1437
+ * created, and `rebuild()` / `reset()` dispose that cached pass. A callback overwriting the
1438
+ * store entry would leave the store pointing at a node the hook never disposes, and the hook
1439
+ * disposing a pass nothing references. So returning it is a type error.
1440
+ */
1441
+ type RegisteredPasses = Record<string, three_webgpu.Node> & { scenePass?: never }
1316
1442
 
1317
1443
  /** Setup callback - runs first to configure MRT, create additional passes */
1318
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1444
+ type RenderPipelineSetupCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1319
1445
 
1320
1446
  /** Main callback - runs second to configure outputNode, create effect passes */
1321
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1447
+ type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
1322
1448
 
1323
- /** Return type for useRenderPipeline hook */
1324
- interface UseRenderPipelineReturn {
1449
+ /** The imperative half of useRenderPipeline's return value, present in every state */
1450
+ interface UseRenderPipelineActions {
1325
1451
  /** Current passes from state */
1326
1452
  passes: PassRecord
1327
- /** RenderPipeline instance (null if not initialized) */
1328
- renderPipeline: ThreeRenderPipeline | null
1329
1453
  /** Clear all passes from state */
1330
1454
  clearPasses: () => void
1331
1455
  /** Reset RenderPipeline entirely (clears PP + passes) */
1332
1456
  reset: () => void
1333
1457
  /** Re-run setup/main callbacks with current closure values */
1334
1458
  rebuild: () => void
1335
- /** True when RenderPipeline is configured and ready */
1336
- isReady: boolean
1337
1459
  }
1460
+
1461
+ /**
1462
+ * Return type for useRenderPipeline hook, discriminated on `isReady`.
1463
+ *
1464
+ * `if (isReady)` narrows `renderPipeline` to non-null, which is what the docs already tell
1465
+ * callers to check. `passes.scenePass` deliberately stays optional in the ready branch:
1466
+ * `clearPasses()` empties the record while leaving the pipeline in place.
1467
+ */
1468
+ type UseRenderPipelineReturn = UseRenderPipelineActions &
1469
+ (
1470
+ | {
1471
+ /** True when RenderPipeline is configured and ready */
1472
+ isReady: true
1473
+ /** RenderPipeline instance */
1474
+ renderPipeline: ThreeRenderPipeline
1475
+ }
1476
+ | {
1477
+ /** False until the pipeline has been created */
1478
+ isReady: false
1479
+ /** Not initialized yet, or torn down by reset() */
1480
+ renderPipeline: null
1481
+ }
1482
+ )
1338
1483
  }
1339
1484
 
1340
1485
  type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
@@ -1878,7 +2023,7 @@ declare namespace useLoader {
1878
2023
  *
1879
2024
  * @param callback - Function called each frame with (state, delta). Optional if you only need scheduler access.
1880
2025
  * @param priorityOrOptions - Either a priority number (backwards compat) or options object
1881
- * @returns Controls object with step(), stepAll(), pause(), resume(), isPaused, id, scheduler
2026
+ * @returns Controls object with step(), stepAll(), invalidate(), pause(), resume(), isPaused, id, rootId, scheduler
1882
2027
  *
1883
2028
  * @example
1884
2029
  * // Simple priority (backwards compat)
@@ -2174,7 +2319,10 @@ declare function addTail(callback: GlobalRenderCallback): () => void;
2174
2319
  * Invalidates the view, requesting a frame to be rendered.
2175
2320
  * In demand mode, this triggers the scheduler to run frames.
2176
2321
  *
2177
- * @param state - Optional root state (ignored in new scheduler, kept for backwards compat)
2322
+ * With a state argument, only that root's jobs run on the requested frames; other
2323
+ * roots on 'demand' stay idle. Without one, every registered root is invalidated.
2324
+ *
2325
+ * @param state - Optional root state; targets the invalidation at that root
2178
2326
  * @param frames - Number of frames to request (default: 1)
2179
2327
  * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
2180
2328
  *
@@ -2185,14 +2333,16 @@ declare function invalidate(state?: RootState, frames?: number, stackFrames?: bo
2185
2333
  * Advances the frameloop and runs render effects.
2186
2334
  * Useful for when manually rendering via `frameloop="never"`.
2187
2335
  *
2336
+ * With a state argument, only that root is stepped. Without one, every
2337
+ * registered root is stepped for backwards compatibility.
2338
+ *
2188
2339
  * @param timestamp - The timestamp to use for this frame
2189
2340
  * @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)
2341
+ * @param state - Optional root state; targets the manual step at that root
2192
2342
  *
2193
2343
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2194
2344
  */
2195
- declare function advance(timestamp: number): void;
2345
+ declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState): void;
2196
2346
 
2197
2347
  /* eslint-disable @definitelytyped/no-unnecessary-generics */
2198
2348
  declare function ReactReconciler<
@@ -3747,4 +3897,4 @@ declare function isOnce(value: unknown): value is {
3747
3897
  declare function Canvas(props: CanvasProps): react_jsx_runtime.JSX.Element;
3748
3898
 
3749
3899
  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 };
3900
+ 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 };