Skip to content

fix(ThemeContext): Guard localStorage access to prevent ReferenceError - #4076

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/gazebo-17kq-localstorage
Open

fix(ThemeContext): Guard localStorage access to prevent ReferenceError#4076
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/gazebo-17kq-localstorage

Conversation

@sentry

@sentry sentry Bot commented Aug 8, 2026

Copy link
Copy Markdown

Description

This PR addresses GAZEBO-17KQ, a ReferenceError: Can't find variable: localStorage that occurred in environments where localStorage is not available (e.g., Apple Mail webviews).

Code Example

Notable Changes

The ThemeContextProvider in src/shared/ThemeContext/ThemeContext.tsx was attempting to access localStorage.getItem and localStorage.setItem directly. This led to a crash when localStorage was undefined.

The fix involves adding typeof localStorage !== 'undefined' checks around all localStorage accesses within ThemeContext.tsx to ensure these operations are only performed when localStorage is present, thus preventing the ReferenceError.

Screenshots

Link to Sample Entry

GAZEBO-17KQ

Legal Boilerplate

Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.

Fixes GAZEBO-17KQ

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 185 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
gazebo-production-system 5.81MB 106 bytes (0.0%) ⬆️
gazebo-production-esm 5.89MB 79 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: gazebo-production-system

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index-legacy.*.js 106 bytes 657.7kB 0.02%

Files in assets/index-legacy.*.js:

  • ./src/shared/ThemeContext/ThemeContext.tsx → Total Size: 1.84kB
view changes for bundle: gazebo-production-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index.*.js 79 bytes 577.8kB 0.01%

Files in assets/index.*.js:

  • ./src/shared/ThemeContext/ThemeContext.tsx → Total Size: 1.82kB

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.76%. Comparing base (faad269) to head (7c3854d).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/shared/ThemeContext/ThemeContext.tsx 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4076      +/-   ##
==========================================
- Coverage   98.76%   98.76%   -0.01%     
==========================================
  Files         822      822              
  Lines       15092    15096       +4     
  Branches     4351     4364      +13     
==========================================
+ Hits        14906    14909       +3     
- Misses        179      180       +1     
  Partials        7        7              
Files with missing lines Coverage Δ
src/shared/ThemeContext/ThemeContext.tsx 94.44% <85.71%> (-2.44%) ⬇️
Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 99.72% <ø> (ø)
Pages 98.42% <ø> (ø)
Services 99.32% <ø> (ø)
Shared 98.88% <85.71%> (-0.07%) ⬇️
UI 99.02% <ø> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update faad269...7c3854d. Read the comment docs.

@codecov-notifications

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/shared/ThemeContext/ThemeContext.tsx 85.71% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main    #4076      +/-   ##
==========================================
- Coverage   98.76%   98.76%   -0.01%     
==========================================
  Files         822      822              
  Lines       15092    15096       +4     
  Branches     4351     4356       +5     
==========================================
+ Hits        14906    14909       +3     
- Misses        179      180       +1     
  Partials        7        7              
Files with missing lines Coverage Δ
src/shared/ThemeContext/ThemeContext.tsx 94.44% <85.71%> (-2.44%) ⬇️
Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 99.72% <ø> (ø)
Pages 98.42% <ø> (ø)
Services 99.32% <ø> (ø)
Shared 98.88% <85.71%> (-0.07%) ⬇️
UI 99.02% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update faad269...7c3854d. Read the comment docs.

@codecov-public-qa

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 98.76%. Comparing base (faad269) to head (7c3854d).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/shared/ThemeContext/ThemeContext.tsx 85.71% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main    #4076      +/-   ##
==========================================
- Coverage   98.76%   98.76%   -0.01%     
==========================================
  Files         822      822              
  Lines       15092    15096       +4     
  Branches     4359     4356       -3     
==========================================
+ Hits        14906    14909       +3     
- Misses        179      180       +1     
  Partials        7        7              
Files with missing lines Coverage Δ
src/shared/ThemeContext/ThemeContext.tsx 94.44% <85.71%> (-2.44%) ⬇️
Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 99.72% <ø> (ø)
Pages 98.42% <ø> (ø)
Services 99.32% <ø> (ø)
Shared 98.88% <85.71%> (-0.07%) ⬇️
UI 99.02% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update faad269...7c3854d. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codecov-releaser

Copy link
Copy Markdown
Collaborator

✅ Deploy preview for gazebo ready!

Previews expire after 1 month automatically.

Storybook

Commit Created Cloud Enterprise
7c3854d Sat, 08 Aug 2026 10:51:50 GMT Cloud Enterprise

@codecov-qa

codecov-qa Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.76%. Comparing base (faad269) to head (7c3854d).

Files with missing lines Patch % Lines
src/shared/ThemeContext/ThemeContext.tsx 85.71% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main    #4076      +/-   ##
==========================================
- Coverage   98.76%   98.76%   -0.01%     
==========================================
  Files         822      822              
  Lines       15092    15096       +4     
  Branches     4359     4364       +5     
==========================================
+ Hits        14906    14909       +3     
- Misses        179      180       +1     
  Partials        7        7              
Files with missing lines Coverage Δ
src/shared/ThemeContext/ThemeContext.tsx 94.44% <85.71%> (-2.44%) ⬇️
Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 99.72% <ø> (ø)
Pages 98.42% <ø> (ø)
Services 99.32% <ø> (ø)
Shared 98.88% <85.71%> (-0.07%) ⬇️
UI 99.02% <ø> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update faad269...7c3854d. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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