@octanejs/three 0.1.57 → 0.1.59

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octanejs/three",
3
- "version": "0.1.57",
3
+ "version": "0.1.59",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@types/three": ">=0.156.0",
53
- "octane": "^0.12.0",
53
+ "octane": "^0.13.0",
54
54
  "three": ">=0.156.0"
55
55
  },
56
56
  "peerDependenciesMeta": {
@@ -59,16 +59,16 @@
59
59
  }
60
60
  },
61
61
  "devDependencies": {
62
- "@octanejs/rsbuild-plugin": "0.1.63",
63
- "@octanejs/rspack-plugin": "0.2.2",
64
- "@octanejs/vite-plugin": "0.3.3",
62
+ "@octanejs/rsbuild-plugin": "0.1.65",
63
+ "@octanejs/rspack-plugin": "0.2.4",
64
+ "@octanejs/vite-plugin": "0.4.1",
65
65
  "@react-three/fiber": "9.6.1",
66
66
  "@rsbuild/core": "^2.1.6",
67
67
  "@rspack/core": "^2.1.4",
68
68
  "@tsrx/react": "^0.4.5",
69
69
  "@types/three": "0.172.0",
70
70
  "esbuild": "^0.28.1",
71
- "octane": "0.12.0",
71
+ "octane": "0.13.8",
72
72
  "playwright": "^1.61.1",
73
73
  "react": "19.2.7",
74
74
  "react-dom": "19.2.7",
package/src/core/hooks.ts CHANGED
@@ -1,3 +1,5 @@
1
+ 'use strong';
2
+
1
3
  /**
2
4
  * Canvas-scoped hooks and graph helpers for the Octane Three renderer.
3
5
  *
package/src/core/loop.ts CHANGED
@@ -1,3 +1,5 @@
1
+ 'use strong';
2
+
1
3
  import type { RenderCallback, RootState, RootStore, Subscription } from './store.js';
2
4
 
3
5
  export type GlobalRenderCallback = (timestamp: number) => void;
package/src/core/root.ts CHANGED
@@ -5,6 +5,8 @@
5
5
  * owns only renderer construction, R3F-shaped root state, the Three host
6
6
  * container, and the configuration barrier before a scene may render.
7
7
  */
8
+ 'use strong';
9
+
8
10
  import * as THREE from 'three';
9
11
  import {
10
12
  defineUniversalComponent,
package/src/core/store.ts CHANGED
@@ -5,6 +5,8 @@
5
5
  * built on Octane's universal hooks so it is safe inside `*.three.tsrx`
6
6
  * components. Zustand remains the framework-neutral storage primitive.
7
7
  */
8
+ 'use strong';
9
+
8
10
  import * as THREE from 'three';
9
11
  import { useContext, useRef, useSyncExternalStore, withSlot } from 'octane/universal';
10
12
  import { createContext } from 'octane/universal/native';
@@ -1,4 +1,13 @@
1
- import { useInsertionEffect, useLayoutEffect, useRef, useState } from 'octane';
1
+ 'use strong';
2
+
3
+ import {
4
+ useEffectEvent,
5
+ useInsertionEffect,
6
+ useLayoutEffect,
7
+ useLayoutSnapshot,
8
+ useRef,
9
+ useState,
10
+ } from 'octane';
2
11
  import type { OctaneNode } from 'octane';
3
12
  import { createUniversalHostBoundary } from 'octane/universal';
4
13
  import type { RendererRegion } from 'octane/universal';
@@ -90,12 +99,11 @@ function createPrefixCompute(prefix: EventPrefix): ComputeFunction {
90
99
  function bindCanvasEvents(
91
100
  state: RootState,
92
101
  source: CanvasProps['eventSource'],
93
- wrapper: HTMLDivElement | null,
102
+ target: HTMLElement | null,
94
103
  prefix: EventPrefix | undefined,
95
104
  binding: CanvasEventBinding,
96
105
  ): void {
97
106
  let current = state.get();
98
- const target = resolveEventSource(source, wrapper);
99
107
  if (!binding.initialized || binding.source !== source || binding.target !== target) {
100
108
  binding.source = source;
101
109
  binding.target = target;
@@ -149,40 +157,48 @@ export function Canvas({
149
157
  onPointerMissed,
150
158
  onCreated,
151
159
  ...domProps
152
- }: CanvasProps) {
160
+ }: CanvasProps) @{
153
161
  const wrapperRef = useRef<HTMLDivElement | null>(null);
154
162
  const canvasRef = useRef<HTMLCanvasElement | null>(null);
155
163
  const rootRef = useRef<ThreeRoot<HTMLCanvasElement> | null>(null);
156
- const eventSourceRef = useRef<CanvasProps['eventSource']>(eventSource);
157
- const eventPrefixRef = useRef<EventPrefix | undefined>(eventPrefix);
158
- const onCreatedRef = useRef(onCreated);
159
- const onPointerMissedRef = useRef(onPointerMissed);
160
164
  const eventBindingRef = useRef<CanvasEventBinding>({ initialized: false });
161
- const createdHandlerRef = useRef<((state: RootState) => void) | null>(null);
162
- const pointerMissedHandlerRef = useRef<((event: MouseEvent) => void) | null>(null);
163
165
  const [size, setSize] = useState<Size | null>(null);
164
166
  const [boundaryMount, setBoundaryMount] = useState<ThreeBoundaryMount | null>(null);
165
167
  const [error, setError] = useState<Error | null>(null);
166
- const eventTarget = resolveEventSource(eventSource, wrapperRef.current);
167
- eventSourceRef.current = eventSource;
168
- eventPrefixRef.current = eventPrefix;
169
- onCreatedRef.current = onCreated;
170
- onPointerMissedRef.current = onPointerMissed;
171
- if (createdHandlerRef.current === null) {
172
- createdHandlerRef.current = (state) => {
173
- bindCanvasEvents(
174
- state,
175
- eventSourceRef.current,
176
- wrapperRef.current,
177
- eventPrefixRef.current,
178
- eventBindingRef.current,
179
- );
180
- onCreatedRef.current?.(state.get());
181
- };
182
- }
183
- if (pointerMissedHandlerRef.current === null) {
184
- pointerMissedHandlerRef.current = (event) => onPointerMissedRef.current?.(event);
185
- }
168
+ const [initialEventSource] = useState(() => ({
169
+ source: eventSource,
170
+ target: resolveEventSource(eventSource, null),
171
+ prefix: eventPrefix,
172
+ }));
173
+ const eventSnapshot = useLayoutSnapshot(
174
+ () => {
175
+ const wrapper = wrapperRef.current;
176
+ const target = resolveEventSource(eventSource, wrapper);
177
+ return {
178
+ source: eventSource,
179
+ target: target === wrapper ? null : target,
180
+ prefix: eventPrefix,
181
+ };
182
+ },
183
+ {
184
+ initial: initialEventSource,
185
+ equal: (previous, next) =>
186
+ previous.source === next.source &&
187
+ previous.target === next.target &&
188
+ previous.prefix === next.prefix,
189
+ },
190
+ );
191
+ const handleCreated = useEffectEvent((state: RootState) => {
192
+ bindCanvasEvents(
193
+ state,
194
+ eventSource,
195
+ resolveEventSource(eventSource, wrapperRef.current),
196
+ eventPrefix,
197
+ eventBindingRef.current,
198
+ );
199
+ onCreated?.(state.get());
200
+ });
201
+ const handlePointerMissed = useEffectEvent((event: MouseEvent) => onPointerMissed?.(event));
186
202
 
187
203
  if (error !== null) throw error;
188
204
 
@@ -192,7 +208,7 @@ export function Canvas({
192
208
  return observeCanvasSize(wrapper, resize ?? DEFAULT_RESIZE_OPTIONS, (next) => {
193
209
  setSize((previous) => (sameSize(previous, next) ? previous : next));
194
210
  });
195
- }, [resize]);
211
+ });
196
212
 
197
213
  // A DOM Suspense or Activity boundary disconnects layout effects while its
198
214
  // content is hidden. Root ownership must survive that retained state and
@@ -203,7 +219,7 @@ export function Canvas({
203
219
  rootRef.current = null;
204
220
  root?.unmount();
205
221
  };
206
- }, []);
222
+ });
207
223
 
208
224
  useLayoutEffect(() => {
209
225
  const canvas = canvasRef.current;
@@ -230,10 +246,8 @@ export function Canvas({
230
246
  raycaster,
231
247
  camera,
232
248
  scene,
233
- // Both handlers were lazily created during render; the `| null` only
234
- // survives because TS cannot carry the narrowing into this closure.
235
- onPointerMissed: pointerMissedHandlerRef.current ?? undefined,
236
- onCreated: createdHandlerRef.current ?? undefined,
249
+ onPointerMissed: handlePointerMissed,
250
+ onCreated: handleCreated,
237
251
  size,
238
252
  })
239
253
  .then(() => {
@@ -246,36 +260,21 @@ export function Canvas({
246
260
  return () => {
247
261
  cancelled = true;
248
262
  };
249
- }, [
250
- size,
251
- gl,
252
- events,
253
- shadows,
254
- linear,
255
- flat,
256
- legacy,
257
- orthographic,
258
- frameloop,
259
- dpr,
260
- performance,
261
- raycaster,
262
- camera,
263
- scene,
264
- ]);
263
+ });
265
264
 
266
- // A stable ref object can receive a new current target during commit. Recheck after every
267
- // render; bindCanvasEvents avoids reconnecting when the resolved target is unchanged.
265
+ // The layout snapshot observes stable ref objects whose target changes during commit.
266
+ // Initialization belongs to onCreated, which may choose its own event connection.
268
267
  useLayoutEffect(() => {
269
268
  const root = rootRef.current;
270
- if (boundaryMount === null || root === null) return;
269
+ if (root === null || !eventBindingRef.current.initialized) return;
271
270
  bindCanvasEvents(
272
271
  root.store.getState(),
273
- eventSource,
274
- wrapperRef.current,
275
- eventPrefix,
272
+ eventSnapshot.source,
273
+ eventSnapshot.target ?? wrapperRef.current,
274
+ eventSnapshot.prefix,
276
275
  eventBindingRef.current,
277
276
  );
278
- }, null);
277
+ });
279
278
 
280
279
  const renderedBoundaryMount: ThreeBoundaryMount | null =
281
280
  boundaryMount === null
@@ -292,28 +291,26 @@ export function Canvas({
292
291
  width: '100%',
293
292
  height: '100%',
294
293
  overflow: 'hidden',
295
- pointerEvents: eventTarget === wrapperRef.current ? 'auto' : 'none',
294
+ pointerEvents: eventSnapshot.target === null ? 'auto' : 'none',
296
295
  ...style,
297
296
  };
298
297
 
299
- return (
300
- <div
301
- ref={wrapperRef}
302
- style={wrapperStyle}
303
- {...(domProps as typeof domProps & { ref?: undefined })}
304
- >
305
- <div style={{ width: '100%', height: '100%' }}>
306
- <canvas ref={[canvasRef, ref]} style={{ display: 'block' }}>
307
- {fallback}
308
- </canvas>
309
- </div>
310
- {renderedBoundaryMount === null ? null : (
311
- <ThreeBoundary
312
- root={renderedBoundaryMount.root}
313
- component={renderedBoundaryMount.component}
314
- props={renderedBoundaryMount.props}
315
- />
316
- )}
298
+ <div
299
+ ref={wrapperRef}
300
+ style={wrapperStyle}
301
+ {...(domProps as typeof domProps & { ref?: undefined })}
302
+ >
303
+ <div style={{ width: '100%', height: '100%' }}>
304
+ <canvas ref={[canvasRef, ref]} style={{ display: 'block' }}>
305
+ {fallback}
306
+ </canvas>
317
307
  </div>
318
- );
308
+ @if (renderedBoundaryMount !== null) {
309
+ <ThreeBoundary
310
+ root={renderedBoundaryMount.root}
311
+ component={renderedBoundaryMount.component}
312
+ props={renderedBoundaryMount.props}
313
+ />
314
+ }
315
+ </div>
319
316
  }