Skip to content

Commit 4b86e50

Browse files
authored
Merge pull request #69 from VariableThe/fix/build-strict-types
fix: resolve TypeScript strict build errors in GraphView and setupTests
2 parents 19fa5da + 332b5dd commit 4b86e50

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

AUDIT_LOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
This log tracks all significant changes, updates, and versions in the PaperCache project.
44

5+
## 2026-06-27 (Update)
6+
**Change:** fix: resolve TypeScript strict build errors in GraphView and setupTests
7+
8+
**Details/Why:**
9+
Resolved production build (`npm run tauri build` / `tsc -b`) failures caused by strict typing mismatches:
10+
1. **`ForceGraphMethods` Typing (`GraphView.tsx`)** — Configured `ForceGraphInstance` to extend `ForceGraphMethods` imported from `react-force-graph-3d`, enabling type-safe calls to `d3Force`, `strength`, `d3ReheatSimulation`, and `cameraPosition`.
11+
2. **Ref Variance (`GraphView.tsx`)** — Casted `<ForceGraph3D>` ref prop to resolve strict `MutableRefObject` variance mismatch.
12+
3. **Mock Contract (`setupTests.ts`)** — Added missing `onUpdateReady` mock implementation to `window.electronAPI` in unit test environment setup.
13+
14+
**Files changed:** `src/GraphView.tsx`, `src/setupTests.ts`, `AUDIT_LOG.md`, `CHANGELOG.md`.
15+
16+
---
17+
518
## 2026-06-27
619
**Change:** fix: address audit findings — ESC logic, IPC types, update UX, mutex safety, ESLint (PR #68)
720

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- **IPC error handling for shell/file commands**: `openExternal`, `openFile`, `setLaunchAtStartup`, and `quitApp` now properly propagate backend errors to the caller instead of silently discarding the Promise.
1919
- **Update notification before restart**: When an auto-update is ready, PaperCache now shows a toast ("PaperCache updated — restarting in 3 seconds…") for 3 seconds before restarting, so users are never caught off-guard.
2020
- **Pause button removed from timer panel**: The ⏸ pause button had no corresponding resume path (backend not implemented). Removed to avoid a dead-end UX; the close/remove button remains.
21+
- **Resolved production build TypeScript errors**: Fixed strict compilation failures in GraphView (`d3Force`, `cameraPosition`, ref assignment) and unit test setup (`onUpdateReady`).
2122

2223
## [v0.5.3] - 2026-06-24
2324

src/GraphView.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useMemo, useCallback, useEffect, useRef, useState, lazy, Suspense } from 'react'
22
import * as THREE from 'three'
33
import * as d3 from 'd3-force'
4+
import type { ForceGraphMethods } from 'react-force-graph-3d'
45
import { getFolderColor } from './utils'
56

67
const ForceGraph3D = lazy(() => import('react-force-graph-3d'))
@@ -46,15 +47,11 @@ function buildFolderCentroids(folderNames: string[]): Map<string, { cx: number;
4647
return centroids
4748
}
4849

49-
// Minimal typing for the react-force-graph-3d instance (library ships no declarations)
50-
interface ForceGraphInstance {
51-
controls: () => Record<string, unknown> | null
52-
cameraPosition: (pos: { x: number; y: number; z: number }) => void
53-
zoomToFit: (duration: number, padding: number) => void
54-
graphData: () => { nodes: GraphNode[]; links: GraphLink[] } | null
55-
d3Force: (name: string, force?: unknown) => unknown
56-
scene: () => THREE.Scene
57-
nodeThreeObject: unknown
50+
declare module 'react-force-graph-3d' {
51+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
52+
interface ForceGraphMethods<NodeType = {}, LinkType = {}> {
53+
graphData(): { nodes: NodeType[]; links: LinkType[] }
54+
}
5855
}
5956

6057
export default function GraphView({
@@ -65,7 +62,7 @@ export default function GraphView({
6562
bgColor,
6663
accentColor,
6764
}: GraphViewProps) {
68-
const fgRef = useRef<ForceGraphInstance | null>(null)
65+
const fgRef = useRef<ForceGraphMethods<GraphNode, GraphLink> | undefined>(undefined)
6966

7067
const draggedNodesRef = useRef<Set<string>>(new Set())
7168

src/setupTests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ if (typeof window !== 'undefined') {
7272
onPowerResume: vi.fn().mockReturnValue(() => {}),
7373
pauseShortcuts: vi.fn(),
7474
resumeShortcuts: vi.fn(),
75+
onUpdateReady: vi.fn().mockReturnValue(() => {}),
7576
scheduleReminders: vi.fn().mockResolvedValue(undefined),
7677
cancelReminders: vi.fn().mockResolvedValue(undefined),
7778
scheduleTimer: vi.fn().mockResolvedValue(undefined),

0 commit comments

Comments
 (0)