#34741: Admin flashes dark/light depending on settings
-----------------------------------------+------------------------
               Reporter:  nerdbaggy      |          Owner:  nobody
                   Type:  Uncategorized  |         Status:  new
              Component:  contrib.admin  |        Version:  4.2
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  1              |
-----------------------------------------+------------------------
 When the user has their prefers-color-scheme set to dark, and then they
 force the Django Admin to light mode it causes the page to flash dark then
 light momentarily. (See attached video). This test video is on a fresh
 install with no extra apps installed.

 Why is this happening you may ask. The JS code that forces the theme to
 dark/light is set to run on page load.
 
https://github.com/django/django/blob/main/django/contrib/admin/static/admin/js/theme.js#L3

 Because of this the full page loads for a moment with the dark theme, then
 the page load event happens and then the js code changes the theme to
 light.
 The initTheme() and setTheme() functions don't really need to be inside
 the event page load. Nothing in those 2 functions are doing anything that
 require the entire page to be loaded. It is just using local storage and
 modify the dataset on the html div. So those functions could be moved
 outside of the on load event. I don't mind making the merge request for it
 just wanted to get opinions on it.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34741>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701898ec7509d-99d69f20-8aa4-4d8c-9e83-555cb55c0060-000000%40eu-central-1.amazonses.com.

Reply via email to