Files
GearBox/.planning/debug/client-w0-undefined-after-login.md
Jean-Luc Makiola f564e8cb54
All checks were successful
CI / ci (push) Successful in 1m7s
CI / e2e (push) Has been skipped
CI / deploy (push) Successful in 7s
docs: archive v1.3 and v2.0 milestones with roadmap, requirements, and retrospective
2026-04-08 23:10:50 +02:00

2.4 KiB

status, trigger, created, updated
status trigger created updated
awaiting_human_verify Client-side error 'can't access property id, w[0] is undefined' occurs after login 2026-04-08T00:00:00Z 2026-04-08T00:00:00Z

Current Focus

hypothesis: CONFIRMED — AddToThreadModal.tsx has an unguarded activeThreads[0].id in a useEffect dependency array, which throws when there are no active threads (new user after login) test: Root cause confirmed by code reading expecting: Fix by replacing activeThreads[0].id with activeThreads[0]?.id in the dependency array next_action: Apply fix

Symptoms

expected: After login, app loads normally and shows user's collection actual: Error thrown client-side: "can't access property 'id', w[0] is undefined" errors: "can't access property 'id', w[0] is undefined" — minified variable name, from production/built bundle reproduction: Happens after logging in (OIDC via Logto) started: Unclear when it started, user noticed it now

Eliminated

  • hypothesis: Bug is in auth hooks or route guards evidence: useAuth.ts and __root.tsx are clean — auth handles null/undefined safely timestamp: 2026-04-08T00:00:00Z

  • hypothesis: Bug is in categories[0].id access in CreateThreadModal, ManualEntryForm, or AddToCollectionModal evidence: All three guard with categories && categories.length > 0 before accessing [0].id timestamp: 2026-04-08T00:00:00Z

Evidence

  • timestamp: 2026-04-08T00:00:00Z checked: AddToThreadModal.tsx lines 62-68 found: useEffect dependency array evaluates activeThreads[0].id unconditionally. When activeThreads is empty (new user after login with no threads), this throws TypeError. implication: This is the root cause. The guard activeThreads.length === 0 inside the effect body does NOT protect the dependency array itself — React evaluates the dep array on every render.

Resolution

root_cause: In AddToThreadModal.tsx, the useEffect dependency array at lines 62-68 directly accesses activeThreads[0].id without optional chaining. When a user logs in with no active threads (empty array), React evaluates this expression during render and throws "can't access property 'id', w[0] is undefined". fix: Replace activeThreads[0].id with activeThreads[0]?.id in the useEffect dependency array verification: Fix applied — changed activeThreads[0].id to activeThreads[0]?.id in useEffect dependency array. This prevents the TypeError when activeThreads is empty. files_changed: [src/client/components/AddToThreadModal.tsx]