@react-three/fiber 9.7.0 → 9.8.1
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/CHANGELOG.md +51 -0
- package/dist/declarations/react-reconciler/index.d.ts +30 -13
- package/dist/declarations/src/core/{renderer.d.ts → configuration.d.ts} +22 -27
- package/dist/declarations/src/core/index.d.ts +7 -3
- package/dist/declarations/src/core/portal.d.ts +13 -0
- package/dist/declarations/src/core/promise.d.ts +19 -0
- package/dist/declarations/src/core/reconciler.d.ts +8 -4
- package/dist/declarations/src/core/root.d.ts +35 -0
- package/dist/declarations/src/core/utils.d.ts +4 -1
- package/dist/declarations/src/native/Canvas.d.ts +1 -1
- package/dist/declarations/src/web/Canvas.d.ts +2 -2
- package/dist/{events-b1bdeb1a.cjs.dev.js → events-21d8cd92.cjs.dev.js} +8065 -6720
- package/dist/{events-156d8d12.esm.js → events-9ce18a08.esm.js} +8051 -6707
- package/dist/{events-4c71f21f.cjs.prod.js → events-a816cbab.cjs.prod.js} +3649 -2886
- package/dist/react-three-fiber.cjs.dev.js +76 -41
- package/dist/react-three-fiber.cjs.prod.js +76 -41
- package/dist/react-three-fiber.esm.js +78 -43
- package/native/dist/react-three-fiber-native.cjs.dev.js +47 -40
- package/native/dist/react-three-fiber-native.cjs.prod.js +47 -40
- package/native/dist/react-three-fiber-native.esm.js +48 -41
- package/package.json +7 -7
- package/react-reconciler/index.d.ts +30 -13
- package/react-reconciler/index.js +79 -77
- package/readme.md +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# @react-three/fiber
|
|
2
2
|
|
|
3
|
+
## 9.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2bcc153b52213535e2149d70f6c01d7dcaee58a2: fix: keep a Canvas root alive while `<Activity>` hides it.
|
|
8
|
+
|
|
9
|
+
React destroys a hidden `<Activity>` tree's effects but keeps its DOM. The Canvas unmounted its root in that effect cleanup, which lost the WebGL context and disposed the scene. When the tree was shown again, the Canvas still held the unmounted root and stayed blank.
|
|
10
|
+
|
|
11
|
+
Canvas now keeps its renderer and scene state while hidden. A Canvas removed while hidden still releases its renderer.
|
|
12
|
+
|
|
13
|
+
- 138bfb0055a2534103686454c5e1f22bcdbf4537: Canvas and `root.configure()` now apply only the configuration props that changed. Runtime changes made through setters such as `setFrameloop`, or directly to `gl.shadowMap`, last through rerenders and resizes until their prop changes. The pixel ratio still follows `dpr` and the device pixel ratio on every render. Inline option objects compare by value. Changing `flat` or `linear` after creation now updates the renderer, unless `gl` sets `toneMapping` or `outputColorSpace` explicitly.
|
|
14
|
+
|
|
15
|
+
Configuration applies in call order, including calls made from a renderer factory or a store subscriber while another configuration is running.
|
|
16
|
+
|
|
17
|
+
- e0e9c2dbb5b9f1567f43ffe97205d29a4094028a: Update its-fine to 2.1.1 and bridge ancestor Activity visibility into the Canvas scene on React 19.2 and later. Hiding an Activity disconnects scene effects and useFrame subscriptions; revealing it reconnects them without resetting scene state. Keep the existing context and StrictMode bridges, and fall back to their previous behavior on React 19.0 and 19.1.
|
|
18
|
+
- 9ac75626b2191c65698d3bfb27c2e43d6e3c8891: fix: dispose the renderer R3F creates when its root unmounts.
|
|
19
|
+
|
|
20
|
+
Teardown only called `forceContextLoss()`, never `dispose()`. A `WebGPURenderer` built in a `gl` factory, which has no `forceContextLoss`, was never released at all: its GPU device and every allocation on it outlived the canvas. A `WebGLRenderer` lost its context while three's listener was still attached, which logged `THREE.WebGLRenderer: Context Lost.` on every unmount.
|
|
21
|
+
|
|
22
|
+
A renderer R3F builds, from its defaults, a props object or a factory, is now disposed, and then its context is lost. A renderer passed in as an instance keeps its previous teardown. Each teardown step now runs on its own, so one that throws no longer skips the rest.
|
|
23
|
+
|
|
24
|
+
- 8965ba4f05eab91c605fe0dfaaa58453c1ede7c9: Preserve an object's visibility across Activity and Suspense hiding. Visibility prop changes made while hidden take effect when the object is shown.
|
|
25
|
+
- 9ac75626b2191c65698d3bfb27c2e43d6e3c8891: Model root teardown with explicit open, closing, disposing, and disposed states. Allow pending unmounts to be cancelled, wait for React cleanups and queued configuration before disposing, and prevent disposed root handles from configuring or unmounting replacement roots. Complete teardown callbacks after asynchronous renderer disposal settles, and release the context even if renderer disposal fails.
|
|
26
|
+
|
|
27
|
+
## 9.8.0
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- 4ae2f816543f21e72b38d3e1328a21fc312428c1: Support React 19.3. Transitions that touch a `<ViewTransition>` subtree inside the canvas now commit synchronously, mirroring react-dom in browsers without view transitions, instead of leaving the reconciler stuck mid-commit.
|
|
32
|
+
- bc240cc56dbb0162737b2df0e99077c889d7cf2e: feat: configure and render roots synchronously; suspend on async renderers.
|
|
33
|
+
|
|
34
|
+
`root.configure()` now runs synchronously unless `gl` is an async factory (WebGPU), and the first `root.render()` mounts synchronously once the root is configured; later renders are batched as before. The returned promises carry a `status` field that React's `use` reads, and every root exposes `ready`, which is pending only while an async renderer is being created.
|
|
35
|
+
|
|
36
|
+
`<Canvas>` uses this to commit its scene inside its own layout effect, so `onCreated` runs while the wrapper is mounted and the events are connected before the browser paints. With an async renderer the canvas suspends on `root.ready` internally, without showing a parent fallback, and mounts once it resolves. Unmounting meanwhile never renders the scene. A renderer factory that fails now reaches the nearest error boundary instead of an unhandled rejection.
|
|
37
|
+
|
|
38
|
+
Configure calls made while another is in flight are applied after it, in order. The `flushSync` caveats apply to that first `root.render()` when it is called from inside another root's commit.
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- f0f1cdf4336519a988faadae7f8607bc0cd8d7e2: fix: unmount roots deterministically instead of after a 500ms timer.
|
|
43
|
+
|
|
44
|
+
`unmountComponentAtNode` deferred disposal by 500ms. A `<StrictMode>` remount lands inside that window and reuses the same root, store, scene and GL context, so the deferred callback destroyed a live root. `forceContextLoss()` is permanent, which left the canvas blank for the rest of the session.
|
|
45
|
+
|
|
46
|
+
Unmounting now claims the root and runs the teardown through React once the unmounted tree's effect cleanups have flushed. Using the root again through `configure` or `render` before then cancels it. A root that is unmounted, remounted and unmounted again is torn down exactly once.
|
|
47
|
+
|
|
48
|
+
- bc240cc56dbb0162737b2df0e99077c889d7cf2e: fix: don't resurrect a `<Canvas>` root that unmounts before its render settles.
|
|
49
|
+
|
|
50
|
+
`<Canvas>` configured its root asynchronously. When the canvas was unmounted between that effect and the microtasks it queued, for example by a spring reparenting it through a synchronous state update from a layout effect, the stale continuation still rendered into the torn-down root. Its Provider then mounted again and called `events.connect` with the unmounted wrapper `div`, throwing `Cannot read properties of null (reading 'addEventListener')`, and the resurrected root leaked a live WebGL context.
|
|
51
|
+
|
|
52
|
+
The scene now commits inside the canvas' own commit, a deferred render bails once the root is claimed for teardown, and `unmountComponentAtNode` waits for a configure still in flight so the renderer it creates is disposed rather than orphaned.
|
|
53
|
+
|
|
3
54
|
## 9.7.0
|
|
4
55
|
|
|
5
56
|
### Minor Changes
|
|
@@ -610,7 +610,8 @@ declare namespace ReactReconciler {
|
|
|
610
610
|
type LanePriority = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17;
|
|
611
611
|
|
|
612
612
|
type Lanes = number;
|
|
613
|
-
|
|
613
|
+
|
|
614
|
+
type Lane = number & { __LaneBrand: any };
|
|
614
615
|
|
|
615
616
|
type Flags = number;
|
|
616
617
|
|
|
@@ -941,7 +942,6 @@ declare namespace ReactReconciler {
|
|
|
941
942
|
onCaughtError: (error: Error, info: BaseErrorInfo) => void,
|
|
942
943
|
onRecoverableError: (error: Error, info: BaseErrorInfo) => void,
|
|
943
944
|
onDefaultTransitionIndicator: () => void,
|
|
944
|
-
transitionCallbacks: null | TransitionTracingCallbacks,
|
|
945
945
|
): OpaqueRoot;
|
|
946
946
|
|
|
947
947
|
createPortal(
|
|
@@ -951,8 +951,6 @@ declare namespace ReactReconciler {
|
|
|
951
951
|
key?: string | null,
|
|
952
952
|
): ReactPortal;
|
|
953
953
|
|
|
954
|
-
registerMutableSourceForHydration(root: FiberRoot, mutableSource: MutableSource): void;
|
|
955
|
-
|
|
956
954
|
createComponentSelector(component: React$AbstractComponent<never, unknown>): ComponentSelector;
|
|
957
955
|
|
|
958
956
|
createHasPseudoClassSelector(selectors: Selector[]): HasPseudoClassSelector;
|
|
@@ -987,8 +985,12 @@ declare namespace ReactReconciler {
|
|
|
987
985
|
isStrictMode: boolean,
|
|
988
986
|
concurrentUpdatesByDefaultOverride: null | boolean,
|
|
989
987
|
identifierPrefix: string,
|
|
990
|
-
|
|
988
|
+
onUncaughtError: (error: Error, info: BaseErrorInfo & { errorBoundary?: Component }) => void,
|
|
989
|
+
onCaughtError: (error: Error, info: BaseErrorInfo) => void,
|
|
990
|
+
onRecoverableError: (error: Error, info: BaseErrorInfo) => void,
|
|
991
|
+
onDefaultTransitionIndicator: () => void,
|
|
991
992
|
transitionCallbacks: null | TransitionTracingCallbacks,
|
|
993
|
+
formState: unknown,
|
|
992
994
|
): OpaqueRoot;
|
|
993
995
|
|
|
994
996
|
updateContainer(
|
|
@@ -998,17 +1000,27 @@ declare namespace ReactReconciler {
|
|
|
998
1000
|
callback?: (() => void) | null,
|
|
999
1001
|
): Lane;
|
|
1000
1002
|
|
|
1003
|
+
updateContainerSync(
|
|
1004
|
+
element: ReactNode,
|
|
1005
|
+
container: OpaqueRoot,
|
|
1006
|
+
parentComponent?: Component<any, any> | null,
|
|
1007
|
+
callback?: (() => void) | null,
|
|
1008
|
+
): Lane;
|
|
1009
|
+
|
|
1001
1010
|
batchedUpdates<A, R>(fn: (a: A) => R, a: A): R;
|
|
1002
1011
|
|
|
1003
1012
|
deferredUpdates<A>(fn: () => A): A;
|
|
1004
1013
|
|
|
1005
1014
|
discreteUpdates<A, B, C, D, R>(fn: (arg0: A, arg1: B, arg2: C, arg3: D) => R, a: A, b: B, c: C, d: D): R;
|
|
1006
1015
|
|
|
1007
|
-
flushControlled(fn: () => any): void;
|
|
1008
|
-
|
|
1009
1016
|
flushSync(): void;
|
|
1010
1017
|
flushSync<R>(fn: () => R): R;
|
|
1011
1018
|
|
|
1019
|
+
flushSyncFromReconciler(): void;
|
|
1020
|
+
flushSyncFromReconciler<R>(fn: () => R): R;
|
|
1021
|
+
|
|
1022
|
+
flushSyncWork(): boolean;
|
|
1023
|
+
|
|
1012
1024
|
isAlreadyRendering(): boolean;
|
|
1013
1025
|
|
|
1014
1026
|
flushPassiveEffects(): boolean;
|
|
@@ -1017,16 +1029,10 @@ declare namespace ReactReconciler {
|
|
|
1017
1029
|
|
|
1018
1030
|
attemptSynchronousHydration(fiber: Fiber): void;
|
|
1019
1031
|
|
|
1020
|
-
attemptDiscreteHydration(fiber: Fiber): void;
|
|
1021
|
-
|
|
1022
1032
|
attemptContinuousHydration(fiber: Fiber): void;
|
|
1023
1033
|
|
|
1024
1034
|
attemptHydrationAtCurrentPriority(fiber: Fiber): void;
|
|
1025
1035
|
|
|
1026
|
-
getCurrentUpdatePriority(): LanePriority;
|
|
1027
|
-
|
|
1028
|
-
runWithPriority<T>(priority: LanePriority, fn: () => T): T;
|
|
1029
|
-
|
|
1030
1036
|
findHostInstance(component: any): PublicInstance | null;
|
|
1031
1037
|
|
|
1032
1038
|
findHostInstanceWithWarning(component: any, methodName: string): PublicInstance | null;
|
|
@@ -1039,6 +1045,17 @@ declare namespace ReactReconciler {
|
|
|
1039
1045
|
|
|
1040
1046
|
injectIntoDevTools(devToolsConfig: DevToolsConfig<Instance, TextInstance, any>): boolean;
|
|
1041
1047
|
}
|
|
1048
|
+
|
|
1049
|
+
function defaultOnUncaughtError(error: Error): void;
|
|
1050
|
+
function defaultOnCaughtError(error: Error): void;
|
|
1051
|
+
function defaultOnRecoverableError(error: Error): void;
|
|
1052
|
+
|
|
1053
|
+
function startHostTransition(
|
|
1054
|
+
formFiber: Fiber,
|
|
1055
|
+
pendingState: unknown,
|
|
1056
|
+
action: ((formData: FormData) => void) | null,
|
|
1057
|
+
formData: FormData,
|
|
1058
|
+
): void;
|
|
1042
1059
|
}
|
|
1043
1060
|
|
|
1044
1061
|
export = ReactReconciler;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import * as THREE from 'three';
|
|
3
2
|
import type { ThreeElement } from "../three-types.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { type Properties, Camera } from "./utils.js";
|
|
3
|
+
import type { EventManager } from "./events.js";
|
|
4
|
+
import { type Dpr, type Frameloop, type Performance, type Renderer, type RootState, type RootStore, type Size } from "./store.js";
|
|
5
|
+
import { type Camera, type Properties } from "./utils.js";
|
|
8
6
|
interface OffscreenCanvas extends EventTarget {
|
|
9
7
|
}
|
|
10
|
-
export declare const _roots: Map<HTMLCanvasElement | OffscreenCanvas, Root>;
|
|
11
8
|
export type DefaultGLProps = Omit<THREE.WebGLRendererParameters, 'canvas'> & {
|
|
12
9
|
canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
13
10
|
};
|
|
@@ -29,7 +26,7 @@ export interface RenderProps<TCanvas extends HTMLCanvasElement | OffscreenCanvas
|
|
|
29
26
|
shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE.WebGLShadowMap>;
|
|
30
27
|
/**
|
|
31
28
|
* Disables three r139 color management.
|
|
32
|
-
* @see https://threejs.org/
|
|
29
|
+
* @see https://threejs.org/manual/#en/color-management
|
|
33
30
|
*/
|
|
34
31
|
legacy?: boolean;
|
|
35
32
|
/** Switch off automatic sRGB encoding and gamma correction */
|
|
@@ -63,27 +60,25 @@ export interface RenderProps<TCanvas extends HTMLCanvasElement | OffscreenCanvas
|
|
|
63
60
|
/** Response for pointer clicks that have missed any target */
|
|
64
61
|
onPointerMissed?: (event: MouseEvent) => void;
|
|
65
62
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
type Canvas = DefaultGLProps['canvas'];
|
|
64
|
+
export type Configuration = RenderProps<Canvas>;
|
|
65
|
+
/** What a root has applied, so its next configuration applies only what changed */
|
|
66
|
+
export interface AppliedConfiguration {
|
|
67
|
+
/** The last configuration applied in full */
|
|
68
|
+
previous?: Configuration;
|
|
69
|
+
/** The camera prop that set the current camera */
|
|
70
|
+
camera?: Configuration['camera'];
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
-
export declare function
|
|
73
|
-
export type InjectState = Partial<Omit<RootState, 'events'> & {
|
|
74
|
-
events?: {
|
|
75
|
-
enabled?: boolean;
|
|
76
|
-
priority?: number;
|
|
77
|
-
compute?: ComputeFunction;
|
|
78
|
-
connected?: any;
|
|
79
|
-
};
|
|
80
|
-
}>;
|
|
81
|
-
export declare function createPortal(children: React.ReactNode, container: THREE.Object3D, state?: InjectState): React.JSX.Element;
|
|
72
|
+
/** The renderer to configure, or a promise for one from an async factory */
|
|
73
|
+
export declare function createRenderer(canvas: Canvas, gl?: GLProps): Renderer | PromiseLike<Renderer>;
|
|
82
74
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
75
|
+
* Applies the inputs that changed since the last configuration applied in full, to a root whose
|
|
76
|
+
* renderer is installed. A runtime change, such as setFrameloop or an edit to gl.shadowMap, lasts
|
|
77
|
+
* until its input changes. The pixel ratio instead follows the device on every call. Objects and
|
|
78
|
+
* arrays compare shallowly, so an equal inline value is unchanged.
|
|
87
79
|
*/
|
|
88
|
-
export declare function
|
|
80
|
+
export declare function applyRootConfiguration({ store, configuration }: {
|
|
81
|
+
store: RootStore;
|
|
82
|
+
configuration: AppliedConfiguration;
|
|
83
|
+
}, canvas: Canvas, props: Configuration): void;
|
|
89
84
|
export {};
|
|
@@ -4,10 +4,14 @@ export * from "./hooks.js";
|
|
|
4
4
|
export type { GlobalRenderCallback, GlobalEffectType } from "./loop.js";
|
|
5
5
|
export { flushGlobalEffects, addEffect, addAfterEffect, addTail, invalidate, advance } from "./loop.js";
|
|
6
6
|
export type { AttachFnType, AttachType, ConstructorRepresentation, Catalogue, Args, InstanceProps, Instance, } from "./reconciler.js";
|
|
7
|
-
export { extend, reconciler } from "./reconciler.js";
|
|
8
|
-
export type {
|
|
9
|
-
export {
|
|
7
|
+
export { extend, reconciler, flushSync } from "./reconciler.js";
|
|
8
|
+
export type { GLProps, CameraProps, RenderProps } from "./configuration.js";
|
|
9
|
+
export type { ReconcilerRoot } from "./root.js";
|
|
10
|
+
export { _roots, createRoot, unmountComponentAtNode } from "./root.js";
|
|
11
|
+
export type { InjectState } from "./portal.js";
|
|
12
|
+
export { createPortal } from "./portal.js";
|
|
10
13
|
export type { Subscription, Dpr, Size, Viewport, RenderCallback, Frameloop, Performance, Renderer, XRManager, RootState, RootStore, } from "./store.js";
|
|
11
14
|
export { context } from "./store.js";
|
|
12
15
|
export type { ObjectMap, Camera, Disposable, Act } from "./utils.js";
|
|
13
16
|
export { applyProps, getRootState, dispose, act, buildGraph } from "./utils.js";
|
|
17
|
+
export type { TrackedPromise } from "./promise.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import type { ComputeFunction } from "./events.js";
|
|
4
|
+
import { type RootState } from "./store.js";
|
|
5
|
+
export type InjectState = Partial<Omit<RootState, 'events'> & {
|
|
6
|
+
events?: {
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
priority?: number;
|
|
9
|
+
compute?: ComputeFunction;
|
|
10
|
+
connected?: any;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
export declare function createPortal(children: React.ReactNode, container: THREE.Object3D, state?: InjectState): React.JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const isPromiseLike: <T>(value: T | PromiseLike<T>) => value is PromiseLike<T>;
|
|
2
|
+
/** A promise tagged with its state, the protocol React's `use` reads */
|
|
3
|
+
export type TrackedPromise<T> = Promise<T> & ({
|
|
4
|
+
status: 'pending';
|
|
5
|
+
} | {
|
|
6
|
+
status: 'fulfilled';
|
|
7
|
+
value: T;
|
|
8
|
+
} | {
|
|
9
|
+
status: 'rejected';
|
|
10
|
+
reason: unknown;
|
|
11
|
+
});
|
|
12
|
+
export declare const fulfilled: <T>(value: T) => TrackedPromise<T>;
|
|
13
|
+
export declare const rejected: <T>(reason: unknown) => TrackedPromise<T>;
|
|
14
|
+
/** A pending promise, settled once from outside. Its `status` updates the moment it settles */
|
|
15
|
+
export declare const deferred: <T>() => {
|
|
16
|
+
promise: TrackedPromise<T>;
|
|
17
|
+
resolve: (_value: T) => void;
|
|
18
|
+
reject: (_reason: unknown) => void;
|
|
19
|
+
};
|
|
@@ -5,10 +5,6 @@ import { IsAllOptional } from "./utils.js";
|
|
|
5
5
|
import type { RootStore } from "./store.js";
|
|
6
6
|
import { type EventHandlers } from "./events.js";
|
|
7
7
|
import type { ThreeElement } from "../three-types.js";
|
|
8
|
-
export interface Root {
|
|
9
|
-
fiber: Reconciler.FiberRoot;
|
|
10
|
-
store: RootStore;
|
|
11
|
-
}
|
|
12
8
|
export type AttachFnType<O = any> = (parent: any, self: O) => () => void;
|
|
13
9
|
export type AttachType<O = any> = string | AttachFnType<O>;
|
|
14
10
|
export type ConstructorRepresentation<T = any> = new (...args: any[]) => T;
|
|
@@ -42,9 +38,17 @@ export interface Instance<O = any> {
|
|
|
42
38
|
handlers: Partial<EventHandlers>;
|
|
43
39
|
attach?: AttachType<O>;
|
|
44
40
|
previousAttach?: any;
|
|
41
|
+
previousVisible: boolean | undefined;
|
|
45
42
|
isHidden: boolean;
|
|
46
43
|
}
|
|
47
44
|
export declare function extend<T extends ConstructorRepresentation>(objects: T): React.ExoticComponent<ThreeElement<T>>;
|
|
48
45
|
export declare function extend<T extends Catalogue>(objects: T): void;
|
|
49
46
|
export declare const reconciler: Reconciler.Reconciler<RootStore, Instance<any>, void, Instance<any>, never, any>;
|
|
47
|
+
/**
|
|
48
|
+
* Force React to flush any updates inside the provided callback synchronously and immediately.
|
|
49
|
+
* All the same caveats documented for react-dom's `flushSync` apply here (see https://react.dev/reference/react-dom/flushSync).
|
|
50
|
+
* Nevertheless, sometimes one needs to render synchronously, for example to keep DOM and 3D changes in lock-step without
|
|
51
|
+
* having to revert to a non-React solution. Note: this will only flush updates within the `Canvas` root.
|
|
52
|
+
*/
|
|
53
|
+
export declare function flushSync<R>(fn: () => R): R;
|
|
50
54
|
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type Reconciler from '../../react-reconciler/index.js';
|
|
3
|
+
import { type AppliedConfiguration, type RenderProps } from "./configuration.js";
|
|
4
|
+
import { type TrackedPromise } from "./promise.js";
|
|
5
|
+
import { type RootStore } from "./store.js";
|
|
6
|
+
interface OffscreenCanvas extends EventTarget {
|
|
7
|
+
}
|
|
8
|
+
export interface Root {
|
|
9
|
+
fiber: Reconciler.FiberRoot;
|
|
10
|
+
store: RootStore;
|
|
11
|
+
state: RootStateMachine;
|
|
12
|
+
/** Settles once all accepted configuration has been applied */
|
|
13
|
+
ready: TrackedPromise<unknown>;
|
|
14
|
+
configuration: AppliedConfiguration;
|
|
15
|
+
/** Whether R3F built `gl` (from defaults, props or a factory) and so disposes it on unmount */
|
|
16
|
+
ownsRenderer: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare const _roots: Map<HTMLCanvasElement | OffscreenCanvas, Root>;
|
|
19
|
+
export type RootStateMachine = {
|
|
20
|
+
status: 'open';
|
|
21
|
+
} | {
|
|
22
|
+
status: 'closing';
|
|
23
|
+
token: symbol;
|
|
24
|
+
} | {
|
|
25
|
+
status: 'disposed';
|
|
26
|
+
};
|
|
27
|
+
export interface ReconcilerRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas> {
|
|
28
|
+
ready: TrackedPromise<unknown>;
|
|
29
|
+
configure: (config?: RenderProps<TCanvas>) => TrackedPromise<ReconcilerRoot<TCanvas>>;
|
|
30
|
+
render: (element: React.ReactNode) => RootStore;
|
|
31
|
+
unmount: () => void;
|
|
32
|
+
}
|
|
33
|
+
export declare function createRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas>(canvas: TCanvas): ReconcilerRoot<TCanvas>;
|
|
34
|
+
export declare function unmountComponentAtNode<TCanvas extends HTMLCanvasElement | OffscreenCanvas>(canvas: TCanvas, callback?: (canvas: TCanvas) => void): void;
|
|
35
|
+
export {};
|
|
@@ -39,11 +39,14 @@ export declare const isColorRepresentation: (value: unknown) => value is THREE.C
|
|
|
39
39
|
*/
|
|
40
40
|
export declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
|
|
41
41
|
export declare function useMutableCallback<T>(fn: T): React.RefObject<T>;
|
|
42
|
+
export declare const noop: () => void;
|
|
43
|
+
/** Waits for a promise in a null subtree, re-rendering the caller once it settles either way. */
|
|
44
|
+
export declare function useGate(): [gate: React.ReactNode, waitFor: (promise: PromiseLike<unknown>) => void];
|
|
42
45
|
export type Bridge = React.FC<{
|
|
43
46
|
children?: React.ReactNode;
|
|
44
47
|
}>;
|
|
45
48
|
/**
|
|
46
|
-
* Bridges
|
|
49
|
+
* Bridges Context, StrictMode, and Activity visibility from a primary renderer.
|
|
47
50
|
*/
|
|
48
51
|
export declare function useBridge(): Bridge;
|
|
49
52
|
export type SetBlock = false | Promise<null> | null;
|
|
@@ -10,4 +10,4 @@ export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'size'
|
|
|
10
10
|
* A native canvas which accepts threejs elements as children.
|
|
11
11
|
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
12
12
|
*/
|
|
13
|
-
export declare function Canvas(props: CanvasProps):
|
|
13
|
+
export declare function Canvas(props: CanvasProps): React.JSX.Element;
|
|
@@ -12,7 +12,7 @@ export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'size'
|
|
|
12
12
|
*/
|
|
13
13
|
resize?: ResizeOptions;
|
|
14
14
|
/** The target where events are being subscribed to, default: the div that wraps canvas */
|
|
15
|
-
eventSource?: HTMLElement | React.RefObject<HTMLElement>;
|
|
15
|
+
eventSource?: HTMLElement | React.RefObject<HTMLElement | null>;
|
|
16
16
|
/** The event prefix that is cast into canvas pointer x/y events, default: "offset" */
|
|
17
17
|
eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen';
|
|
18
18
|
}
|
|
@@ -20,4 +20,4 @@ export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'size'
|
|
|
20
20
|
* A DOM canvas which accepts threejs elements as children.
|
|
21
21
|
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
22
22
|
*/
|
|
23
|
-
export declare function Canvas(props: CanvasProps):
|
|
23
|
+
export declare function Canvas(props: CanvasProps): React.JSX.Element;
|