Skip to content

Refactor: extract shared utilities, fix handler leak, accessibility#1

Open
finedesignz wants to merge 1 commit into
mainfrom
upstream-fixes
Open

Refactor: extract shared utilities, fix handler leak, accessibility#1
finedesignz wants to merge 1 commit into
mainfrom
upstream-fixes

Conversation

@finedesignz
Copy link
Copy Markdown
Owner

Summary

  • Fix handler leak in Layout.tsxsubscribe() was called every render without cleanup, accumulating handlers unboundedly. Moved into useEffect with proper cleanup return.
  • Extract shared crypto utilitiesgenerateSecureToken() and hashToken() moved to hub/src/lib/crypto.ts. Removes 3 duplicate token-generation functions and fixes layering violation where hashToken lived in ws/channel.ts but was imported by 3 unrelated API files.
  • Extract hubFetch utility — Created web/src/lib/api.ts with HUB_URL, authHeaders(), hubFetch(). Replaces ~30 repetitive lines across 5 hook files.
  • Fix profile PATCH response — Was returning { ok: true }, causing client to clobber profile state. Now returns full profile object.
  • Fix Infinity serializationTIER_LIMITS.max was Infinity (serializes as null in JSON). Changed to -1 sentinel with proper limit checks.
  • Parallelize DB queries — Independent tier/session-count queries in sessions.ts and plugin.ts now use Promise.all.
  • Move TIER_LIMITS to config.ts — Was defined in profile.ts but imported cross-module.
  • Wrap hook mutations in useCallback — Prevents unnecessary re-renders downstream.
  • Fix accessibility — Sidebar action <span> elements changed to <button type="button"> for keyboard accessibility.
  • Deduplicate App.tsx — Extracted LoadingScreen, removed redundant goToChat, collapsed duplicate Layout renders.

Test plan

  • Verify hub starts without import errors
  • Verify web type-checks cleanly (tsc --noEmit)
  • Test session creation/deletion still works
  • Test API key generation/revocation
  • Test channel connection/auth flow
  • Verify Layout doesn't accumulate handlers on re-render
  • Verify profile update reflects in UI immediately

🤖 Generated with Claude Code

…bility

- Extract generateSecureToken() and hashToken() to hub/src/lib/crypto.ts
  (removes 3 duplicate definitions, fixes layering violation where hashToken
  lived in ws/channel.ts but was imported by API files)
- Move TIER_LIMITS to hub/src/config.ts (single source of truth)
- Fix profile PATCH to return full profile object (was returning { ok: true })
- Use -1 sentinel for unlimited tier (Infinity is not JSON-serializable)
- Parallelize independent DB queries with Promise.all (sessions, plugin)
- Extract hubFetch/authHeaders to web/src/lib/api.ts (replaces ~30 repetitive
  lines across 5 hook files)
- Wrap hook mutation functions in useCallback (prevents unnecessary re-renders)
- Fix handler leak in Layout.tsx (subscribe called every render without
  cleanup, handlers accumulated unboundedly)
- Fix Sidebar action buttons: span → button for keyboard accessibility
- Deduplicate LoadingScreen and goToChat in App.tsx

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant