Skip to content

fix: resolve libsql wal conflict auto-healing and reports hook order - #11

Merged
AdityaRaj212 merged 1 commit into
stagingfrom
fix/otp-sync-and-reports-hooks
Oct 2, 2026
Merged

AdityaRaj212 merged 1 commit into
stagingfrom
fix/otp-sync-and-reports-hooks

Conversation

@AdityaRaj212

Copy link
Copy Markdown
Owner

📋 Summary of Changes

  1. Turso / Libsql Connection Stability & Self-Healing (src/lib/db.ts):
    • Fixed globalDbUrl caching so connection instances are properly reused across requests instead of repeatedly destroyed and re-opened.
    • Added handleWalConflict() to safely close dangling handles, unlink conflicted/diverged local replica files, pull a clean replica from Turso, and auto-retry write queries.
  2. Local Auth Cookie Support (src/app/api/auth/otp/verify/route.ts):
    • Conditioned secure: true on cookies so localhost (127.0.0.1 / localhost) does not reject session cookies over http://.
  3. React Rules of Hooks Fix on Reports Page (src/app/reports/page.tsx):
    • Replaced conditional useMemo at line 539 (which was invoked after early returns on loading and error states) with direct calculation. All hooks in ReportsPage now execute unconditionally at top-level.

🎯 Target Branch Verification

  • This PR targets the staging branch (Direct PRs to main are reserved exclusively for staging-to-main production releases).

🔍 Context & Motivation

  • Resolves WalConflict errors during OTP send/writes on embedded replica.
  • Resolves console error React has detected a change in the order of Hooks called by ReportsPage and runtime error Rendered more hooks than during the previous render.

✅ Verification & Quality Checklist

  • Typecheck: npx tsc --noEmit passes with 0 errors.
  • Test Suite: npm test passes 70/70 tests.
  • Production Build: npm run build succeeds cleanly.
  • Deterministic Financial Math: Verified.
  • Security & Authorization: Validated session tokens and cookie flags.
  • Design Aesthetics & Theming: Preserved theme consistency.

@AdityaRaj212 AdityaRaj212 self-assigned this Oct 2, 2026
Copilot AI balanced review requested due to automatic review settings October 2, 2026 16:48
@vercel

vercel Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
bagstack Ready Ready Preview Oct 2, 2026 4:48pm UTC

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@AdityaRaj212 AdityaRaj212 added the bug Something isn't working label Oct 2, 2026
@AdityaRaj212
AdityaRaj212 merged commit c15ca62 into staging Oct 2, 2026
4 checks passed

This branch was successfully deployed

1 active deployment
Preview — 63032f91 Deployed Oct 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants