Opened 6 months ago

Closed 5 months ago

#36312 closed Cleanup/optimization (fixed)

dark_mode.css has invalid size units for svg in Safari

Reported by: Christian Wiegand Owned by: Ahmed Nassar
Component: contrib.admin Version: dev
Severity: Normal Keywords: admin css
Cc: Fabian Braun Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In django admin the javascript console shows some error messages

Error: Invalid value for <svg> attribute width="1.5rem"

This ist caused by an invalid size unit "1.5rem" in the django/contrib/admin/static/admin/css/dark_mode.css:

.theme-toggle svg {
    vertical-align: middle;
    height: 1.5rem;
    width: 1.5rem;
    display: none;
}

According to the specs svg doesn't allow "rem" as a valid unit (although some browsers will set the correct size).

Attachments (1)

Bildschirmfoto 2025-04-10 um 19.46.13.png (214.4 KB ) - added by Christian Wiegand 6 months ago.

Download all attachments as: .zip

Change History (15)

comment:1 by Christian Wiegand, 6 months ago

Not sure, if this is a problem only in Safari browser. Thought about providing a pull request to fix the issue, but there's maybe more of it behind, that I'm not aware of. So let me know, if a PR is welcome or otherwise we can just close this.

comment:2 by Natalia Bidart, 6 months ago

Easy pickings: unset
Resolution: needsinfo
Status: assignedclosed

Hello Christian Wiegand, thank you for your ticket. I have tried with Firefox and Chrome, and I don't get any errors in the Javascript console. Could you please provide extra information, specifically a way to reliable reproduce? Thank you!

by Christian Wiegand, 6 months ago

comment:3 by Christian Wiegand, 6 months ago

Hi Natalia, thanks for looking into that. The issue is easy to reproduce as long you have access to a Mac computer. I'm observing this issue since about 1.5 to two years.

If you open any Django App in Safari, goto Django admin and open the javascript console. It shows the error messages described above, no conditions. It's always there in the admin since the dark mode was introduced for Django admin. I attached an image of the javascript console to the issue.

The error messages are gone as soon as I replace the "1.5rem" size units with "24px" in the above quoted css code. Thought about providing a PR but then I read some articles that this maybe an error in Safari. Although there are hints around the net that generally SVG doesn't support "rem" or "em" units (since the dimensions in svg are a little more complex). As far as I learned SVG can only be sized in rem via the font-size css statement (and yes, I'm now 64 and retired, so my knowledge on svg graphics maybe stale ;-)). At least stated here: https://stackoverflow.com/questions/10325070/svg-translate-with-em-as-unit and here: https://www.w3.org/TR/SVG/coords.html#Units.

Anyway, I would be able to stand the error messages, so nothing really critical. Even if not being fixed, it would be nice to document here, so any other people worrying about the messages can follow the arguments.

Thanks, Christian

Last edited 6 months ago by Christian Wiegand (previous) (diff)

comment:4 by Natalia Bidart, 6 months ago

Resolution: needsinfo
Status: closednew
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization
Version: 5.2dev

Thank you Christian, other users using Safari have been able to reproduce. Accepting on that basis.

comment:5 by Natalia Bidart, 6 months ago

Summary: dark_mode.css has invalid size units for svgdark_mode.css has invalid size units for svg in Safari

comment:6 by Ahmed Nassar, 5 months ago

Owner: changed from cwiegand to Ahmed Nassar
Status: newassigned

comment:7 by Ahmed Nassar, 5 months ago

Has patch: set

comment:8 by Fabian Braun, 5 months ago

Cc: Fabian Braun added

comment:9 by Fabian Braun, 5 months ago

Patch needs improvement: set

Besides within the CSS, the width="1.5rem" etc. are part of the base.html template. The current patch does not remove the error messages on the Safari console for me when testing locally. Can you take a look at those, too?

Version 0, edited 5 months ago by Fabian Braun (next)

comment:10 by Ahmed Nassar, 5 months ago

Patch needs improvement: unset

comment:11 by Fabian Braun, 5 months ago

Patch needs improvement: set

comment:12 by Ahmed Nassar, 5 months ago

Patch needs improvement: unset

comment:13 by Fabian Braun, 5 months ago

Triage Stage: AcceptedReady for checkin

comment:14 by Sarah Boyce <42296566+sarahboyce@…>, 5 months ago

Resolution: fixed
Status: assignedclosed

In fbdbccf2:

Fixed #36312 -- Removed invalid size units for svg in Safari.

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