Skip to content

fix: auto theme does not update when OS switches day/night mode#12278

Open
jakub961241 wants to merge 1 commit into1Panel-dev:dev-v2from
jakub961241:fix/auto-theme-switch-6813
Open

fix: auto theme does not update when OS switches day/night mode#12278
jakub961241 wants to merge 1 commit into1Panel-dev:dev-v2from
jakub961241:fix/auto-theme-switch-6813

Conversation

@jakub961241
Copy link

Summary

Fixes #6813 (point 1) - When theme is set to "auto" (follow system), the panel doesn't switch between dark/light mode when the OS changes without a page reload.

Root Cause

useTheme() in frontend/src/global/use-theme.ts only evaluates window.matchMedia('(prefers-color-scheme: dark)').matches when switchTheme() is explicitly called. No listener is registered for the change event on the media query.

Fix

Added matchMedia.addEventListener('change', ...) that calls switchTheme() when the OS color scheme changes, but only when the theme setting is "auto". Listener is cleaned up via onUnmounted.

Changed file

  • frontend/src/global/use-theme.ts (+14)
fix: Auto theme now reactively switches when OS changes between light and dark mode (#6813)

…l-dev#6813)

When theme is set to "auto" (follow system), changing the OS from
light to dark (or vice versa) without reloading the page had no
effect. The theme was only evaluated once on page load.

Added a matchMedia 'change' event listener that calls switchTheme()
whenever the OS color scheme changes, but only when theme is "auto".
Listener is properly cleaned up on component unmount.

Fixes 1Panel-dev#6813 (point 1)
@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Mar 22, 2026

[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 wanghe-fit2cloud 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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 针对 1Panel 使用过程中的一些问题及建议反馈

1 participant