Skip to content

refactor(frontend): Refactor React State Managers to Centralize LocalStorage Sync and Add Error Boundaries#659

Open
advikdivekar wants to merge 2 commits into
ritesh-1918:gssocfrom
advikdivekar:fix/issue-639-error-boundaries-zustand
Open

refactor(frontend): Refactor React State Managers to Centralize LocalStorage Sync and Add Error Boundaries#659
advikdivekar wants to merge 2 commits into
ritesh-1918:gssocfrom
advikdivekar:fix/issue-639-error-boundaries-zustand

Conversation

@advikdivekar
Copy link
Copy Markdown

Summary

Fixes #639

This PR centralizes all Zustand localStorage writes through a single safe persistence middleware and adds a production-quality ErrorBoundary component with a diagnostic error payload exporter.

Changes

  • Frontend/src/store/middleware/safePersist.js — Safe Zustand Persistence Middleware

    • Wraps the standard persist middleware with a custom storage adapter
    • Catches QuotaExceededError / NS_ERROR_DOM_QUOTA_REACHED on setItem — silently skips the write (state stays in memory) and logs a descriptive console.warn
    • Catches all getItem and removeItem errors — returns null / no-ops gracefully
    • Catches onRehydrateStorage errors — logs and continues with default state
    • All stores now degrade gracefully instead of crashing when storage is full or unavailable (private browsing, locked storage, etc.)
  • Frontend/src/store/ticketStore.js — migrated from persistsafePersist

  • Frontend/src/store/authStore.js — migrated from persistsafePersist

  • Frontend/src/admin/store/adminStore.js — migrated from persistsafePersist

  • Frontend/src/components/shared/ErrorBoundary.jsx — React Error Boundary

    • Class component (required — hooks cannot catch render errors)
    • Stylized error page: dark header with error icon, red-tinted error message card, explanatory text, Try Again and Go Home action buttons
    • "Copy error payload" button: copies structured JSON to clipboard containing:
      • timestamp, message, name, stack, componentStack
      • url (current page), userAgent
    • Visual feedback: button turns green with checkmark for 3 seconds after copy
    • onError prop for optional external error reporting (e.g., Sentry)
    • fallback prop to provide a custom UI instead of the default error page
    • Accessible markup with proper heading hierarchy

Usage

// Wrap critical route sections in App.jsx or individual pages:
import ErrorBoundary from './components/shared/ErrorBoundary';

<ErrorBoundary>
  <AdminDashboard />
</ErrorBoundary>

Test Plan

  • Fill localStorage to quota in DevTools (Application → Storage) — verify app does not crash, console.warn appears
  • Render a component that throws — verify ErrorBoundary catches it and shows the error UI
  • Click "Copy error payload" — verify JSON is in clipboard with all fields populated
  • Click "Try again" — verify boundary resets and re-renders the child
  • Click "Go home" — verify navigation to /

…dleware and add ErrorBoundary

Closes ritesh-1918#639

- Add Frontend/src/store/middleware/safePersist.js: Zustand middleware wrapping
  the standard `persist` middleware with a safe localStorage adapter that catches
  QuotaExceededError (quota full), read errors, and remove errors — all silently
  degraded to in-memory-only state with console.warn instead of thrown exceptions;
  onRehydrateStorage errors are also caught and logged
- Migrate Frontend/src/store/ticketStore.js: replace `persist` import with
  `safePersist` — all ticket state writes are now quota-safe
- Migrate Frontend/src/store/authStore.js: replace `persist` import with
  `safePersist` — auth session writes are now quota-safe
- Migrate Frontend/src/admin/store/adminStore.js: replace `persist` import
  with `safePersist` — admin settings writes are now quota-safe
- Add Frontend/src/components/shared/ErrorBoundary.jsx: React class component
  error boundary with stylized error page showing error message, Try Again /
  Go Home actions, and a "Copy error payload" button that copies full error
  diagnostic JSON (message, stack, componentStack, URL, userAgent, timestamp)
  to clipboard for rapid customer bug reporting
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

@advikdivekar is attempting to deploy a commit to the ritesh Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f09b4e17-21ec-4e53-b826-3ee6c7b92724

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@advikdivekar
Copy link
Copy Markdown
Author

@ritesh-1918 please review my PR, thank you

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