@react-three/fiber 10.0.0-canary.f75fbf6 → 10.0.0-canary.fbc659b

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.
Files changed (36) hide show
  1. package/dist/extension.cjs +8 -8
  2. package/dist/extension.d.cts +4 -4
  3. package/dist/extension.d.mts +4 -4
  4. package/dist/extension.d.ts +4 -4
  5. package/dist/extension.mjs +1 -1
  6. package/dist/index.cjs +14 -15
  7. package/dist/index.d.cts +11 -10
  8. package/dist/index.d.mts +11 -10
  9. package/dist/index.d.ts +11 -10
  10. package/dist/index.mjs +4 -5
  11. package/dist/legacy.cjs +37 -15
  12. package/dist/legacy.d.cts +10 -7
  13. package/dist/legacy.d.mts +10 -7
  14. package/dist/legacy.d.ts +10 -7
  15. package/dist/legacy.mjs +13 -5
  16. package/dist/shared/{fiber.BgxhptM_.mjs → fiber.BdIbKbh7.mjs} +2066 -1497
  17. package/dist/shared/{fiber.B0oukOFO.mjs → fiber.Biz9olEe.mjs} +181 -64
  18. package/dist/shared/{fiber.BcX0-yko.d.mts → fiber.C6hitYDY.d.cts} +1 -1
  19. package/dist/shared/{fiber.Dh8K6RJr.d.cts → fiber.C_MFx7We.d.cts} +472 -20
  20. package/dist/shared/{fiber.Dh8K6RJr.d.mts → fiber.C_MFx7We.d.mts} +472 -20
  21. package/dist/shared/{fiber.Dh8K6RJr.d.ts → fiber.C_MFx7We.d.ts} +472 -20
  22. package/dist/shared/{fiber.DH-VJXM_.d.ts → fiber.CtivZ3IY.d.ts} +89 -464
  23. package/dist/shared/{fiber.cO-9hDzr.d.cts → fiber.CvlK0a1Z.d.mts} +89 -464
  24. package/dist/shared/{fiber.BgP4izaL.d.cts → fiber.D4fD6H74.d.mts} +1 -1
  25. package/dist/shared/{fiber.khFlPHPf.cjs → fiber.DfiCufha.cjs} +186 -62
  26. package/dist/shared/{fiber.AN9kOS0N.d.mts → fiber.VTTQNnlj.d.cts} +89 -464
  27. package/dist/shared/{fiber.BIhZnMzg.d.ts → fiber.YgTUGbja.d.ts} +1 -1
  28. package/dist/shared/{fiber.EDf0d92E.cjs → fiber.nDnBf1np.cjs} +2092 -1523
  29. package/dist/webgpu/index.cjs +13 -13
  30. package/dist/webgpu/index.d.cts +12 -6
  31. package/dist/webgpu/index.d.mts +12 -6
  32. package/dist/webgpu/index.d.ts +12 -6
  33. package/dist/webgpu/index.mjs +4 -4
  34. package/package.json +3 -3
  35. package/dist/chunks/webgl.cjs +0 -27
  36. package/dist/chunks/webgl.mjs +0 -11
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { useContext } from 'react';
3
3
  import { jsx } from 'react/jsx-runtime';
4
- import { useFiber, useContextBridge, traverseFiber } from 'its-fine';
4
+ import { useFiber, useContextBridge, useActivityBridge as useActivityBridge$1, traverseFiber } from 'its-fine';
5
5
  import { getScheduler } from '@pmndrs/scheduler';
6
6
 
7
7
  var __defProp = Object.defineProperty;
@@ -13,16 +13,18 @@ function useMutableCallback(fn) {
13
13
  useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
14
14
  return ref;
15
15
  }
16
+ const useActivityBridge = React["Activity"] ? useActivityBridge$1 : () => React.Fragment;
16
17
  function useBridge() {
17
18
  const fiber = useFiber();
18
19
  const ContextBridge = useContextBridge();
20
+ const ActivityBridge = useActivityBridge();
19
21
  return React.useMemo(
20
22
  () => ({ children }) => {
21
23
  const strict = !!traverseFiber(fiber, true, (node) => node.type === React.StrictMode);
22
24
  const Root = strict ? React.StrictMode : React.Fragment;
23
- return /* @__PURE__ */ jsx(Root, { children: /* @__PURE__ */ jsx(ContextBridge, { children }) });
25
+ return /* @__PURE__ */ jsx(Root, { children: /* @__PURE__ */ jsx(ActivityBridge, { children: /* @__PURE__ */ jsx(ContextBridge, { children }) }) });
24
26
  },
25
- [fiber, ContextBridge]
27
+ [fiber, ContextBridge, ActivityBridge]
26
28
  );
27
29
  }
28
30
  function Block({ set }) {
@@ -47,6 +49,23 @@ const ErrorBoundary = /* @__PURE__ */ (() => {
47
49
  }
48
50
  }, __publicField(_a, "getDerivedStateFromError", () => ({ error: true })), _a;
49
51
  })();
52
+ const noop = () => {
53
+ };
54
+ function Gate({ promise, onSettled }) {
55
+ React.use(promise);
56
+ useIsomorphicLayoutEffect(onSettled, [onSettled]);
57
+ return null;
58
+ }
59
+ function useGate() {
60
+ const [promise, setPromise] = React.useState(null);
61
+ const onSettled = React.useCallback(() => setPromise(null), []);
62
+ const waitFor = React.useCallback(
63
+ (next) => setPromise((current) => current ?? Promise.resolve(next).then(noop, noop)),
64
+ []
65
+ );
66
+ const gate = promise ? /* @__PURE__ */ jsx(React.Suspense, { fallback: null, children: /* @__PURE__ */ jsx(Gate, { promise, onSettled }) }) : null;
67
+ return [gate, waitFor];
68
+ }
50
69
 
51
70
  const shownNotices = /* @__PURE__ */ new Set();
52
71
  function notifyDepreciated({ heading, body, link }) {
@@ -104,10 +123,160 @@ function notifyAlpha({ message, link }) {
104
123
  console.log(`%cMore info: ${link}`, "color: #6366f1; font-weight: normal;");
105
124
  }
106
125
  }
126
+ function isDevelopment() {
127
+ try {
128
+ return process.env.NODE_ENV !== "production";
129
+ } catch {
130
+ return true;
131
+ }
132
+ }
133
+
134
+ const INTERNAL_LIB_MARKERS = [
135
+ "zustand",
136
+ "setState",
137
+ "Object.assign",
138
+ "@pmndrs/scheduler",
139
+ "Scheduler.tickRoot",
140
+ "Scheduler.stepJob"
141
+ ];
142
+ function isInternalRendererAccess(stack, callerDepth = 2) {
143
+ if (!stack) return false;
144
+ const caller = stack.split("\n")[callerDepth] ?? "";
145
+ return INTERNAL_LIB_MARKERS.some((m) => caller.includes(m));
146
+ }
147
+
148
+ const isAccessorDescriptor = (descriptor) => !!descriptor && (descriptor.get !== void 0 || descriptor.set !== void 0);
149
+ const isAccessor = (object, key) => isAccessorDescriptor(Object.getOwnPropertyDescriptor(object, key));
150
+ function cloneState(...sources) {
151
+ const target = {};
152
+ for (const source of sources) {
153
+ if (source) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
154
+ }
155
+ return target;
156
+ }
157
+ function preserveAccessors(rawSet, get) {
158
+ return ((partial, replace) => {
159
+ const previous = get();
160
+ const patch = typeof partial === "function" ? partial(previous) : partial;
161
+ if (replace || !previous || patch == null || Object.is(patch, previous)) {
162
+ return rawSet(patch, replace);
163
+ }
164
+ const next = cloneState(previous);
165
+ const viaSetter = [];
166
+ for (const key of Reflect.ownKeys(patch)) {
167
+ const descriptor = Object.getOwnPropertyDescriptor(patch, key);
168
+ if (!descriptor.enumerable) continue;
169
+ if (isAccessorDescriptor(descriptor)) {
170
+ Object.defineProperty(next, key, descriptor);
171
+ } else if (isAccessor(next, key)) {
172
+ viaSetter.push(key);
173
+ } else {
174
+ Object.defineProperty(next, key, {
175
+ value: descriptor.value,
176
+ writable: true,
177
+ enumerable: true,
178
+ configurable: true
179
+ });
180
+ }
181
+ }
182
+ for (const key of viaSetter) next[key] = patch[key];
183
+ rawSet(next, true);
184
+ });
185
+ }
186
+ const keepAccessors = (initializer) => (rawSet, get, api) => {
187
+ const set = preserveAccessors(rawSet, get);
188
+ api.setState = set;
189
+ return initializer(set, get, api);
190
+ };
191
+ let glNoticeShown = false;
192
+ function defineRendererAccessors(state) {
193
+ Object.defineProperty(state, "gl", {
194
+ get() {
195
+ const renderer = this.internal?.actualRenderer;
196
+ if (!glNoticeShown && renderer && !this.isLegacy) {
197
+ const stack = new Error().stack || "";
198
+ if (!isInternalRendererAccess(stack)) {
199
+ glNoticeShown = true;
200
+ const cleanedStack = stack.split("\n").slice(2).join("\n") || "Stack trace unavailable";
201
+ notifyDepreciated({
202
+ heading: "Accessing state.gl in WebGPU mode",
203
+ body: "Please use state.renderer instead. state.gl is deprecated and will be removed in future versions.\n\nFor backwards compatibility, state.gl currently maps to state.renderer, but this may cause issues with libraries expecting WebGLRenderer.\n\nAccessed from:\n" + cleanedStack
204
+ });
205
+ }
206
+ }
207
+ return renderer;
208
+ },
209
+ set(value) {
210
+ this.internal.actualRenderer = value;
211
+ },
212
+ enumerable: true,
213
+ configurable: true
214
+ });
215
+ Object.defineProperty(state, "renderer", {
216
+ get() {
217
+ return this.internal?.actualRenderer;
218
+ },
219
+ set(value) {
220
+ this.internal.actualRenderer = value;
221
+ },
222
+ enumerable: true,
223
+ configurable: true
224
+ });
225
+ }
107
226
 
108
227
  const R3F_CONTEXT = Symbol.for("@react-three/fiber.context");
109
228
  const context = globalThis[R3F_CONTEXT] ?? (globalThis[R3F_CONTEXT] = React.createContext(null));
110
229
 
230
+ const R3F_EXTENSIONS = Symbol.for("@react-three/fiber.extensions");
231
+ function getRegistry() {
232
+ return globalThis[R3F_EXTENSIONS] ?? (globalThis[R3F_EXTENSIONS] = {
233
+ extensions: /* @__PURE__ */ new Map(),
234
+ roots: /* @__PURE__ */ new Set(),
235
+ applied: /* @__PURE__ */ new WeakMap()
236
+ });
237
+ }
238
+ function setupRoot(registry, store, extension) {
239
+ let applied = registry.applied.get(store);
240
+ if (!applied) registry.applied.set(store, applied = /* @__PURE__ */ new Map());
241
+ if (applied.has(extension.name)) return;
242
+ applied.set(extension.name, extension);
243
+ const patch = extension.setup?.(store);
244
+ if (patch) store.setState(patch);
245
+ }
246
+ function registerRootExtension(extension) {
247
+ const registry = getRegistry();
248
+ registry.extensions.set(extension.name, extension);
249
+ for (const store of registry.roots) setupRoot(registry, store, extension);
250
+ return () => {
251
+ if (registry.extensions.get(extension.name) === extension) registry.extensions.delete(extension.name);
252
+ };
253
+ }
254
+ function setRenderOverride(store, render) {
255
+ store.getState().internal.renderOverride = render;
256
+ }
257
+ function attachRootExtensions(store) {
258
+ const registry = getRegistry();
259
+ registry.roots.add(store);
260
+ for (const extension of registry.extensions.values()) setupRoot(registry, store, extension);
261
+ }
262
+ function current(registry, setUpBy) {
263
+ return registry.extensions.get(setUpBy.name) ?? setUpBy;
264
+ }
265
+ function detachRootExtensions(store) {
266
+ const registry = getRegistry();
267
+ if (!registry.roots.delete(store)) return;
268
+ const applied = registry.applied.get(store);
269
+ registry.applied.delete(store);
270
+ if (!applied) return;
271
+ for (const setUpBy of applied.values()) current(registry, setUpBy).dispose?.(store);
272
+ }
273
+ function notifyRootExtensionsHmr(store) {
274
+ const registry = getRegistry();
275
+ const applied = registry.applied.get(store);
276
+ if (!applied) return;
277
+ for (const setUpBy of applied.values()) current(registry, setUpBy).hmr?.(store);
278
+ }
279
+
111
280
  function useStore() {
112
281
  const store = useContext(context);
113
282
  if (!store) throw new Error("R3F: Hooks can only be used within the Canvas component!");
@@ -134,8 +303,8 @@ function useFrame(callback, priorityOrOptions) {
134
303
  const options = React.useMemo(() => {
135
304
  return typeof priorityOrOptions === "number" ? { priority: priorityOrOptions } : priorityOrOptions ?? {};
136
305
  }, [optionsKey]);
137
- const reactId = React.useId();
138
- const id = options.id ?? reactId;
306
+ const [generatedId] = React.useState(() => scheduler.generateJobId());
307
+ const id = options.id ?? generatedId;
139
308
  const callbackRef = useMutableCallback(callback);
140
309
  const isLegacyPriority = typeof priorityOrOptions === "number" && priorityOrOptions > 0;
141
310
  const isLegacyOrdering = typeof priorityOrOptions === "number" && priorityOrOptions < 0;
@@ -166,14 +335,12 @@ function useFrame(callback, priorityOrOptions) {
166
335
  });
167
336
  }
168
337
  const wrappedCallback = (frameState, delta) => {
169
- const localState = store.getState();
170
- const mergedState = {
171
- ...localState,
172
- time: frameState.time,
173
- delta: frameState.delta,
174
- elapsed: frameState.elapsed,
175
- frame: frameState.frame
176
- };
338
+ const mergedState = cloneState(store.getState());
339
+ mergedState.time = frameState.time;
340
+ mergedState.delta = frameState.delta;
341
+ mergedState.elapsed = frameState.elapsed;
342
+ mergedState.frame = frameState.frame;
343
+ mergedState.overstep = frameState.overstep;
177
344
  callbackRef.current?.(mergedState, delta);
178
345
  };
179
346
  const unregister = scheduler.register(wrappedCallback, {
@@ -311,54 +478,4 @@ function getTextureView(store) {
311
478
  return view;
312
479
  }
313
480
 
314
- const R3F_EXTENSIONS = Symbol.for("@react-three/fiber.extensions");
315
- function getRegistry() {
316
- return globalThis[R3F_EXTENSIONS] ?? (globalThis[R3F_EXTENSIONS] = {
317
- extensions: /* @__PURE__ */ new Map(),
318
- roots: /* @__PURE__ */ new Set(),
319
- applied: /* @__PURE__ */ new WeakMap()
320
- });
321
- }
322
- function setupRoot(registry, store, extension) {
323
- let applied = registry.applied.get(store);
324
- if (!applied) registry.applied.set(store, applied = /* @__PURE__ */ new Map());
325
- if (applied.has(extension.name)) return;
326
- applied.set(extension.name, extension);
327
- const patch = extension.setup?.(store);
328
- if (patch) store.setState(patch);
329
- }
330
- function registerRootExtension(extension) {
331
- const registry = getRegistry();
332
- registry.extensions.set(extension.name, extension);
333
- for (const store of registry.roots) setupRoot(registry, store, extension);
334
- return () => {
335
- if (registry.extensions.get(extension.name) === extension) registry.extensions.delete(extension.name);
336
- };
337
- }
338
- function setRenderOverride(store, render) {
339
- store.getState().internal.renderOverride = render;
340
- }
341
- function attachRootExtensions(store) {
342
- const registry = getRegistry();
343
- registry.roots.add(store);
344
- for (const extension of registry.extensions.values()) setupRoot(registry, store, extension);
345
- }
346
- function current(registry, setUpBy) {
347
- return registry.extensions.get(setUpBy.name) ?? setUpBy;
348
- }
349
- function detachRootExtensions(store) {
350
- const registry = getRegistry();
351
- if (!registry.roots.delete(store)) return;
352
- const applied = registry.applied.get(store);
353
- registry.applied.delete(store);
354
- if (!applied) return;
355
- for (const setUpBy of applied.values()) current(registry, setUpBy).dispose?.(store);
356
- }
357
- function notifyRootExtensionsHmr(store) {
358
- const registry = getRegistry();
359
- const applied = registry.applied.get(store);
360
- if (!applied) return;
361
- for (const setUpBy of applied.values()) current(registry, setUpBy).hmr?.(store);
362
- }
363
-
364
- export { Block as B, ErrorBoundary as E, useThree as a, useFrame as b, context as c, useIsomorphicLayoutEffect as d, useMutableCallback as e, useBridge as f, getTextureView as g, unstageTextures as h, stageTextures as i, detachRootExtensions as j, attachRootExtensions as k, notifyAlpha as l, notifyRootExtensionsHmr as m, notifyDepreciated as n, registerRootExtension as r, setRenderOverride as s, useStore as u };
481
+ export { Block as B, ErrorBoundary as E, useThree as a, useFrame as b, context as c, useIsomorphicLayoutEffect as d, useMutableCallback as e, useBridge as f, getTextureView as g, defineRendererAccessors as h, isDevelopment as i, detachRootExtensions as j, attachRootExtensions as k, unstageTextures as l, stageTextures as m, notifyDepreciated as n, isAccessor as o, preserveAccessors as p, cloneState as q, registerRootExtension as r, setRenderOverride as s, keepAccessors as t, useStore as u, useGate as v, notifyAlpha as w, notifyRootExtensionsHmr as x };
@@ -1,4 +1,4 @@
1
- import { a3 as FrameNextCallback } from './fiber.Dh8K6RJr.mjs';
1
+ import { aO as FrameNextCallback } from './fiber.C_MFx7We.cjs';
2
2
  import { UseFrameNextOptions, FrameNextControls } from '@pmndrs/scheduler';
3
3
 
4
4
  /**