Opened 17 months ago

Closed 17 months ago

Last modified 17 months ago

#34741 closed Uncategorized (duplicate)

Admin flashes dark/light depending on settings

Reported by: Spencer Lowe Owned by: nobody
Component: contrib.admin Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

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.

Change History (2)

comment:1 by Spencer Lowe, 17 months ago

Resolution: invalid
Status: newclosed

comment:2 by Mariusz Felisiak, 17 months ago

Resolution: invalidduplicate

Duplicate of #34740.

Note: See TracTickets for help on using tickets.
Back to Top