refactor(frontend): Refactor React State Managers to Centralize LocalStorage Sync and Add Error Boundaries#659
Conversation
…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
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@advikdivekar is attempting to deploy a commit to the ritesh Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@ritesh-1918 please review my PR, thank you |
Summary
Fixes #639
This PR centralizes all Zustand localStorage writes through a single safe persistence middleware and adds a production-quality
ErrorBoundarycomponent with a diagnostic error payload exporter.Changes
Frontend/src/store/middleware/safePersist.js— Safe Zustand Persistence Middlewarepersistmiddleware with a custom storage adapterQuotaExceededError/NS_ERROR_DOM_QUOTA_REACHEDonsetItem— silently skips the write (state stays in memory) and logs a descriptiveconsole.warngetItemandremoveItemerrors — returnsnull/ no-ops gracefullyonRehydrateStorageerrors — logs and continues with default stateFrontend/src/store/ticketStore.js— migrated frompersist→safePersistFrontend/src/store/authStore.js— migrated frompersist→safePersistFrontend/src/admin/store/adminStore.js— migrated frompersist→safePersistFrontend/src/components/shared/ErrorBoundary.jsx— React Error Boundarytimestamp,message,name,stack,componentStackurl(current page),userAgentonErrorprop for optional external error reporting (e.g., Sentry)fallbackprop to provide a custom UI instead of the default error pageUsage
Test Plan
/