Skip to content

Fix web test failures from SSR theme import and Claude auth diagnostics#456

Merged
BunsDev merged 2 commits intomainfrom
copilot/fix-localstorage-not-defined
Apr 14, 2026
Merged

Fix web test failures from SSR theme import and Claude auth diagnostics#456
BunsDev merged 2 commits intomainfrom
copilot/fix-localstorage-not-defined

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

What Changed

@okcode/web#test was failing for two independent reasons: useTheme touched localStorage during module import in non-browser test/SSR paths, and Claude authentication errors were not recognized by threadError, so the expected troubleshooting copy was never added.

  • SSR-safe theme initialization

    • Added a browser capability guard in apps/web/src/hooks/useTheme.ts.
    • Wrapped localStorage reads/writes behind safe accessors.
    • Skipped module-load side effects (initCustomTheme(), initial applyTheme(...)) when no DOM is available.
    • Returned stable server snapshots / no-op subscriptions in non-DOM environments so static rendering tests can import components without crashing.
  • Claude auth error detection

    • Expanded AUTH_FAILURE_PATTERNS in apps/web/src/components/chat/threadError.ts to match the Claude failure wording used in the failing tests.
    • This restores the expected troubleshooting tip generation for Claude login failures.
const canUseDOM = typeof window !== "undefined" && typeof document !== "undefined";

function safeLocalStorageGet(key: string): string | null {
  if (!canUseDOM) return null;
  try {
    return window.localStorage.getItem(key);
  } catch {
    return null;
  }
}

Why

The failing import path was executing browser-only theme code in a server/test environment, which caused ReferenceError: localStorage is not defined before the test could render. Separately, the auth matcher only recognized run claude auth login phrasing, but the actual error said authenticated with claude auth login, so auth failures were misclassified and the expected diagnostic tip was omitted.

UI Changes

None.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Copilot AI and others added 2 commits April 14, 2026 10:43
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
okcode-marketing Ready Ready Preview Apr 14, 2026 11:43am
v0-compute-the-platform-to-build Ready Ready Preview, Open in v0 Apr 14, 2026 11:43am

@BunsDev BunsDev merged commit 448b4f8 into main Apr 14, 2026
4 checks passed
@github-actions github-actions bot added size:M vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants