Skip to content

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

Merged
wanghe-fit2cloud merged 1 commit into1Panel-dev:dev-v2from
jakub961241:fix/auto-theme-switch-6813
Mar 23, 2026
Merged

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

Conversation

@jakub961241
Copy link
Copy Markdown
Contributor

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
Copy Markdown

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

@lan-yonghui
Copy link
Copy Markdown
Member

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm label Mar 23, 2026
@wanghe-fit2cloud wanghe-fit2cloud merged commit 5a80931 into 1Panel-dev:dev-v2 Mar 23, 2026
1 check was pending
HynoR pushed a commit to HynoR/1Panel that referenced this pull request Mar 29, 2026
…l-dev#6813) (1Panel-dev#12278)

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)
justadri pushed a commit to justadri/1Panel that referenced this pull request Mar 29, 2026
…l-dev#6813) (1Panel-dev#12278)

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)
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 使用过程中的一些问题及建议反馈

3 participants