Skip to content

fix(ThemeContext): Prevent empty string in classList.add - #4137

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/gazebo-188e-theme-context
Open

sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/gazebo-188e-theme-context

Conversation

@sentry

@sentry sentry Bot commented Oct 2, 2026

Copy link
Copy Markdown

Description

This PR addresses a SyntaxError: DOMTokenList.add: The empty string is not a valid token. that occurs when the theme value retrieved from localStorage is an empty string.

The root cause was that localStorage.getItem('theme') could return an empty string, which was then incorrectly cast as Theme and used in document.body.classList.add(). The nullish coalescing operator ?? did not prevent this, as it only handles null or undefined, not empty strings.

Code Example

Notable Changes

The fix involves:

  1. Validating the value retrieved from localStorage to ensure it is a valid Theme enum member ('light' or 'dark'). If not, it defaults to null.
  2. Changing the useState initializer from ?? to || (logical OR) to correctly fall back to the systemTheme if the localStorage value is an empty string or null.

This ensures that document.body.classList.add() always receives a valid theme string.

Screenshots

Link to Sample Entry

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-188E

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Bundle Report

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

Detailed changes
Bundle name Size Change
gazebo-production-system 5.82MB 39 bytes (0.0%) ⬆️
gazebo-production-esm 5.89MB 32 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 39 bytes 657.86kB 0.01%

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

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

Assets Changed:

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

Files in assets/index.*.js:

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

@sentry

sentry Bot commented Oct 2, 2026

Copy link
Copy Markdown
Author

⚠️ Sentry needs additional GitHub App permissions

The Sentry GitHub App installation for this repository is missing permissions it needs to keep iterating on this pull request to get CI passing.

Review and accept the updated permissions to let Seer continue: https://github.com/organizations/codecov/settings/installations/86101127/permissions/update

@codecov-notifications

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

@@           Coverage Diff           @@
##             main    #4137   +/-   ##
=======================================
  Coverage   98.77%   98.77%           
=======================================
  Files         823      823           
  Lines       15147    15150    +3     
  Branches     4387     4382    -5     
=======================================
+ Hits        14961    14964    +3     
  Misses        179      179           
  Partials        7        7           
Files with missing lines Coverage Δ
src/shared/ThemeContext/ThemeContext.tsx 97.14% <100.00%> (+0.26%) ⬆️
Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 99.72% <ø> (ø)
Pages 98.43% <ø> (ø)
Services 99.32% <ø> (ø)
Shared 98.94% <100.00%> (+<0.01%) ⬆️
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 b8fbfc0...5ed679b. Read the comment docs.

@codecov-public-qa

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.77%. Comparing base (b8fbfc0) to head (5ed679b).

✅ All tests successful. No failed tests found.

@@           Coverage Diff           @@
##             main    #4137   +/-   ##
=======================================
  Coverage   98.77%   98.77%           
=======================================
  Files         823      823           
  Lines       15147    15150    +3     
  Branches     4379     4382    +3     
=======================================
+ Hits        14961    14964    +3     
  Misses        179      179           
  Partials        7        7           
Files with missing lines Coverage Δ
src/shared/ThemeContext/ThemeContext.tsx 97.14% <100.00%> (+0.26%) ⬆️
Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 99.72% <ø> (ø)
Pages 98.43% <ø> (ø)
Services 99.32% <ø> (ø)
Shared 98.94% <100.00%> (+<0.01%) ⬆️
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 b8fbfc0...5ed679b. 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

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.77%. Comparing base (b8fbfc0) to head (5ed679b).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4137   +/-   ##
=======================================
  Coverage   98.77%   98.77%           
=======================================
  Files         823      823           
  Lines       15147    15150    +3     
  Branches     4387     4382    -5     
=======================================
+ Hits        14961    14964    +3     
  Misses        179      179           
  Partials        7        7           
Files with missing lines Coverage Δ
src/shared/ThemeContext/ThemeContext.tsx 97.14% <100.00%> (+0.26%) ⬆️
Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 99.72% <ø> (ø)
Pages 98.43% <ø> (ø)
Services 99.32% <ø> (ø)
Shared 98.94% <100.00%> (+<0.01%) ⬆️
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 b8fbfc0...5ed679b. Read the comment docs.

@codecov-releaser

Copy link
Copy Markdown
Collaborator

✅ Deploy preview for gazebo ready!

Previews expire after 1 month automatically.

Storybook

Commit Created Cloud Enterprise
5ed679b Fri, 02 Oct 2026 17:45:16 GMT Cloud Enterprise

@codecov-qa

codecov-qa Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.77%. Comparing base (b8fbfc0) to head (5ed679b).

@@           Coverage Diff           @@
##             main    #4137   +/-   ##
=======================================
  Coverage   98.77%   98.77%           
=======================================
  Files         823      823           
  Lines       15147    15150    +3     
  Branches     4387     4390    +3     
=======================================
+ Hits        14961    14964    +3     
  Misses        179      179           
  Partials        7        7           
Files with missing lines Coverage Δ
src/shared/ThemeContext/ThemeContext.tsx 97.14% <100.00%> (+0.26%) ⬆️
Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 99.72% <ø> (ø)
Pages 98.43% <ø> (ø)
Services 99.32% <ø> (ø)
Shared 98.94% <100.00%> (+<0.01%) ⬆️
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 b8fbfc0...5ed679b. 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.

This branch has not been deployed

No deployments
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