Repository: netbox-community/netbox

Issue:
Switch between dark/light mode doesn't take effect until user logs out and back in
### Deployment Type

Self-hosted

### NetBox Version

v4.0-beta1

### Python Version

3.10

### Steps to Reproduce

1. Log in as a user.
2. Click on the User menu in the top right
3. Click Preferences
4. Change color mode, and click Save at the bottom

### Expected Behavior

Color mode changes as soon as Save is clicked and the page refreshes to the new mode.

### Observed Behavior

Color mode doesn't change until user logs out of Netbox and back in.


Discussion:
I went back to my production (3.7.4) and discovered it does the same in the Preferences menu, but also found the menu item for light/dark mode switch which takes effect immediately.  That led me to the button which I noticed in beta that has the same function, but I didn't realize it was a button before.

Having said all that, I don't see why the preference can't change mode on Save, but I can also see why that wouldn't be a reasonable use of development time.
The first time I tried to reproduce this issue (going from dark to light), it behaved as expected. Each subsequent time I was able to reproduce it consistently regardless of which direction the color mode was going.
When the color mode is changed in User Preferences, you must log out and log in again for the changes to be applied. On the other hand, if you select "Dark" or "Light" on Preferences, the change is applied at the same time. 

If you want to apply the changes as soon as the color mode changes, please assign this ticket to me.
The root issue is that the user preference is stored on the backend, whereas the live toggle (the button at top right) saves its setting in local storage. So we can end up with a conflicting state where the user's preference indicates dark mode but local storage indicates light mode, or vice versa.

Honestly it feels like overkill to track light/dark mode as a preference anyway. I can easily see this being device- or time-dependent, and the live toggle makes much more sense IMO. Maybe we should just ditch the stored preference altogether.
> Honestly it feels like overkill to track light/dark mode as a preference anyway. I can easily see this being device- or time-dependent, and the live toggle makes much more sense IMO. Maybe we should just ditch the stored preference altogether.

The one arguement I could see is that if you move to new devices frequently, however I think that is a corner case and not the norm so we might not even care about it.

Resolving patch:
diff --git a/netbox/netbox/preferences.py b/netbox/netbox/preferences.py
--- a/netbox/netbox/preferences.py
+++ b/netbox/netbox/preferences.py
@@ -15,15 +15,6 @@ def get_page_lengths():
 PREFERENCES = {
 
     # User interface
-    'ui.colormode': UserPreference(
-        label=_('Color mode'),
-        choices=(
-            ('light', _('Light')),
-            ('dark', _('Dark')),
-        ),
-        default='light',
-        description=_('Preferred default UI theme')
-    ),
     'ui.htmx_navigation': UserPreference(
         label=_('HTMX Navigation'),
         choices=(
diff --git a/netbox/users/forms/model_forms.py b/netbox/users/forms/model_forms.py
--- a/netbox/users/forms/model_forms.py
+++ b/netbox/users/forms/model_forms.py
@@ -62,7 +62,7 @@ def __new__(mcs, name, bases, attrs):
 class UserConfigForm(forms.ModelForm, metaclass=UserConfigFormMetaclass):
     fieldsets = (
         FieldSet(
-            'locale.language', 'pagination.per_page', 'pagination.placement', 'ui.colormode', 'ui.htmx_navigation',
+            'locale.language', 'pagination.per_page', 'pagination.placement', 'ui.htmx_navigation',
             name=_('User Interface')
         ),
         FieldSet('data_format', name=_('Miscellaneous')),


Test patch: