#34740 closed Bug (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.

Attachments (1)

django-flash(2).mp4 (173.6 KB ) - added by Spencer Lowe 14 months ago.

Download all attachments as: .zip

Change History (3)

by Spencer Lowe, 14 months ago

Attachment: django-flash(2).mp4 added

comment:1 by Spencer Lowe, 14 months ago

Type: UncategorizedBug

comment:2 by Mariusz Felisiak, 14 months ago

Resolution: duplicate
Status: newclosed

Duplicate of #34670.

Nerdbaggy, Can you add a comment to the #34670 and provide details about why and where Django is at fault?

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