Skip to content

fix(theme): Validate localStorage theme to prevent DOMTokenList error - #4136

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

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

Conversation

@sentry

@sentry sentry Bot commented Oct 1, 2026

Copy link
Copy Markdown

Description

This PR addresses an InvalidCharacterError that occurs when document.body.classList.add() is called with a theme value containing whitespace. The root cause was that the localStorage.getItem('theme') as Theme cast in ThemeContextProvider was a compile-time assertion, providing no runtime validation for potentially malformed values stored in localStorage.

The fix introduces a runtime validation check (isValidTheme) in src/shared/ThemeContext/ThemeContext.tsx. This ensures that only valid Theme enum values ('light' or 'dark') are used. If the value retrieved from localStorage is invalid (e.g., contains whitespace or is not 'light'/'dark'), it now gracefully falls back to null, which then defaults to the system-detected theme, preventing the InvalidCharacterError.

Code Example

Notable Changes

  • Introduced runtime validation (isValidTheme) for theme values retrieved from localStorage.
  • Ensures only valid Theme enum values ('light' or 'dark') are used.
  • Gracefully falls back to null (triggering system theme default) for invalid localStorage theme values.
  • Prevents InvalidCharacterError when adding theme class to document.body.classList.

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

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

@sentry

sentry Bot commented Oct 1, 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

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Bundle Report

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

Detailed changes
Bundle name Size Change
gazebo-production-system 5.82MB 48 bytes (0.0%) ⬆️
gazebo-production-esm 5.89MB 41 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: gazebo-production-esm

Assets Changed:

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

Files in assets/index.*.js:

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

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index-legacy.*.js 48 bytes 657.87kB 0.01%

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

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

@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    #4136   +/-   ##
=======================================
  Coverage   98.77%   98.77%           
=======================================
  Files         823      823           
  Lines       15147    15150    +3     
  Branches     4387     4389    +2     
=======================================
+ 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...2cb933c. 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 (2cb933c).

✅ All tests successful. No failed tests found.

@@           Coverage Diff           @@
##             main    #4136   +/-   ##
=======================================
  Coverage   98.77%   98.77%           
=======================================
  Files         823      823           
  Lines       15147    15150    +3     
  Branches     4379     4389   +10     
=======================================
+ 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...2cb933c. 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 1, 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 (2cb933c).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4136   +/-   ##
=======================================
  Coverage   98.77%   98.77%           
=======================================
  Files         823      823           
  Lines       15147    15150    +3     
  Branches     4387     4389    +2     
=======================================
+ 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...2cb933c. 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
2cb933c Thu, 01 Oct 2026 10:08:32 GMT Cloud Enterprise

@codecov-qa

codecov-qa Bot commented Oct 1, 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 (2cb933c).

@@           Coverage Diff           @@
##             main    #4136   +/-   ##
=======================================
  Coverage   98.77%   98.77%           
=======================================
  Files         823      823           
  Lines       15147    15150    +3     
  Branches     4387     4389    +2     
=======================================
+ 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...2cb933c. 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