@react-three/fiber 10.0.0-canary.6eb9584 → 10.0.0-canary.7a50545

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.
@@ -935,7 +935,7 @@ const createStore = (invalidate, advance) => {
935
935
  size: newSize,
936
936
  viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
937
937
  }));
938
- scheduler.getScheduler().invalidate();
938
+ get().invalidate();
939
939
  }
940
940
  }
941
941
  return;
@@ -950,15 +950,16 @@ const createStore = (invalidate, advance) => {
950
950
  viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
951
951
  _sizeImperative: true
952
952
  }));
953
- scheduler.getScheduler().invalidate();
953
+ get().invalidate();
954
954
  },
955
955
  setDpr: (dpr) => set((state2) => {
956
956
  const resolved = calculateDpr(dpr);
957
957
  return { viewport: { ...state2.viewport, dpr: resolved, initialDpr: state2.viewport.initialDpr || resolved } };
958
958
  }),
959
959
  setFrameloop: (frameloop = "always") => {
960
+ const rootId = get().internal.rootId;
961
+ if (rootId) scheduler.getScheduler().setRootFrameloop(rootId, frameloop);
960
962
  set(() => ({ frameloop }));
961
- scheduler.getScheduler().frameloop = frameloop;
962
963
  },
963
964
  setError: (error) => set(() => ({ error })),
964
965
  error: null,
@@ -1074,17 +1075,10 @@ const createStore = (invalidate, advance) => {
1074
1075
  oldSize = size;
1075
1076
  oldDpr = viewport.dpr;
1076
1077
  updateCamera(camera, size);
1077
- if (internal.isSecondary && canvasTarget) {
1078
- if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
1079
- canvasTarget.setSize(size.width, size.height, false);
1080
- } else {
1081
- if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
1082
- actualRenderer.setSize(size.width, size.height, false);
1083
- if (canvasTarget) {
1084
- if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
1085
- canvasTarget.setSize(size.width, size.height, false);
1086
- }
1087
- }
1078
+ const resizeTarget = canvasTarget ?? actualRenderer;
1079
+ if (viewport.dpr > 0) resizeTarget.setPixelRatio(viewport.dpr);
1080
+ resizeTarget.setSize(size.width, size.height, false);
1081
+ internal.canvasTargetSizeDirty = true;
1088
1082
  }
1089
1083
  if (camera !== oldCamera) {
1090
1084
  oldCamera = camera;
@@ -1146,7 +1140,11 @@ function useLoader(loader, input, extensions, onProgress, cacheKey) {
1146
1140
  const results = cacheKeys.map(
1147
1141
  (key, index) => suspendReact.suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
1148
1142
  );
1149
- return Array.isArray(input) ? results : results[0];
1143
+ const stableRef = React.useRef(null);
1144
+ const previous = stableRef.current;
1145
+ const stable = previous !== null && previous.length === results.length && previous.every((value, i) => value === results[i]) ? previous : results;
1146
+ stableRef.current = stable;
1147
+ return Array.isArray(input) ? stable : stable[0];
1150
1148
  }
1151
1149
  useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
1152
1150
  const inputs = Array.isArray(input) ? input : [input];
@@ -1266,6 +1264,13 @@ function useFrame$1(callback, priorityOrOptions) {
1266
1264
  * Use for controlling the entire frame loop, adding phases, etc.
1267
1265
  */
1268
1266
  scheduler: scheduler2,
1267
+ /**
1268
+ * The root that currently owns this job. Resolve on access because ambient
1269
+ * jobs can be adopted by a Canvas after the controls object is created.
1270
+ */
1271
+ get rootId() {
1272
+ return scheduler.getScheduler().getJobRootId(id);
1273
+ },
1269
1274
  /**
1270
1275
  * Manually step this job only.
1271
1276
  * Bypasses FPS limiting - always runs.
@@ -1282,6 +1287,14 @@ function useFrame$1(callback, priorityOrOptions) {
1282
1287
  stepAll: (timestamp) => {
1283
1288
  scheduler.getScheduler().step(timestamp);
1284
1289
  },
1290
+ /**
1291
+ * Request frames for this job's owning root without waking sibling roots.
1292
+ */
1293
+ invalidate: (frames, stackFrames) => {
1294
+ const scheduler3 = scheduler.getScheduler();
1295
+ const rootId = scheduler3.getJobRootId(id);
1296
+ if (rootId) scheduler3.invalidateRoot(rootId, frames, stackFrames);
1297
+ },
1285
1298
  /**
1286
1299
  * Pause this job (set enabled=false).
1287
1300
  * Job remains registered but won't run.
@@ -1311,6 +1324,11 @@ function getUrls(input) {
1311
1324
  if (Array.isArray(input)) return input;
1312
1325
  return Object.values(input);
1313
1326
  }
1327
+ function inputSignature(input) {
1328
+ if (typeof input === "string") return input;
1329
+ if (Array.isArray(input)) return input.join("\0");
1330
+ return Object.keys(input).sort().map((key) => `${key}\0${input[key]}`).join("");
1331
+ }
1314
1332
  function allUrlsCached(urls, textureCache) {
1315
1333
  return urls.every((url) => textureCache.has(url));
1316
1334
  }
@@ -1336,18 +1354,19 @@ function useTexture(input, optionsOrOnLoad) {
1336
1354
  const onLoadRef = React.useRef(onLoad);
1337
1355
  onLoadRef.current = onLoad;
1338
1356
  const onLoadCalledForRef = React.useRef(null);
1339
- const urls = React.useMemo(() => getUrls(input), [input]);
1357
+ const inputKey = React.useMemo(() => inputSignature(input), [input]);
1358
+ const stableInput = React.useMemo(() => input, [inputKey]);
1359
+ const urls = React.useMemo(() => getUrls(stableInput), [stableInput]);
1340
1360
  const cachedResult = React.useMemo(() => {
1341
1361
  if (!cache) return null;
1342
1362
  const textures = store.getState().textures;
1343
1363
  if (!allUrlsCached(urls, textures)) return null;
1344
- return buildFromCache(input, textures);
1345
- }, [cache, urls, input, store]);
1364
+ return buildFromCache(stableInput, textures);
1365
+ }, [cache, urls, stableInput, store]);
1346
1366
  const loadedTextures = useLoader(
1347
1367
  webgpu.TextureLoader,
1348
- IsObject(input) ? Object.values(input) : input
1368
+ IsObject(stableInput) ? Object.values(stableInput) : stableInput
1349
1369
  );
1350
- const inputKey = urls.join("\0");
1351
1370
  React.useLayoutEffect(() => {
1352
1371
  if (cachedResult) return;
1353
1372
  if (onLoadCalledForRef.current === inputKey) return;
@@ -1374,28 +1393,28 @@ function useTexture(input, optionsOrOnLoad) {
1374
1393
  }, [renderer, loadedTextures, cachedResult]);
1375
1394
  const mappedTextures = React.useMemo(() => {
1376
1395
  if (cachedResult) return cachedResult;
1377
- if (IsObject(input)) {
1396
+ if (IsObject(stableInput)) {
1378
1397
  const keyed = {};
1379
1398
  const textureArray = loadedTextures;
1380
1399
  let i = 0;
1381
- for (const key in input) keyed[key] = textureArray[i++];
1400
+ for (const key in stableInput) keyed[key] = textureArray[i++];
1382
1401
  return keyed;
1383
1402
  } else {
1384
1403
  return loadedTextures;
1385
1404
  }
1386
- }, [input, loadedTextures, cachedResult]);
1405
+ }, [stableInput, loadedTextures, cachedResult]);
1387
1406
  React.useEffect(() => {
1388
1407
  if (!cache) return;
1389
1408
  const urlTextureMap = [];
1390
- if (typeof input === "string") {
1391
- urlTextureMap.push([input, mappedTextures]);
1392
- } else if (Array.isArray(input)) {
1409
+ if (typeof stableInput === "string") {
1410
+ urlTextureMap.push([stableInput, mappedTextures]);
1411
+ } else if (Array.isArray(stableInput)) {
1393
1412
  const textureArray = mappedTextures;
1394
- input.forEach((url, i) => urlTextureMap.push([url, textureArray[i]]));
1395
- } else if (IsObject(input)) {
1413
+ stableInput.forEach((url, i) => urlTextureMap.push([url, textureArray[i]]));
1414
+ } else if (IsObject(stableInput)) {
1396
1415
  const textureRecord = mappedTextures;
1397
- for (const key in input) {
1398
- const url = input[key];
1416
+ for (const key in stableInput) {
1417
+ const url = stableInput[key];
1399
1418
  urlTextureMap.push([url, textureRecord[key]]);
1400
1419
  }
1401
1420
  }
@@ -1424,7 +1443,7 @@ function useTexture(input, optionsOrOnLoad) {
1424
1443
  }
1425
1444
  return { _textureRefs: refs };
1426
1445
  });
1427
- }, [cache, input, mappedTextures, store]);
1446
+ }, [cache, stableInput, mappedTextures, store]);
1428
1447
  return mappedTextures;
1429
1448
  }
1430
1449
  useTexture.preload = (url) => useLoader.preload(webgpu.TextureLoader, url);
@@ -1693,10 +1712,16 @@ function addTail(callback) {
1693
1712
  return scheduler.getScheduler().onIdle(callback);
1694
1713
  }
1695
1714
  function invalidate(state, frames = 1, stackFrames = false) {
1696
- scheduler.getScheduler().invalidate(frames, stackFrames);
1715
+ const rootId = state?.internal?.rootId;
1716
+ const scheduler$1 = scheduler.getScheduler();
1717
+ if (rootId) scheduler$1.invalidateRoot(rootId, frames, stackFrames);
1718
+ else scheduler$1.invalidate(frames, stackFrames);
1697
1719
  }
1698
- function advance(timestamp) {
1699
- scheduler.getScheduler().step(timestamp);
1720
+ function advance(timestamp, runGlobalEffects, state) {
1721
+ const rootId = state?.internal?.rootId;
1722
+ const scheduler$1 = scheduler.getScheduler();
1723
+ if (rootId) scheduler$1.stepRoot(rootId, timestamp);
1724
+ else scheduler$1.step(timestamp);
1700
1725
  }
1701
1726
 
1702
1727
  const version = "10.0.0-alpha.3";
@@ -14340,7 +14365,7 @@ function createRoot(canvas) {
14340
14365
  const handleXRFrame = (timestamp, _frame) => {
14341
14366
  const state2 = store.getState();
14342
14367
  if (state2.frameloop === "never") return;
14343
- advance(timestamp);
14368
+ advance(timestamp, true, state2);
14344
14369
  };
14345
14370
  const actualRenderer = state.internal.actualRenderer;
14346
14371
  const handleSessionChange = () => {
@@ -14348,7 +14373,7 @@ function createRoot(canvas) {
14348
14373
  const renderer2 = state2.internal.actualRenderer;
14349
14374
  actualRenderer.xr.enabled = actualRenderer.xr.isPresenting;
14350
14375
  renderer2.xr.setAnimationLoop(renderer2.xr.isPresenting ? handleXRFrame : null);
14351
- if (!renderer2.xr.isPresenting) invalidate();
14376
+ if (!renderer2.xr.isPresenting) invalidate(state2);
14352
14377
  };
14353
14378
  const xr = {
14354
14379
  connect() {
@@ -14430,7 +14455,11 @@ function createRoot(canvas) {
14430
14455
  const newRootId = canvasId || scheduler$1.generateRootId();
14431
14456
  const unregisterRoot = scheduler$1.registerRoot(newRootId, {
14432
14457
  getState: () => store.getState(),
14433
- onError: (err) => store.getState().setError(err)
14458
+ onError: (err) => store.getState().setError(err),
14459
+ frameloop: store.getState().frameloop,
14460
+ before: schedulerConfig?.before,
14461
+ after: schedulerConfig?.after,
14462
+ order: schedulerConfig?.order
14434
14463
  });
14435
14464
  const unregisterCanvasTarget = scheduler$1.register(
14436
14465
  () => {
@@ -14438,6 +14467,10 @@ function createRoot(canvas) {
14438
14467
  if (state2.internal.isMultiCanvas && state2.internal.canvasTarget) {
14439
14468
  const renderer2 = state2.internal.actualRenderer;
14440
14469
  renderer2.setCanvasTarget(state2.internal.canvasTarget);
14470
+ if (state2.internal.canvasTargetSizeDirty) {
14471
+ state2.internal.canvasTargetSizeDirty = false;
14472
+ renderer2.backend?.updateSize?.();
14473
+ }
14441
14474
  }
14442
14475
  },
14443
14476
  {
@@ -14506,8 +14539,7 @@ function createRoot(canvas) {
14506
14539
  phase: "render",
14507
14540
  system: true,
14508
14541
  // Internal flag: this is a system job, not user-controlled
14509
- // Apply scheduler config for render ordering and rate limiting
14510
- ...schedulerConfig?.after && { after: schedulerConfig.after },
14542
+ // FPS throttles only the default render job; Canvas ordering belongs to the root.
14511
14543
  ...schedulerConfig?.fps && { fps: schedulerConfig.fps }
14512
14544
  }
14513
14545
  );
@@ -14526,8 +14558,21 @@ function createRoot(canvas) {
14526
14558
  scheduler: scheduler$1
14527
14559
  }
14528
14560
  }));
14561
+ } else {
14562
+ const constraintsChanged = !is.equ(schedulerConfig?.before, lastConfiguredProps.schedulerBefore, shallowLoose) || !is.equ(schedulerConfig?.after, lastConfiguredProps.schedulerAfter, shallowLoose);
14563
+ if (constraintsChanged) {
14564
+ scheduler$1.setRootConstraints(rootId, {
14565
+ before: schedulerConfig?.before,
14566
+ after: schedulerConfig?.after
14567
+ });
14568
+ }
14569
+ if (schedulerConfig?.order !== lastConfiguredProps.schedulerOrder) {
14570
+ scheduler$1.setRootOrder(rootId, schedulerConfig?.order ?? 0);
14571
+ }
14529
14572
  }
14530
- scheduler$1.frameloop = frameloop;
14573
+ lastConfiguredProps.schedulerBefore = schedulerConfig?.before;
14574
+ lastConfiguredProps.schedulerAfter = schedulerConfig?.after;
14575
+ lastConfiguredProps.schedulerOrder = schedulerConfig?.order;
14531
14576
  onCreated = onCreatedCallback;
14532
14577
  configured = true;
14533
14578
  resolve();
@@ -14569,14 +14614,19 @@ function unmountComponentAtNode(canvas, callback) {
14569
14614
  const fiber = root?.fiber;
14570
14615
  if (fiber) {
14571
14616
  const state = root?.store.getState();
14572
- if (state) state.internal.active = false;
14617
+ if (state) {
14618
+ state.internal.active = false;
14619
+ const unregisterRoot = state.internal.unregisterRoot;
14620
+ if (unregisterRoot) {
14621
+ unregisterRoot();
14622
+ state.internal.unregisterRoot = void 0;
14623
+ }
14624
+ }
14573
14625
  reconciler.updateContainer(null, fiber, null, () => {
14574
14626
  if (state) {
14575
14627
  setTimeout(() => {
14576
14628
  try {
14577
14629
  const renderer = state.internal.actualRenderer;
14578
- const unregisterRoot = state.internal.unregisterRoot;
14579
- if (unregisterRoot) unregisterRoot();
14580
14630
  const unregisterPrimary = state.internal.unregisterPrimary;
14581
14631
  if (unregisterPrimary) unregisterPrimary();
14582
14632
  const canvasTarget = state.internal.canvasTarget;
@@ -15267,6 +15317,7 @@ function CanvasImpl({
15267
15317
  const canvas = canvasRef.current;
15268
15318
  if (canvas) {
15269
15319
  return () => {
15320
+ if (canvas.isConnected) return;
15270
15321
  unmountComponentAtNode(canvas);
15271
15322
  root.current = null;
15272
15323
  };
@@ -15993,6 +16044,7 @@ function useRenderPipeline(mainCB, setupCB) {
15993
16044
  const { scene, camera, renderer, isLegacy } = useThree$1();
15994
16045
  const callbacksRanRef = React.useRef(false);
15995
16046
  const scenePassCacheRef = React.useRef(null);
16047
+ const forceScenePassRebuildRef = React.useRef(false);
15996
16048
  const mainCBRef = React.useRef(mainCB);
15997
16049
  const setupCBRef = React.useRef(setupCB);
15998
16050
  mainCBRef.current = mainCB;
@@ -16000,7 +16052,7 @@ function useRenderPipeline(mainCB, setupCB) {
16000
16052
  const [rebuildVersion, setRebuildVersion] = React.useState(0);
16001
16053
  React.useEffect(() => {
16002
16054
  callbacksRanRef.current = false;
16003
- scenePassCacheRef.current = null;
16055
+ forceScenePassRebuildRef.current = true;
16004
16056
  }, []);
16005
16057
  const clearPasses = React.useCallback(() => {
16006
16058
  store.setState({ passes: {} });
@@ -16010,12 +16062,14 @@ function useRenderPipeline(mainCB, setupCB) {
16010
16062
  renderPipeline: null,
16011
16063
  passes: {}
16012
16064
  });
16065
+ scenePassCacheRef.current?.scenePass?.dispose?.();
16013
16066
  callbacksRanRef.current = false;
16014
16067
  scenePassCacheRef.current = null;
16068
+ forceScenePassRebuildRef.current = false;
16015
16069
  }, [store]);
16016
16070
  const rebuild = React.useCallback(() => {
16017
16071
  callbacksRanRef.current = false;
16018
- scenePassCacheRef.current = null;
16072
+ forceScenePassRebuildRef.current = true;
16019
16073
  setRebuildVersion((v) => v + 1);
16020
16074
  }, []);
16021
16075
  React.useLayoutEffect(() => {
@@ -16033,21 +16087,31 @@ function useRenderPipeline(mainCB, setupCB) {
16033
16087
  pipeline = new webgpu.RenderPipeline(renderer);
16034
16088
  justCreatedPipeline = true;
16035
16089
  }
16036
- const cacheValid = scenePassCacheRef.current && scenePassCacheRef.current.sceneUuid === scene.uuid && scenePassCacheRef.current.cameraUuid === camera.uuid;
16090
+ const cacheValid = !forceScenePassRebuildRef.current && scenePassCacheRef.current && scenePassCacheRef.current.sceneUuid === scene.uuid && scenePassCacheRef.current.cameraUuid === camera.uuid;
16091
+ let outgoingScenePass = null;
16037
16092
  let scenePass;
16038
16093
  if (cacheValid) {
16039
16094
  scenePass = scenePassCacheRef.current.scenePass;
16040
16095
  } else {
16096
+ outgoingScenePass = scenePassCacheRef.current?.scenePass ?? null;
16041
16097
  scenePass = tsl.pass(scene, camera);
16042
16098
  scenePassCacheRef.current = { sceneUuid: scene.uuid, cameraUuid: camera.uuid, scenePass };
16099
+ forceScenePassRebuildRef.current = false;
16043
16100
  }
16044
16101
  currentPasses.scenePass = scenePass;
16045
- if (!pipeline.outputNode || justCreatedPipeline) pipeline.outputNode = scenePass;
16102
+ let outputNodeChanged = false;
16103
+ if (!pipeline.outputNode || justCreatedPipeline || pipeline.outputNode === outgoingScenePass) {
16104
+ pipeline.outputNode = scenePass;
16105
+ outputNodeChanged = true;
16106
+ }
16046
16107
  set({ renderPipeline: pipeline, passes: currentPasses });
16047
16108
  const shouldRunCallbacks = justCreatedPipeline || !callbacksRanRef.current || !cacheValid;
16048
16109
  if (shouldRunCallbacks) {
16049
16110
  if (setupCBRef.current) {
16050
- const freshState = store.getState();
16111
+ const freshState = Object.assign({}, store.getState(), {
16112
+ renderPipeline: pipeline,
16113
+ passes: currentPasses
16114
+ });
16051
16115
  const setupResult = setupCBRef.current(freshState);
16052
16116
  if (setupResult && typeof setupResult === "object") {
16053
16117
  currentPasses = { ...currentPasses, ...setupResult };
@@ -16055,15 +16119,21 @@ function useRenderPipeline(mainCB, setupCB) {
16055
16119
  }
16056
16120
  }
16057
16121
  if (mainCBRef.current) {
16058
- const freshState = store.getState();
16122
+ const freshState = Object.assign({}, store.getState(), {
16123
+ renderPipeline: pipeline,
16124
+ passes: currentPasses
16125
+ });
16059
16126
  const mainResult = mainCBRef.current(freshState);
16060
16127
  if (mainResult && typeof mainResult === "object") {
16061
16128
  currentPasses = { ...currentPasses, ...mainResult };
16062
16129
  set({ passes: currentPasses });
16063
16130
  }
16064
16131
  }
16132
+ outputNodeChanged = true;
16065
16133
  callbacksRanRef.current = true;
16066
16134
  }
16135
+ if (outputNodeChanged) pipeline.needsUpdate = true;
16136
+ if (outgoingScenePass && outgoingScenePass !== scenePass) outgoingScenePass.dispose?.();
16067
16137
  } catch (error) {
16068
16138
  console.warn("[useRenderPipeline] Setup failed; the render pipeline was not configured:", error);
16069
16139
  }
@@ -503,6 +503,18 @@ interface InternalState {
503
503
  * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
504
504
  */
505
505
  canvasTarget?: CanvasTarget
506
+ /**
507
+ * Set when this root's canvas target has been resized and the backend's cached render pass
508
+ * descriptor (which holds a depth-stencil view built once per canvas) is therefore stale.
509
+ *
510
+ * Flushed by the canvas-target job in the `start` phase, which is the only place this root's
511
+ * target is guaranteed to be the renderer's active one — `backend.updateSize()` operates on
512
+ * whatever `getCanvasTarget()` returns, so calling it from the resize subscription would
513
+ * invalidate some other canvas's descriptor instead.
514
+ *
515
+ * @see https://github.com/pmndrs/react-three-fiber/issues/3847
516
+ */
517
+ canvasTargetSizeDirty?: boolean
506
518
  /**
507
519
  * Whether multi-canvas rendering is active.
508
520
  * True when any canvas uses `renderer={{ primaryCanvas: 'id' }}` to share a renderer.
@@ -712,12 +724,19 @@ type DefaultRendererProps = {
712
724
  */
713
725
  interface CanvasSchedulerConfig {
714
726
  /**
715
- * Render this canvas after another canvas completes.
716
- * Pass the `id` of another canvas.
727
+ * Run this Canvas root before the referenced Canvas root id(s).
728
+ */
729
+ before?: string | string[]
730
+ /**
731
+ * Run this Canvas root after the referenced Canvas root id(s).
717
732
  */
718
- after?: string
733
+ after?: string | string[]
719
734
  /**
720
- * Limit this canvas's render rate (frames per second).
735
+ * Numeric root order. Lower values run first.
736
+ */
737
+ order?: number
738
+ /**
739
+ * Limit this Canvas's default render job (frames per second).
721
740
  */
722
741
  fps?: number
723
742
  }
@@ -1321,11 +1340,16 @@ declare global {
1321
1340
  /** Pass record - stores TSL pass nodes for render pipeline */
1322
1341
  type PassRecord = Record<string, any>
1323
1342
 
1343
+ /** State passed to pipeline callbacks after the active pipeline has been created */
1344
+ type RenderPipelineCallbackState = RootState & {
1345
+ renderPipeline: ThreeRenderPipeline
1346
+ }
1347
+
1324
1348
  /** Setup callback - runs first to configure MRT, create additional passes */
1325
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1349
+ type RenderPipelineSetupCallback = (state: RenderPipelineCallbackState) => PassRecord | void
1326
1350
 
1327
1351
  /** Main callback - runs second to configure outputNode, create effect passes */
1328
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1352
+ type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => PassRecord | void
1329
1353
 
1330
1354
  /** Return type for useRenderPipeline hook */
1331
1355
  interface UseRenderPipelineReturn {
@@ -2132,7 +2156,10 @@ declare function addTail(callback: GlobalRenderCallback): () => void;
2132
2156
  * Invalidates the view, requesting a frame to be rendered.
2133
2157
  * In demand mode, this triggers the scheduler to run frames.
2134
2158
  *
2135
- * @param state - Optional root state (ignored in new scheduler, kept for backwards compat)
2159
+ * With a state argument, only that root's jobs run on the requested frames; other
2160
+ * roots on 'demand' stay idle. Without one, every registered root is invalidated.
2161
+ *
2162
+ * @param state - Optional root state; targets the invalidation at that root
2136
2163
  * @param frames - Number of frames to request (default: 1)
2137
2164
  * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
2138
2165
  *
@@ -2143,14 +2170,16 @@ declare function invalidate(state?: RootState, frames?: number, stackFrames?: bo
2143
2170
  * Advances the frameloop and runs render effects.
2144
2171
  * Useful for when manually rendering via `frameloop="never"`.
2145
2172
  *
2173
+ * With a state argument, only that root is stepped. Without one, every
2174
+ * registered root is stepped for backwards compatibility.
2175
+ *
2146
2176
  * @param timestamp - The timestamp to use for this frame
2147
2177
  * @param runGlobalEffects - Ignored (kept for backwards compat, global effects always run)
2148
- * @param state - Ignored (kept for backwards compat)
2149
- * @param frame - Ignored (kept for backwards compat)
2178
+ * @param state - Optional root state; targets the manual step at that root
2150
2179
  *
2151
2180
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2152
2181
  */
2153
- declare function advance(timestamp: number): void;
2182
+ declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState): void;
2154
2183
 
2155
2184
  /* eslint-disable @definitelytyped/no-unnecessary-generics */
2156
2185
  declare function ReactReconciler<
@@ -4041,6 +4070,10 @@ declare function createTextureOperations(set: StoreApi<RootState>['setState']):
4041
4070
  * - Callbacks receive full RootState for flexibility
4042
4071
  * - No auto-cleanup on unmount - use reset() for explicit cleanup
4043
4072
  * - Scene/camera changes trigger scenePass recreation
4073
+ * - A replaced scenePass is disposed once the new graph is installed, so rebuild() does not
4074
+ * strand its render target (and MRT attachments) on the GPU
4075
+ * - Any run that changes the output node sets RenderPipeline.needsUpdate, so rebuild() actually
4076
+ * recompiles instead of silently keeping the first compiled graph
4044
4077
  *
4045
4078
  * @param mainCB - Main callback to configure outputNode and create effect passes
4046
4079
  * @param setupCB - Optional setup callback to configure MRT on scenePass
@@ -503,6 +503,18 @@ interface InternalState {
503
503
  * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
504
504
  */
505
505
  canvasTarget?: CanvasTarget
506
+ /**
507
+ * Set when this root's canvas target has been resized and the backend's cached render pass
508
+ * descriptor (which holds a depth-stencil view built once per canvas) is therefore stale.
509
+ *
510
+ * Flushed by the canvas-target job in the `start` phase, which is the only place this root's
511
+ * target is guaranteed to be the renderer's active one — `backend.updateSize()` operates on
512
+ * whatever `getCanvasTarget()` returns, so calling it from the resize subscription would
513
+ * invalidate some other canvas's descriptor instead.
514
+ *
515
+ * @see https://github.com/pmndrs/react-three-fiber/issues/3847
516
+ */
517
+ canvasTargetSizeDirty?: boolean
506
518
  /**
507
519
  * Whether multi-canvas rendering is active.
508
520
  * True when any canvas uses `renderer={{ primaryCanvas: 'id' }}` to share a renderer.
@@ -712,12 +724,19 @@ type DefaultRendererProps = {
712
724
  */
713
725
  interface CanvasSchedulerConfig {
714
726
  /**
715
- * Render this canvas after another canvas completes.
716
- * Pass the `id` of another canvas.
727
+ * Run this Canvas root before the referenced Canvas root id(s).
728
+ */
729
+ before?: string | string[]
730
+ /**
731
+ * Run this Canvas root after the referenced Canvas root id(s).
717
732
  */
718
- after?: string
733
+ after?: string | string[]
719
734
  /**
720
- * Limit this canvas's render rate (frames per second).
735
+ * Numeric root order. Lower values run first.
736
+ */
737
+ order?: number
738
+ /**
739
+ * Limit this Canvas's default render job (frames per second).
721
740
  */
722
741
  fps?: number
723
742
  }
@@ -1321,11 +1340,16 @@ declare global {
1321
1340
  /** Pass record - stores TSL pass nodes for render pipeline */
1322
1341
  type PassRecord = Record<string, any>
1323
1342
 
1343
+ /** State passed to pipeline callbacks after the active pipeline has been created */
1344
+ type RenderPipelineCallbackState = RootState & {
1345
+ renderPipeline: ThreeRenderPipeline
1346
+ }
1347
+
1324
1348
  /** Setup callback - runs first to configure MRT, create additional passes */
1325
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1349
+ type RenderPipelineSetupCallback = (state: RenderPipelineCallbackState) => PassRecord | void
1326
1350
 
1327
1351
  /** Main callback - runs second to configure outputNode, create effect passes */
1328
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1352
+ type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => PassRecord | void
1329
1353
 
1330
1354
  /** Return type for useRenderPipeline hook */
1331
1355
  interface UseRenderPipelineReturn {
@@ -2132,7 +2156,10 @@ declare function addTail(callback: GlobalRenderCallback): () => void;
2132
2156
  * Invalidates the view, requesting a frame to be rendered.
2133
2157
  * In demand mode, this triggers the scheduler to run frames.
2134
2158
  *
2135
- * @param state - Optional root state (ignored in new scheduler, kept for backwards compat)
2159
+ * With a state argument, only that root's jobs run on the requested frames; other
2160
+ * roots on 'demand' stay idle. Without one, every registered root is invalidated.
2161
+ *
2162
+ * @param state - Optional root state; targets the invalidation at that root
2136
2163
  * @param frames - Number of frames to request (default: 1)
2137
2164
  * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
2138
2165
  *
@@ -2143,14 +2170,16 @@ declare function invalidate(state?: RootState, frames?: number, stackFrames?: bo
2143
2170
  * Advances the frameloop and runs render effects.
2144
2171
  * Useful for when manually rendering via `frameloop="never"`.
2145
2172
  *
2173
+ * With a state argument, only that root is stepped. Without one, every
2174
+ * registered root is stepped for backwards compatibility.
2175
+ *
2146
2176
  * @param timestamp - The timestamp to use for this frame
2147
2177
  * @param runGlobalEffects - Ignored (kept for backwards compat, global effects always run)
2148
- * @param state - Ignored (kept for backwards compat)
2149
- * @param frame - Ignored (kept for backwards compat)
2178
+ * @param state - Optional root state; targets the manual step at that root
2150
2179
  *
2151
2180
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2152
2181
  */
2153
- declare function advance(timestamp: number): void;
2182
+ declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState): void;
2154
2183
 
2155
2184
  /* eslint-disable @definitelytyped/no-unnecessary-generics */
2156
2185
  declare function ReactReconciler<
@@ -4041,6 +4070,10 @@ declare function createTextureOperations(set: StoreApi<RootState>['setState']):
4041
4070
  * - Callbacks receive full RootState for flexibility
4042
4071
  * - No auto-cleanup on unmount - use reset() for explicit cleanup
4043
4072
  * - Scene/camera changes trigger scenePass recreation
4073
+ * - A replaced scenePass is disposed once the new graph is installed, so rebuild() does not
4074
+ * strand its render target (and MRT attachments) on the GPU
4075
+ * - Any run that changes the output node sets RenderPipeline.needsUpdate, so rebuild() actually
4076
+ * recompiles instead of silently keeping the first compiled graph
4044
4077
  *
4045
4078
  * @param mainCB - Main callback to configure outputNode and create effect passes
4046
4079
  * @param setupCB - Optional setup callback to configure MRT on scenePass