Skip to content

fix: localStorage try/catch and SSR guards across 7 components#5833

Merged
clubanderson merged 1 commit intomainfrom
fix/5825-5831-localstorage-guards
Apr 9, 2026
Merged

fix: localStorage try/catch and SSR guards across 7 components#5833
clubanderson merged 1 commit intomainfrom
fix/5825-5831-localstorage-guards

Conversation

@clubanderson
Copy link
Copy Markdown
Collaborator

Summary

Add localStorage try/catch and SSR guards across 7 components to prevent crashes in Safari private mode, SSR, and test environments:

  • ClusterCosts, GitHubActivity, KustomizationStatus, MaintenanceWindows, CardWrapper, gitHubCIUtils: SSR guards + try/catch
  • useMarketplace: SSR guard + useMemo for expensive filter computations to fix re-render cascade

Fixes #5823 #5825 #5826 #5827 #5828 #5829 #5831

Test plan

  • npm run build passes

🤖 Generated with Claude Code

- 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>
@clubanderson clubanderson added the ai-generated Pull request generated by AI label Apr 9, 2026
Copilot AI review requested due to automatic review settings April 9, 2026 20:15
@kubestellar-prow kubestellar-prow bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Apr 9, 2026
@kubestellar-prow
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mikespreitzer for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 9, 2026

Deploy Preview for kubestellarconsole ready!

Name Link
🔨 Latest commit 01eb6ee
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/69d808f26d033c0008bb6dbc
😎 Deploy Preview https://deploy-preview-5833.console-deploy-preview.kubestellar.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

👋 Hey @clubanderson — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Post-merge build verification passed

Both Go and frontend builds compiled successfully against merge commit d7375448902513a9a413d074368a5587643db6ed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 wrap localStorage reads/writes in try/catch across multiple cards/utilities.
  • Memoize Marketplace derived values (tags, CNCF groupings/stats, type counts, filtered items) with useMemo to reduce recalculation churn.
  • Ensure GitHub CI repo persistence helpers no-op safely when window is 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 {}

Comment on lines 446 to 450
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()
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

✅ Post-Merge Verification: passed

Commit: d7375448902513a9a413d074368a5587643db6ed
Specs run: Dashboard.spec.ts smoke.spec.ts
Report: https://github.com/kubestellar/console/actions/runs/24211247488

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Pull request generated by AI dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Marketplace Filter Re-render Cascade due to Monolithic State Hook

2 participants