@chestnutlabs/gcode-preview-react 0.20.0 → 0.20.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.
@@ -1 +1 @@
1
- {"version":3,"file":"use-model-viewer.d.ts","sourceRoot":"","sources":["../../src/model/use-model-viewer.ts"],"names":[],"mappings":"AAQA,OAAO,EAGL,KAAK,6BAA6B,EAClC,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACpB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,YAAY,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,CAAC;AAC1F,MAAM,MAAM,qBAAqB,GAAG,6BAA6B,CAAC;AAElE,MAAM,WAAW,iBAAiB;IAChC,2EAA2E;IAC3E,SAAS,EAAE,CAAC,EAAE,EAAE,iBAAiB,GAAG,IAAI,KAAK,IAAI,CAAC;IAClD,+EAA+E;IAC/E,SAAS,EAAE,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAC7C,6EAA6E;IAC7E,OAAO,CAAC,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,mEAAmE;IACnE,KAAK,EAAE,iBAAiB,CAAC;IACzB,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,WAAW,GAAG,IAAI,CAAA;KAAE,CAAC;IAC1C,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,gBAAgB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACvD,OAAO,IAAI,IAAI,CAAC;CACjB;AAQD,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,iBAAiB,CA+CrF"}
1
+ {"version":3,"file":"use-model-viewer.d.ts","sourceRoot":"","sources":["../../src/model/use-model-viewer.ts"],"names":[],"mappings":"AAQA,OAAO,EAGL,KAAK,6BAA6B,EAClC,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACpB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,YAAY,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,CAAC;AAC1F,MAAM,MAAM,qBAAqB,GAAG,6BAA6B,CAAC;AAElE,MAAM,WAAW,iBAAiB;IAChC,2EAA2E;IAC3E,SAAS,EAAE,CAAC,EAAE,EAAE,iBAAiB,GAAG,IAAI,KAAK,IAAI,CAAC;IAClD,+EAA+E;IAC/E,SAAS,EAAE,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAC7C,6EAA6E;IAC7E,OAAO,CAAC,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,mEAAmE;IACnE,KAAK,EAAE,iBAAiB,CAAC;IACzB,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,WAAW,GAAG,IAAI,CAAA;KAAE,CAAC;IAC1C,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,gBAAgB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACvD,OAAO,IAAI,IAAI,CAAC;CACjB;AAQD,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,iBAAiB,CAgErF"}
@@ -5,7 +5,7 @@
5
5
  * — never a separate viewer implementation (the D1 drift firewall). Shared contracts are re-exported
6
6
  * from the controller.
7
7
  */
8
- import { useCallback, useMemo, useRef, useSyncExternalStore } from 'react';
8
+ import { useCallback, useEffect, useMemo, useRef, useSyncExternalStore } from 'react';
9
9
  import { createModelPreviewController } from '@chestnutlabs/gcode-model-renderer';
10
10
  export function useModelViewer(options = {}) {
11
11
  const optionsRef = useRef(options);
@@ -24,6 +24,22 @@ export function useModelViewer(options = {}) {
24
24
  const subscribe = useCallback((cb) => ensure().onStateChange(() => cb()), [ensure]);
25
25
  const getSnapshot = useCallback(() => ensure().getState(), [ensure]);
26
26
  const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
27
+ // Own the controller's lifecycle: (re)create on mount (StrictMode's second setup lands here) and
28
+ // DISPOSE on unmount. Without this the GL engine was freed via the canvas-ref-null path but the
29
+ // controller was never disposed, so in-flight setSource promises never settled and the controller
30
+ // leaked — the toolpath hook already does this; the model hook must match.
31
+ useEffect(() => {
32
+ const c = ensure();
33
+ // Refs attach BEFORE StrictMode's dispose/recreate cycle: rebind the delivered canvas to the fresh
34
+ // controller (refs never re-fire) so it renders again after a remount.
35
+ if (slot.current.canvas !== null && c.raw.viewer() === null) {
36
+ c.bindCanvas(slot.current.canvas);
37
+ }
38
+ return () => {
39
+ slot.current.controller?.dispose();
40
+ slot.current.disposed = true;
41
+ };
42
+ }, [ensure]);
27
43
  const stateRef = useRef(state);
28
44
  stateRef.current = state;
29
45
  return useMemo(() => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chestnutlabs/gcode-preview-react",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "description": "Thin React integration for the Chestnut Labs G-code viewer (DD-007 D1 amendment): useGcodePreview hook + GcodePreview component as a reactivity bridge over @chestnutlabs/gcode-preview-core.",
5
5
  "keywords": [
6
6
  "gcode",
@@ -53,11 +53,11 @@
53
53
  "test": "vitest run"
54
54
  },
55
55
  "dependencies": {
56
- "@chestnutlabs/gcode-model-renderer": "0.20.0",
57
- "@chestnutlabs/gcode-parser": "0.20.0",
58
- "@chestnutlabs/gcode-preview-core": "0.20.0",
59
- "@chestnutlabs/gcode-renderer-three": "0.20.0",
60
- "@chestnutlabs/toolpath-core": "0.20.0"
56
+ "@chestnutlabs/gcode-model-renderer": "0.20.1",
57
+ "@chestnutlabs/gcode-parser": "0.20.1",
58
+ "@chestnutlabs/gcode-preview-core": "0.20.1",
59
+ "@chestnutlabs/gcode-renderer-three": "0.20.1",
60
+ "@chestnutlabs/toolpath-core": "0.20.1"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "react": "^18.0.0 || ^19.0.0"