Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/routes/trackpad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ function TrackpadPage() {
const [invertScroll] = useState(() => {
if (typeof window === "undefined") return false
const s = localStorage.getItem("rein_invert")
return s ? JSON.parse(s) : false
if (!s) return false
try {
return JSON.parse(s)
} catch {
return false
}
Comment on lines 33 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify expected type at hook boundary and inspect current state initialization.
fd 'useTrackpadGesture\.(ts|tsx)$' --exec sed -n '1,220p' {}
rg -nP -C3 'const \[invertScroll\]\s*=\s*useState' src/routes/trackpad.tsx

Repository: AOSSIE-Org/Rein

Length of output: 6403


🏁 Script executed:

head -10 src/routes/trackpad.tsx | cat -n

Repository: AOSSIE-Org/Rein

Length of output: 723


Constrain parsed localStorage value to boolean and type the state explicitly.

Line 38 returns JSON.parse(s) directly, which makes invertScroll effectively any and accepts non-boolean JSON (e.g., "1" or {}). Keep the crash fix, but enforce a boolean guard.

Proposed fix
-	const [invertScroll] = useState(() => {
+	const [invertScroll] = useState<boolean>(() => {
 		if (typeof window === "undefined") return false
 		const s = localStorage.getItem("rein_invert")
 		if (!s) return false
 		try {
-			return JSON.parse(s)
+			const parsed: unknown = JSON.parse(s)
+			return typeof parsed === "boolean" ? parsed : false
 		} catch {
 			return false
 		}
 	})

This addresses the TypeScript guideline: "Avoid 'any', use explicit types".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/routes/trackpad.tsx` around lines 33 - 41, The useState initializer for
invertScroll in the Trackpad component currently returns JSON.parse(s) directly
which can yield non-boolean and widen the state to any; change the state to an
explicit boolean type (e.g., useState<boolean>) and guard the parsed value so
only a true boolean is accepted (parse, check typeof parsed === "boolean", and
return parsed, otherwise return false) while preserving the try/catch fallback
to false; update references to the invertScroll state accordingly.

})

const { send, sendCombo } = useRemoteConnection()
Expand Down
Loading