@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.
package/dist/legacy.d.cts CHANGED
@@ -497,6 +497,18 @@ interface InternalState {
497
497
  * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
498
498
  */
499
499
  canvasTarget?: CanvasTarget
500
+ /**
501
+ * Set when this root's canvas target has been resized and the backend's cached render pass
502
+ * descriptor (which holds a depth-stencil view built once per canvas) is therefore stale.
503
+ *
504
+ * Flushed by the canvas-target job in the `start` phase, which is the only place this root's
505
+ * target is guaranteed to be the renderer's active one — `backend.updateSize()` operates on
506
+ * whatever `getCanvasTarget()` returns, so calling it from the resize subscription would
507
+ * invalidate some other canvas's descriptor instead.
508
+ *
509
+ * @see https://github.com/pmndrs/react-three-fiber/issues/3847
510
+ */
511
+ canvasTargetSizeDirty?: boolean
500
512
  /**
501
513
  * Whether multi-canvas rendering is active.
502
514
  * True when any canvas uses `renderer={{ primaryCanvas: 'id' }}` to share a renderer.
@@ -706,12 +718,19 @@ type DefaultRendererProps = {
706
718
  */
707
719
  interface CanvasSchedulerConfig {
708
720
  /**
709
- * Render this canvas after another canvas completes.
710
- * Pass the `id` of another canvas.
721
+ * Run this Canvas root before the referenced Canvas root id(s).
722
+ */
723
+ before?: string | string[]
724
+ /**
725
+ * Run this Canvas root after the referenced Canvas root id(s).
711
726
  */
712
- after?: string
727
+ after?: string | string[]
713
728
  /**
714
- * Limit this canvas's render rate (frames per second).
729
+ * Numeric root order. Lower values run first.
730
+ */
731
+ order?: number
732
+ /**
733
+ * Limit this Canvas's default render job (frames per second).
715
734
  */
716
735
  fps?: number
717
736
  }
@@ -1315,11 +1334,16 @@ declare global {
1315
1334
  /** Pass record - stores TSL pass nodes for render pipeline */
1316
1335
  type PassRecord = Record<string, any>
1317
1336
 
1337
+ /** State passed to pipeline callbacks after the active pipeline has been created */
1338
+ type RenderPipelineCallbackState = RootState & {
1339
+ renderPipeline: ThreeRenderPipeline
1340
+ }
1341
+
1318
1342
  /** Setup callback - runs first to configure MRT, create additional passes */
1319
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1343
+ type RenderPipelineSetupCallback = (state: RenderPipelineCallbackState) => PassRecord | void
1320
1344
 
1321
1345
  /** Main callback - runs second to configure outputNode, create effect passes */
1322
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1346
+ type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => PassRecord | void
1323
1347
 
1324
1348
  /** Return type for useRenderPipeline hook */
1325
1349
  interface UseRenderPipelineReturn {
@@ -1879,7 +1903,7 @@ declare namespace useLoader {
1879
1903
  *
1880
1904
  * @param callback - Function called each frame with (state, delta). Optional if you only need scheduler access.
1881
1905
  * @param priorityOrOptions - Either a priority number (backwards compat) or options object
1882
- * @returns Controls object with step(), stepAll(), pause(), resume(), isPaused, id, scheduler
1906
+ * @returns Controls object with step(), stepAll(), invalidate(), pause(), resume(), isPaused, id, rootId, scheduler
1883
1907
  *
1884
1908
  * @example
1885
1909
  * // Simple priority (backwards compat)
@@ -2175,7 +2199,10 @@ declare function addTail(callback: GlobalRenderCallback): () => void;
2175
2199
  * Invalidates the view, requesting a frame to be rendered.
2176
2200
  * In demand mode, this triggers the scheduler to run frames.
2177
2201
  *
2178
- * @param state - Optional root state (ignored in new scheduler, kept for backwards compat)
2202
+ * With a state argument, only that root's jobs run on the requested frames; other
2203
+ * roots on 'demand' stay idle. Without one, every registered root is invalidated.
2204
+ *
2205
+ * @param state - Optional root state; targets the invalidation at that root
2179
2206
  * @param frames - Number of frames to request (default: 1)
2180
2207
  * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
2181
2208
  *
@@ -2186,14 +2213,16 @@ declare function invalidate(state?: RootState, frames?: number, stackFrames?: bo
2186
2213
  * Advances the frameloop and runs render effects.
2187
2214
  * Useful for when manually rendering via `frameloop="never"`.
2188
2215
  *
2216
+ * With a state argument, only that root is stepped. Without one, every
2217
+ * registered root is stepped for backwards compatibility.
2218
+ *
2189
2219
  * @param timestamp - The timestamp to use for this frame
2190
2220
  * @param runGlobalEffects - Ignored (kept for backwards compat, global effects always run)
2191
- * @param state - Ignored (kept for backwards compat)
2192
- * @param frame - Ignored (kept for backwards compat)
2221
+ * @param state - Optional root state; targets the manual step at that root
2193
2222
  *
2194
2223
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2195
2224
  */
2196
- declare function advance(timestamp: number): void;
2225
+ declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState): void;
2197
2226
 
2198
2227
  /* eslint-disable @definitelytyped/no-unnecessary-generics */
2199
2228
  declare function ReactReconciler<
package/dist/legacy.d.mts CHANGED
@@ -497,6 +497,18 @@ interface InternalState {
497
497
  * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
498
498
  */
499
499
  canvasTarget?: CanvasTarget
500
+ /**
501
+ * Set when this root's canvas target has been resized and the backend's cached render pass
502
+ * descriptor (which holds a depth-stencil view built once per canvas) is therefore stale.
503
+ *
504
+ * Flushed by the canvas-target job in the `start` phase, which is the only place this root's
505
+ * target is guaranteed to be the renderer's active one — `backend.updateSize()` operates on
506
+ * whatever `getCanvasTarget()` returns, so calling it from the resize subscription would
507
+ * invalidate some other canvas's descriptor instead.
508
+ *
509
+ * @see https://github.com/pmndrs/react-three-fiber/issues/3847
510
+ */
511
+ canvasTargetSizeDirty?: boolean
500
512
  /**
501
513
  * Whether multi-canvas rendering is active.
502
514
  * True when any canvas uses `renderer={{ primaryCanvas: 'id' }}` to share a renderer.
@@ -706,12 +718,19 @@ type DefaultRendererProps = {
706
718
  */
707
719
  interface CanvasSchedulerConfig {
708
720
  /**
709
- * Render this canvas after another canvas completes.
710
- * Pass the `id` of another canvas.
721
+ * Run this Canvas root before the referenced Canvas root id(s).
722
+ */
723
+ before?: string | string[]
724
+ /**
725
+ * Run this Canvas root after the referenced Canvas root id(s).
711
726
  */
712
- after?: string
727
+ after?: string | string[]
713
728
  /**
714
- * Limit this canvas's render rate (frames per second).
729
+ * Numeric root order. Lower values run first.
730
+ */
731
+ order?: number
732
+ /**
733
+ * Limit this Canvas's default render job (frames per second).
715
734
  */
716
735
  fps?: number
717
736
  }
@@ -1315,11 +1334,16 @@ declare global {
1315
1334
  /** Pass record - stores TSL pass nodes for render pipeline */
1316
1335
  type PassRecord = Record<string, any>
1317
1336
 
1337
+ /** State passed to pipeline callbacks after the active pipeline has been created */
1338
+ type RenderPipelineCallbackState = RootState & {
1339
+ renderPipeline: ThreeRenderPipeline
1340
+ }
1341
+
1318
1342
  /** Setup callback - runs first to configure MRT, create additional passes */
1319
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1343
+ type RenderPipelineSetupCallback = (state: RenderPipelineCallbackState) => PassRecord | void
1320
1344
 
1321
1345
  /** Main callback - runs second to configure outputNode, create effect passes */
1322
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1346
+ type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => PassRecord | void
1323
1347
 
1324
1348
  /** Return type for useRenderPipeline hook */
1325
1349
  interface UseRenderPipelineReturn {
@@ -1879,7 +1903,7 @@ declare namespace useLoader {
1879
1903
  *
1880
1904
  * @param callback - Function called each frame with (state, delta). Optional if you only need scheduler access.
1881
1905
  * @param priorityOrOptions - Either a priority number (backwards compat) or options object
1882
- * @returns Controls object with step(), stepAll(), pause(), resume(), isPaused, id, scheduler
1906
+ * @returns Controls object with step(), stepAll(), invalidate(), pause(), resume(), isPaused, id, rootId, scheduler
1883
1907
  *
1884
1908
  * @example
1885
1909
  * // Simple priority (backwards compat)
@@ -2175,7 +2199,10 @@ declare function addTail(callback: GlobalRenderCallback): () => void;
2175
2199
  * Invalidates the view, requesting a frame to be rendered.
2176
2200
  * In demand mode, this triggers the scheduler to run frames.
2177
2201
  *
2178
- * @param state - Optional root state (ignored in new scheduler, kept for backwards compat)
2202
+ * With a state argument, only that root's jobs run on the requested frames; other
2203
+ * roots on 'demand' stay idle. Without one, every registered root is invalidated.
2204
+ *
2205
+ * @param state - Optional root state; targets the invalidation at that root
2179
2206
  * @param frames - Number of frames to request (default: 1)
2180
2207
  * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
2181
2208
  *
@@ -2186,14 +2213,16 @@ declare function invalidate(state?: RootState, frames?: number, stackFrames?: bo
2186
2213
  * Advances the frameloop and runs render effects.
2187
2214
  * Useful for when manually rendering via `frameloop="never"`.
2188
2215
  *
2216
+ * With a state argument, only that root is stepped. Without one, every
2217
+ * registered root is stepped for backwards compatibility.
2218
+ *
2189
2219
  * @param timestamp - The timestamp to use for this frame
2190
2220
  * @param runGlobalEffects - Ignored (kept for backwards compat, global effects always run)
2191
- * @param state - Ignored (kept for backwards compat)
2192
- * @param frame - Ignored (kept for backwards compat)
2221
+ * @param state - Optional root state; targets the manual step at that root
2193
2222
  *
2194
2223
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2195
2224
  */
2196
- declare function advance(timestamp: number): void;
2225
+ declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState): void;
2197
2226
 
2198
2227
  /* eslint-disable @definitelytyped/no-unnecessary-generics */
2199
2228
  declare function ReactReconciler<
package/dist/legacy.d.ts CHANGED
@@ -497,6 +497,18 @@ interface InternalState {
497
497
  * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
498
498
  */
499
499
  canvasTarget?: CanvasTarget
500
+ /**
501
+ * Set when this root's canvas target has been resized and the backend's cached render pass
502
+ * descriptor (which holds a depth-stencil view built once per canvas) is therefore stale.
503
+ *
504
+ * Flushed by the canvas-target job in the `start` phase, which is the only place this root's
505
+ * target is guaranteed to be the renderer's active one — `backend.updateSize()` operates on
506
+ * whatever `getCanvasTarget()` returns, so calling it from the resize subscription would
507
+ * invalidate some other canvas's descriptor instead.
508
+ *
509
+ * @see https://github.com/pmndrs/react-three-fiber/issues/3847
510
+ */
511
+ canvasTargetSizeDirty?: boolean
500
512
  /**
501
513
  * Whether multi-canvas rendering is active.
502
514
  * True when any canvas uses `renderer={{ primaryCanvas: 'id' }}` to share a renderer.
@@ -706,12 +718,19 @@ type DefaultRendererProps = {
706
718
  */
707
719
  interface CanvasSchedulerConfig {
708
720
  /**
709
- * Render this canvas after another canvas completes.
710
- * Pass the `id` of another canvas.
721
+ * Run this Canvas root before the referenced Canvas root id(s).
722
+ */
723
+ before?: string | string[]
724
+ /**
725
+ * Run this Canvas root after the referenced Canvas root id(s).
711
726
  */
712
- after?: string
727
+ after?: string | string[]
713
728
  /**
714
- * Limit this canvas's render rate (frames per second).
729
+ * Numeric root order. Lower values run first.
730
+ */
731
+ order?: number
732
+ /**
733
+ * Limit this Canvas's default render job (frames per second).
715
734
  */
716
735
  fps?: number
717
736
  }
@@ -1315,11 +1334,16 @@ declare global {
1315
1334
  /** Pass record - stores TSL pass nodes for render pipeline */
1316
1335
  type PassRecord = Record<string, any>
1317
1336
 
1337
+ /** State passed to pipeline callbacks after the active pipeline has been created */
1338
+ type RenderPipelineCallbackState = RootState & {
1339
+ renderPipeline: ThreeRenderPipeline
1340
+ }
1341
+
1318
1342
  /** Setup callback - runs first to configure MRT, create additional passes */
1319
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1343
+ type RenderPipelineSetupCallback = (state: RenderPipelineCallbackState) => PassRecord | void
1320
1344
 
1321
1345
  /** Main callback - runs second to configure outputNode, create effect passes */
1322
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1346
+ type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => PassRecord | void
1323
1347
 
1324
1348
  /** Return type for useRenderPipeline hook */
1325
1349
  interface UseRenderPipelineReturn {
@@ -1879,7 +1903,7 @@ declare namespace useLoader {
1879
1903
  *
1880
1904
  * @param callback - Function called each frame with (state, delta). Optional if you only need scheduler access.
1881
1905
  * @param priorityOrOptions - Either a priority number (backwards compat) or options object
1882
- * @returns Controls object with step(), stepAll(), pause(), resume(), isPaused, id, scheduler
1906
+ * @returns Controls object with step(), stepAll(), invalidate(), pause(), resume(), isPaused, id, rootId, scheduler
1883
1907
  *
1884
1908
  * @example
1885
1909
  * // Simple priority (backwards compat)
@@ -2175,7 +2199,10 @@ declare function addTail(callback: GlobalRenderCallback): () => void;
2175
2199
  * Invalidates the view, requesting a frame to be rendered.
2176
2200
  * In demand mode, this triggers the scheduler to run frames.
2177
2201
  *
2178
- * @param state - Optional root state (ignored in new scheduler, kept for backwards compat)
2202
+ * With a state argument, only that root's jobs run on the requested frames; other
2203
+ * roots on 'demand' stay idle. Without one, every registered root is invalidated.
2204
+ *
2205
+ * @param state - Optional root state; targets the invalidation at that root
2179
2206
  * @param frames - Number of frames to request (default: 1)
2180
2207
  * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
2181
2208
  *
@@ -2186,14 +2213,16 @@ declare function invalidate(state?: RootState, frames?: number, stackFrames?: bo
2186
2213
  * Advances the frameloop and runs render effects.
2187
2214
  * Useful for when manually rendering via `frameloop="never"`.
2188
2215
  *
2216
+ * With a state argument, only that root is stepped. Without one, every
2217
+ * registered root is stepped for backwards compatibility.
2218
+ *
2189
2219
  * @param timestamp - The timestamp to use for this frame
2190
2220
  * @param runGlobalEffects - Ignored (kept for backwards compat, global effects always run)
2191
- * @param state - Ignored (kept for backwards compat)
2192
- * @param frame - Ignored (kept for backwards compat)
2221
+ * @param state - Optional root state; targets the manual step at that root
2193
2222
  *
2194
2223
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2195
2224
  */
2196
- declare function advance(timestamp: number): void;
2225
+ declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState): void;
2197
2226
 
2198
2227
  /* eslint-disable @definitelytyped/no-unnecessary-generics */
2199
2228
  declare function ReactReconciler<
package/dist/legacy.mjs CHANGED
@@ -909,7 +909,7 @@ const createStore = (invalidate, advance) => {
909
909
  size: newSize,
910
910
  viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, newSize) }
911
911
  }));
912
- getScheduler().invalidate();
912
+ get().invalidate();
913
913
  }
914
914
  }
915
915
  return;
@@ -924,15 +924,16 @@ const createStore = (invalidate, advance) => {
924
924
  viewport: { ...s.viewport, ...getCurrentViewport(state2.camera, defaultTarget, size) },
925
925
  _sizeImperative: true
926
926
  }));
927
- getScheduler().invalidate();
927
+ get().invalidate();
928
928
  },
929
929
  setDpr: (dpr) => set((state2) => {
930
930
  const resolved = calculateDpr(dpr);
931
931
  return { viewport: { ...state2.viewport, dpr: resolved, initialDpr: state2.viewport.initialDpr || resolved } };
932
932
  }),
933
933
  setFrameloop: (frameloop = "always") => {
934
+ const rootId = get().internal.rootId;
935
+ if (rootId) getScheduler().setRootFrameloop(rootId, frameloop);
934
936
  set(() => ({ frameloop }));
935
- getScheduler().frameloop = frameloop;
936
937
  },
937
938
  setError: (error) => set(() => ({ error })),
938
939
  error: null,
@@ -1048,17 +1049,10 @@ const createStore = (invalidate, advance) => {
1048
1049
  oldSize = size;
1049
1050
  oldDpr = viewport.dpr;
1050
1051
  updateCamera(camera, size);
1051
- if (internal.isSecondary && canvasTarget) {
1052
- if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
1053
- canvasTarget.setSize(size.width, size.height, false);
1054
- } else {
1055
- if (viewport.dpr > 0) actualRenderer.setPixelRatio(viewport.dpr);
1056
- actualRenderer.setSize(size.width, size.height, false);
1057
- if (canvasTarget) {
1058
- if (viewport.dpr > 0) canvasTarget.setPixelRatio(viewport.dpr);
1059
- canvasTarget.setSize(size.width, size.height, false);
1060
- }
1061
- }
1052
+ const resizeTarget = canvasTarget ?? actualRenderer;
1053
+ if (viewport.dpr > 0) resizeTarget.setPixelRatio(viewport.dpr);
1054
+ resizeTarget.setSize(size.width, size.height, false);
1055
+ internal.canvasTargetSizeDirty = true;
1062
1056
  }
1063
1057
  if (camera !== oldCamera) {
1064
1058
  oldCamera = camera;
@@ -1120,7 +1114,11 @@ function useLoader(loader, input, extensions, onProgress, cacheKey) {
1120
1114
  const results = cacheKeys.map(
1121
1115
  (key, index) => suspend(() => fn(loader, inputs[index]), [loader, key], { equal: is.equ })
1122
1116
  );
1123
- return Array.isArray(input) ? results : results[0];
1117
+ const stableRef = useRef(null);
1118
+ const previous = stableRef.current;
1119
+ const stable = previous !== null && previous.length === results.length && previous.every((value, i) => value === results[i]) ? previous : results;
1120
+ stableRef.current = stable;
1121
+ return Array.isArray(input) ? stable : stable[0];
1124
1122
  }
1125
1123
  useLoader.preload = function(loader, input, extensions, onProgress, cacheKey) {
1126
1124
  const inputs = Array.isArray(input) ? input : [input];
@@ -1240,6 +1238,13 @@ function useFrame(callback, priorityOrOptions) {
1240
1238
  * Use for controlling the entire frame loop, adding phases, etc.
1241
1239
  */
1242
1240
  scheduler: scheduler2,
1241
+ /**
1242
+ * The root that currently owns this job. Resolve on access because ambient
1243
+ * jobs can be adopted by a Canvas after the controls object is created.
1244
+ */
1245
+ get rootId() {
1246
+ return getScheduler().getJobRootId(id);
1247
+ },
1243
1248
  /**
1244
1249
  * Manually step this job only.
1245
1250
  * Bypasses FPS limiting - always runs.
@@ -1256,6 +1261,14 @@ function useFrame(callback, priorityOrOptions) {
1256
1261
  stepAll: (timestamp) => {
1257
1262
  getScheduler().step(timestamp);
1258
1263
  },
1264
+ /**
1265
+ * Request frames for this job's owning root without waking sibling roots.
1266
+ */
1267
+ invalidate: (frames, stackFrames) => {
1268
+ const scheduler3 = getScheduler();
1269
+ const rootId = scheduler3.getJobRootId(id);
1270
+ if (rootId) scheduler3.invalidateRoot(rootId, frames, stackFrames);
1271
+ },
1259
1272
  /**
1260
1273
  * Pause this job (set enabled=false).
1261
1274
  * Job remains registered but won't run.
@@ -1285,6 +1298,11 @@ function getUrls(input) {
1285
1298
  if (Array.isArray(input)) return input;
1286
1299
  return Object.values(input);
1287
1300
  }
1301
+ function inputSignature(input) {
1302
+ if (typeof input === "string") return input;
1303
+ if (Array.isArray(input)) return input.join("\0");
1304
+ return Object.keys(input).sort().map((key) => `${key}\0${input[key]}`).join("");
1305
+ }
1288
1306
  function allUrlsCached(urls, textureCache) {
1289
1307
  return urls.every((url) => textureCache.has(url));
1290
1308
  }
@@ -1310,18 +1328,19 @@ function useTexture(input, optionsOrOnLoad) {
1310
1328
  const onLoadRef = useRef(onLoad);
1311
1329
  onLoadRef.current = onLoad;
1312
1330
  const onLoadCalledForRef = useRef(null);
1313
- const urls = useMemo(() => getUrls(input), [input]);
1331
+ const inputKey = useMemo(() => inputSignature(input), [input]);
1332
+ const stableInput = useMemo(() => input, [inputKey]);
1333
+ const urls = useMemo(() => getUrls(stableInput), [stableInput]);
1314
1334
  const cachedResult = useMemo(() => {
1315
1335
  if (!cache) return null;
1316
1336
  const textures = store.getState().textures;
1317
1337
  if (!allUrlsCached(urls, textures)) return null;
1318
- return buildFromCache(input, textures);
1319
- }, [cache, urls, input, store]);
1338
+ return buildFromCache(stableInput, textures);
1339
+ }, [cache, urls, stableInput, store]);
1320
1340
  const loadedTextures = useLoader(
1321
1341
  TextureLoader,
1322
- IsObject(input) ? Object.values(input) : input
1342
+ IsObject(stableInput) ? Object.values(stableInput) : stableInput
1323
1343
  );
1324
- const inputKey = urls.join("\0");
1325
1344
  useLayoutEffect(() => {
1326
1345
  if (cachedResult) return;
1327
1346
  if (onLoadCalledForRef.current === inputKey) return;
@@ -1348,28 +1367,28 @@ function useTexture(input, optionsOrOnLoad) {
1348
1367
  }, [renderer, loadedTextures, cachedResult]);
1349
1368
  const mappedTextures = useMemo(() => {
1350
1369
  if (cachedResult) return cachedResult;
1351
- if (IsObject(input)) {
1370
+ if (IsObject(stableInput)) {
1352
1371
  const keyed = {};
1353
1372
  const textureArray = loadedTextures;
1354
1373
  let i = 0;
1355
- for (const key in input) keyed[key] = textureArray[i++];
1374
+ for (const key in stableInput) keyed[key] = textureArray[i++];
1356
1375
  return keyed;
1357
1376
  } else {
1358
1377
  return loadedTextures;
1359
1378
  }
1360
- }, [input, loadedTextures, cachedResult]);
1379
+ }, [stableInput, loadedTextures, cachedResult]);
1361
1380
  useEffect(() => {
1362
1381
  if (!cache) return;
1363
1382
  const urlTextureMap = [];
1364
- if (typeof input === "string") {
1365
- urlTextureMap.push([input, mappedTextures]);
1366
- } else if (Array.isArray(input)) {
1383
+ if (typeof stableInput === "string") {
1384
+ urlTextureMap.push([stableInput, mappedTextures]);
1385
+ } else if (Array.isArray(stableInput)) {
1367
1386
  const textureArray = mappedTextures;
1368
- input.forEach((url, i) => urlTextureMap.push([url, textureArray[i]]));
1369
- } else if (IsObject(input)) {
1387
+ stableInput.forEach((url, i) => urlTextureMap.push([url, textureArray[i]]));
1388
+ } else if (IsObject(stableInput)) {
1370
1389
  const textureRecord = mappedTextures;
1371
- for (const key in input) {
1372
- const url = input[key];
1390
+ for (const key in stableInput) {
1391
+ const url = stableInput[key];
1373
1392
  urlTextureMap.push([url, textureRecord[key]]);
1374
1393
  }
1375
1394
  }
@@ -1398,7 +1417,7 @@ function useTexture(input, optionsOrOnLoad) {
1398
1417
  }
1399
1418
  return { _textureRefs: refs };
1400
1419
  });
1401
- }, [cache, input, mappedTextures, store]);
1420
+ }, [cache, stableInput, mappedTextures, store]);
1402
1421
  return mappedTextures;
1403
1422
  }
1404
1423
  useTexture.preload = (url) => useLoader.preload(TextureLoader, url);
@@ -1667,10 +1686,16 @@ function addTail(callback) {
1667
1686
  return getScheduler().onIdle(callback);
1668
1687
  }
1669
1688
  function invalidate(state, frames = 1, stackFrames = false) {
1670
- getScheduler().invalidate(frames, stackFrames);
1689
+ const rootId = state?.internal?.rootId;
1690
+ const scheduler = getScheduler();
1691
+ if (rootId) scheduler.invalidateRoot(rootId, frames, stackFrames);
1692
+ else scheduler.invalidate(frames, stackFrames);
1671
1693
  }
1672
- function advance(timestamp) {
1673
- getScheduler().step(timestamp);
1694
+ function advance(timestamp, runGlobalEffects, state) {
1695
+ const rootId = state?.internal?.rootId;
1696
+ const scheduler = getScheduler();
1697
+ if (rootId) scheduler.stepRoot(rootId, timestamp);
1698
+ else scheduler.step(timestamp);
1674
1699
  }
1675
1700
 
1676
1701
  const version = "10.0.0-alpha.3";
@@ -14285,7 +14310,7 @@ function createRoot(canvas) {
14285
14310
  const handleXRFrame = (timestamp, _frame) => {
14286
14311
  const state2 = store.getState();
14287
14312
  if (state2.frameloop === "never") return;
14288
- advance(timestamp);
14313
+ advance(timestamp, true, state2);
14289
14314
  };
14290
14315
  const actualRenderer = state.internal.actualRenderer;
14291
14316
  const handleSessionChange = () => {
@@ -14293,7 +14318,7 @@ function createRoot(canvas) {
14293
14318
  const renderer2 = state2.internal.actualRenderer;
14294
14319
  actualRenderer.xr.enabled = actualRenderer.xr.isPresenting;
14295
14320
  renderer2.xr.setAnimationLoop(renderer2.xr.isPresenting ? handleXRFrame : null);
14296
- if (!renderer2.xr.isPresenting) invalidate();
14321
+ if (!renderer2.xr.isPresenting) invalidate(state2);
14297
14322
  };
14298
14323
  const xr = {
14299
14324
  connect() {
@@ -14375,7 +14400,11 @@ function createRoot(canvas) {
14375
14400
  const newRootId = canvasId || scheduler.generateRootId();
14376
14401
  const unregisterRoot = scheduler.registerRoot(newRootId, {
14377
14402
  getState: () => store.getState(),
14378
- onError: (err) => store.getState().setError(err)
14403
+ onError: (err) => store.getState().setError(err),
14404
+ frameloop: store.getState().frameloop,
14405
+ before: schedulerConfig?.before,
14406
+ after: schedulerConfig?.after,
14407
+ order: schedulerConfig?.order
14379
14408
  });
14380
14409
  const unregisterCanvasTarget = scheduler.register(
14381
14410
  () => {
@@ -14383,6 +14412,10 @@ function createRoot(canvas) {
14383
14412
  if (state2.internal.isMultiCanvas && state2.internal.canvasTarget) {
14384
14413
  const renderer2 = state2.internal.actualRenderer;
14385
14414
  renderer2.setCanvasTarget(state2.internal.canvasTarget);
14415
+ if (state2.internal.canvasTargetSizeDirty) {
14416
+ state2.internal.canvasTargetSizeDirty = false;
14417
+ renderer2.backend?.updateSize?.();
14418
+ }
14386
14419
  }
14387
14420
  },
14388
14421
  {
@@ -14451,8 +14484,7 @@ function createRoot(canvas) {
14451
14484
  phase: "render",
14452
14485
  system: true,
14453
14486
  // Internal flag: this is a system job, not user-controlled
14454
- // Apply scheduler config for render ordering and rate limiting
14455
- ...schedulerConfig?.after && { after: schedulerConfig.after },
14487
+ // FPS throttles only the default render job; Canvas ordering belongs to the root.
14456
14488
  ...schedulerConfig?.fps && { fps: schedulerConfig.fps }
14457
14489
  }
14458
14490
  );
@@ -14471,8 +14503,21 @@ function createRoot(canvas) {
14471
14503
  scheduler
14472
14504
  }
14473
14505
  }));
14506
+ } else {
14507
+ const constraintsChanged = !is.equ(schedulerConfig?.before, lastConfiguredProps.schedulerBefore, shallowLoose) || !is.equ(schedulerConfig?.after, lastConfiguredProps.schedulerAfter, shallowLoose);
14508
+ if (constraintsChanged) {
14509
+ scheduler.setRootConstraints(rootId, {
14510
+ before: schedulerConfig?.before,
14511
+ after: schedulerConfig?.after
14512
+ });
14513
+ }
14514
+ if (schedulerConfig?.order !== lastConfiguredProps.schedulerOrder) {
14515
+ scheduler.setRootOrder(rootId, schedulerConfig?.order ?? 0);
14516
+ }
14474
14517
  }
14475
- scheduler.frameloop = frameloop;
14518
+ lastConfiguredProps.schedulerBefore = schedulerConfig?.before;
14519
+ lastConfiguredProps.schedulerAfter = schedulerConfig?.after;
14520
+ lastConfiguredProps.schedulerOrder = schedulerConfig?.order;
14476
14521
  onCreated = onCreatedCallback;
14477
14522
  configured = true;
14478
14523
  resolve();
@@ -14514,14 +14559,19 @@ function unmountComponentAtNode(canvas, callback) {
14514
14559
  const fiber = root?.fiber;
14515
14560
  if (fiber) {
14516
14561
  const state = root?.store.getState();
14517
- if (state) state.internal.active = false;
14562
+ if (state) {
14563
+ state.internal.active = false;
14564
+ const unregisterRoot = state.internal.unregisterRoot;
14565
+ if (unregisterRoot) {
14566
+ unregisterRoot();
14567
+ state.internal.unregisterRoot = void 0;
14568
+ }
14569
+ }
14518
14570
  reconciler.updateContainer(null, fiber, null, () => {
14519
14571
  if (state) {
14520
14572
  setTimeout(() => {
14521
14573
  try {
14522
14574
  const renderer = state.internal.actualRenderer;
14523
- const unregisterRoot = state.internal.unregisterRoot;
14524
- if (unregisterRoot) unregisterRoot();
14525
14575
  const unregisterPrimary = state.internal.unregisterPrimary;
14526
14576
  if (unregisterPrimary) unregisterPrimary();
14527
14577
  const canvasTarget = state.internal.canvasTarget;
@@ -15115,6 +15165,7 @@ function CanvasImpl({
15115
15165
  const canvas = canvasRef.current;
15116
15166
  if (canvas) {
15117
15167
  return () => {
15168
+ if (canvas.isConnected) return;
15118
15169
  unmountComponentAtNode(canvas);
15119
15170
  root.current = null;
15120
15171
  };