Skip to content

feat: Default color mode to user's current system theme#3456

Merged
ajay-sentry merged 5 commits into
mainfrom
Ajay/2403-default-to-system-theme
Oct 31, 2024
Merged

feat: Default color mode to user's current system theme#3456
ajay-sentry merged 5 commits into
mainfrom
Ajay/2403-default-to-system-theme

Conversation

@ajay-sentry
Copy link
Copy Markdown
Contributor

@ajay-sentry ajay-sentry commented Oct 30, 2024

Description

This PR aims to add logic to default the user's appearance mode to whatever their current system theme is at the time they come to Codecov.

Originally I wanted to have the user's system theme be swappable, but I was running into some funky behavior with the instances where we had the "dark:" class name not being picked up correctly. In the end, I feel like that'd be a cute little easter egg at best, and just having the default system theme setup for when the user first comes onto the site is probably a nice Quality of Life adjustment anyway.

Worst case they just push the light/dark mode button 😄

Closes codecov/engineering-team#2403

Notable Changes

  • Uses the "prefers-color-scheme" media query to default the user's appearance on their first visit to Codecov

Screenshots

Screen.Recording.2024-10-30.at.3.02.58.PM.mov

Link to Sample Entry

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry 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 Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 30, 2024

Bundle Report

Changes will increase total bundle size by 6.09kB (0.04%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
gazebo-production-system 5.5MB 3.17kB (0.06%) ⬆️
gazebo-production-system-esm 5.55MB 2.92kB (0.05%) ⬆️

@codecov-staging
Copy link
Copy Markdown

codecov-staging Bot commented Oct 30, 2024

Bundle Report

Changes will increase total bundle size by 6.09kB (0.04%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
gazebo-staging-system-esm 5.55MB 2.92kB (0.05%) ⬆️
gazebo-staging-system 5.5MB 3.17kB (0.06%) ⬆️

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 30, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
2713 1 2712 0
View the top 1 failed tests by shortest run time
src/services/toast/renderToast.test.tsx > src/services/toast/renderToast.test.tsx
Stack Traces | 0.00562s run time
TypeError: Cannot assign to read only property 'matchMedia' of object '#<Object>'
 ❯ src/vitest.setup.ts:53:10

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

@codecov-staging
Copy link
Copy Markdown

codecov-staging Bot commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 83.33333% 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 83.33% 1 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3456      +/-   ##
==========================================
- Coverage   99.15%   99.10%   -0.05%     
==========================================
  Files         809      806       -3     
  Lines       14307    14114     -193     
  Branches     3960     3958       -2     
==========================================
- Hits        14186    13988     -198     
- Misses        112      117       +5     
  Partials        9        9              
Files with missing lines Coverage Δ
src/shared/ThemeContext/ThemeContext.tsx 96.77% <83.33%> (-3.23%) ⬇️

... and 28 files with indirect coverage changes

Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 100.00% <ø> (ø)
Pages 98.81% <ø> (-0.07%) ⬇️
Services 99.42% <ø> (-0.04%) ⬇️
Shared 99.74% <83.33%> (-0.07%) ⬇️
UI 99.15% <ø> (ø)

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 b7968a4...3ff8dc0. Read the comment docs.

@codecov-public-qa
Copy link
Copy Markdown

codecov-public-qa Bot commented Oct 30, 2024

Codecov Report

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

Project coverage is 99.10%. Comparing base (b7968a4) to head (3ff8dc0).
Report is 5 commits behind head on main.

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3456      +/-   ##
==========================================
- Coverage   99.15%   99.10%   -0.05%     
==========================================
  Files         809      806       -3     
  Lines       14307    14114     -193     
  Branches     3967     3958       -9     
==========================================
- Hits        14186    13988     -198     
- Misses        112      117       +5     
  Partials        9        9              
Files Coverage Δ
src/shared/ThemeContext/ThemeContext.tsx 96.77% <83.33%> (-3.23%) ⬇️

... and 28 files with indirect coverage changes

Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 100.00% <ø> (ø)
Pages 98.81% <ø> (-0.07%) ⬇️
Services 99.42% <ø> (-0.04%) ⬇️
Shared 99.74% <83.33%> (-0.07%) ⬇️
UI 99.15% <ø> (ø)

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 b7968a4...3ff8dc0. Read the comment docs.

@codecov-qa
Copy link
Copy Markdown

codecov-qa Bot commented Oct 30, 2024

Codecov Report

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

Project coverage is 99.10%. Comparing base (b7968a4) to head (3ff8dc0).
Report is 6 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/shared/ThemeContext/ThemeContext.tsx 83.33% 1 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3456      +/-   ##
==========================================
- Coverage   99.15%   99.10%   -0.05%     
==========================================
  Files         809      806       -3     
  Lines       14307    14114     -193     
  Branches     3960     3958       -2     
==========================================
- Hits        14186    13988     -198     
- Misses        112      117       +5     
  Partials        9        9              
Files with missing lines Coverage Δ
src/shared/ThemeContext/ThemeContext.tsx 96.77% <83.33%> (-3.23%) ⬇️

... and 28 files with indirect coverage changes

Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 100.00% <ø> (ø)
Pages 98.81% <ø> (-0.07%) ⬇️
Services 99.42% <ø> (-0.04%) ⬇️
Shared 99.74% <83.33%> (-0.07%) ⬇️
UI 99.15% <ø> (ø)

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 b7968a4...3ff8dc0. Read the comment docs.

@codecov-releaser
Copy link
Copy Markdown
Collaborator

codecov-releaser commented Oct 30, 2024

✅ Deploy preview for gazebo ready!

Previews expire after 1 month automatically.

Storybook

Commit Created Cloud Enterprise
d98b8c5 Wed, 30 Oct 2024 22:07:30 GMT Expired Expired
3ac0afa Wed, 30 Oct 2024 22:21:31 GMT Expired Expired
5a47a97 Thu, 31 Oct 2024 17:43:18 GMT Expired Expired
5a47a97 Thu, 31 Oct 2024 17:47:23 GMT Expired Expired
3ff8dc0 Thu, 31 Oct 2024 17:53:46 GMT Cloud Enterprise

Comment thread src/globals.css
/* new body theme can be applied here
/* new body theme can be applied here */

@media (prefers-color-scheme: dark) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is uncommented now

}) => {
const currentTheme = (localStorage.getItem('theme') as Theme) || Theme.LIGHT
const [theme, setTheme] = useState<Theme>(currentTheme)
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the only logic changes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thoughts on moving this logic to a <script> in the <head> of the index.html? That should mean the user doesn't have to wait for the JS to be downloaded, and executed to have the correct colour set, when they visit the site 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did consider that approach, though I ended up on preferring to have all the theme logic in one place

Copy link
Copy Markdown
Contributor

@nicholas-codecov nicholas-codecov left a comment

Choose a reason for hiding this comment

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

Instead of mocking this out in all of these tests, can you mock it out in the vitest.config.mjs similar to how we're globally mocking out some Sentry stuff?

@ajay-sentry
Copy link
Copy Markdown
Contributor Author

Instead of mocking this out in all of these tests, can you mock it out in the vitest.config.mjs similar to how we're globally mocking out some Sentry stuff?

For sure, updated in 5a47a97

@ajay-sentry ajay-sentry added this pull request to the merge queue Oct 31, 2024
Merged via the queue into main with commit b92c538 Oct 31, 2024
@ajay-sentry ajay-sentry deleted the Ajay/2403-default-to-system-theme branch October 31, 2024 17:57
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.

The mode switches based on user's default system

3 participants