-
Notifications
You must be signed in to change notification settings - Fork 186
PMM-14624: Fix theme inheritance between users #4830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dmitri-saricev-3pillargloball
merged 6 commits into
v3
from
PMM-14624-Fix-theme-inheritance
Jan 9, 2026
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b88a0d8
PMM-14624: Fix theme inheritance between users
dmitri-saricev-3pillargloball f2aebae
Merge branch 'v3' into PMM-14624-Fix-theme-inheritance
dmitri-saricev-3pillargloball 018427d
change provider name
dmitri-saricev-3pillargloball bce2068
Fix PR review comments
dmitri-saricev-3pillargloball 597a3e4
Use GetPreferenceResponse in getUserPreferences
dmitri-saricev-3pillargloball a057354
Merge branch 'v3' into PMM-14624-Fix-theme-inheritance
dmitri-saricev-3pillargloball File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,11 @@ export const getCurrentUserOrgs = async () => { | |||||
| return res.data; | ||||||
| }; | ||||||
|
|
||||||
| export const getUserPreferences = async () => { | ||||||
| const res = await grafanaApi.get<UpdatePreferencesBody>('/user/preferences'); | ||||||
|
||||||
| const res = await grafanaApi.get<UpdatePreferencesBody>('/user/preferences'); | |
| const res = await grafanaApi.get<GetPreferencesResponse>('/user/preferences'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { useEffect, useRef } from 'react'; | ||
| import { useUserPreferences } from './api/useUser'; | ||
| import { useColorMode } from './theme'; | ||
| import { useAuth } from 'contexts/auth'; | ||
| import { ColorMode } from '@pmm/shared'; | ||
|
|
||
| const DEFAULT_THEME: ColorMode = 'dark'; | ||
|
|
||
| /** | ||
| * Synchronizes user theme from Grafana API on initial load. | ||
| * Fixes PMM-14624 where new users inherit theme from localStorage. | ||
| * | ||
| * Problem: /api/user returns empty theme field, and ThemeContextProvider | ||
| * was using localStorage causing theme inheritance between users. | ||
| * | ||
| * Solution: Load theme from /api/user/preferences on login and apply | ||
| * via setFromGrafana (without broadcast/persist to avoid loops). | ||
| */ | ||
| export const useThemeSync = () => { | ||
| const auth = useAuth(); | ||
| const { | ||
| data: preferences, | ||
| isLoading, | ||
| error, | ||
| } = useUserPreferences({ | ||
| enabled: auth.isLoggedIn, | ||
| }); | ||
| const { setFromGrafana } = useColorMode(); | ||
| const syncedRef = useRef(false); | ||
|
|
||
| // Reset synced flag when user logs out | ||
| useEffect(() => { | ||
| if (!auth.isLoggedIn) { | ||
| syncedRef.current = false; | ||
| } | ||
| }, [auth.isLoggedIn]); | ||
|
|
||
| useEffect(() => { | ||
| if (!auth.isLoggedIn || isLoading || syncedRef.current || !preferences) { | ||
| return; | ||
| } | ||
|
|
||
| if (error) { | ||
| console.error('[useThemeSync] Failed to load user preferences:', error); | ||
| return; | ||
| } | ||
|
|
||
| const themeToApply = preferences.theme || DEFAULT_THEME; | ||
|
|
||
| // Apply theme from preferences | ||
| setFromGrafana(themeToApply) | ||
| .then(() => { | ||
| syncedRef.current = true; | ||
| }) | ||
| .catch((err: unknown) => { | ||
| console.error('[useThemeSync] Failed to apply theme:', err); | ||
| }); | ||
| }, [preferences, isLoading, error, setFromGrafana, auth.isLoggedIn]); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.