fix: localStorage try/catch and SSR guards across 7 components#5833
fix: localStorage try/catch and SSR guards across 7 components#5833clubanderson merged 1 commit intomainfrom
Conversation
- ClusterCosts: SSR guard + try/catch on setItem (#5825) - GitHubActivity: SSR guards on module-level functions + try/catch (#5826) - KustomizationStatus: SSR guard on module-level loader (#5827) - MaintenanceWindows: SSR guard + try/catch on save (#5828) - CardWrapper (cardHooks.ts): SSR guard + try/catch on collapsed cards (#5829) - gitHubCIUtils: SSR guards on load/save repos (#5831) - useMarketplace: SSR guard + useMemo for filter computations (#5823) Fixes #5823 #5825 #5826 #5827 #5828 #5829 #5831 Signed-off-by: Andy Anderson <andy@clubanderson.com> Signed-off-by: Andrew Anderson <andy@clubanderson.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellarconsole ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
|
Post-merge build verification passed ✅ Both Go and frontend builds compiled successfully against merge commit |
There was a problem hiding this comment.
Pull request overview
This PR hardens several frontend cards/hooks against localStorage failures (Safari private mode / quota errors) and non-browser execution (SSR/test imports), and reduces expensive recomputation in the Marketplace hook.
Changes:
- Add SSR guards (
typeof window === 'undefined') and wraplocalStoragereads/writes intry/catchacross multiple cards/utilities. - Memoize Marketplace derived values (tags, CNCF groupings/stats, type counts, filtered items) with
useMemoto reduce recalculation churn. - Ensure GitHub CI repo persistence helpers no-op safely when
windowis unavailable.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| web/src/lib/cards/cardHooks.ts | Adds SSR guard for collapsed-card reads and wraps collapsed-card persistence writes in try/catch. |
| web/src/hooks/useMarketplace.ts | Adds SSR guard for installed-items persistence and memoizes expensive derived computations and filtering. |
| web/src/components/cards/workload-monitor/gitHubCIUtils.ts | Adds SSR guards to prevent localStorage usage when window is unavailable. |
| web/src/components/cards/MaintenanceWindows.tsx | Adds SSR guard for initial load and wraps persistence writes in try/catch. |
| web/src/components/cards/KustomizationStatus.tsx | Adds SSR guard for module-level localStorage cache load. |
| web/src/components/cards/GitHubActivity.tsx | Adds SSR guards for cache/repo loading and wraps localStorage writes in try/catch. |
| web/src/components/cards/ClusterCosts.tsx | Adds SSR guard for module-level overrides load and wraps persistence writes in try/catch. |
Comments suppressed due to low confidence (1)
web/src/hooks/useMarketplace.ts:125
- loadInstalled() now returns an empty map when window is undefined, but the existing useMarketplace hook tests don’t exercise this SSR branch. Consider adding a test that temporarily removes/stubs window/localStorage and asserts the hook can initialize without throwing and with installedItems defaulting to {}.
function loadInstalled(): InstalledMap {
if (typeof window === 'undefined') return {}
try {
return JSON.parse(localStorage.getItem(INSTALLED_KEY) || '{}')
} catch {
return {}
| function getCollapsedCards(): Set<string> { | ||
| if (typeof window === 'undefined') return new Set() | ||
| try { | ||
| const stored = localStorage.getItem(COLLAPSED_STORAGE_KEY) | ||
| return stored ? new Set(JSON.parse(stored)) : new Set() |
There was a problem hiding this comment.
The new SSR guard branch in getCollapsedCards() (returning an empty Set when window is undefined) isn’t covered by the existing cardHooks tests. Adding a unit test that runs with window/localStorage unavailable would help prevent regressions in SSR/test environments (the main motivation for this change).
✅ Post-Merge Verification: passedCommit: |
Summary
Add localStorage try/catch and SSR guards across 7 components to prevent crashes in Safari private mode, SSR, and test environments:
Fixes #5823 #5825 #5826 #5827 #5828 #5829 #5831
Test plan
npm run buildpasses🤖 Generated with Claude Code