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)
Change History (15)
comment:1 by , 6 months ago
comment:2 by , 6 months ago
Easy pickings: | unset |
---|---|
Resolution: | → needsinfo |
Status: | assigned → closed |
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 , 6 months ago
Attachment: | Bildschirmfoto 2025-04-10 um 19.46.13.png added |
---|
comment:3 by , 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
comment:4 by , 6 months ago
Resolution: | needsinfo |
---|---|
Status: | closed → new |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
Version: | 5.2 → dev |
Thank you Christian, other users using Safari have been able to reproduce. Accepting on that basis.
comment:5 by , 6 months ago
Summary: | dark_mode.css has invalid size units for svg → dark_mode.css has invalid size units for svg in Safari |
---|
comment:6 by , 5 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 5 months ago
Has patch: | set |
---|
comment:8 by , 5 months ago
Cc: | added |
---|
comment:9 by , 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?
comment:10 by , 5 months ago
Patch needs improvement: | unset |
---|
comment:11 by , 5 months ago
Patch needs improvement: | set |
---|
comment:12 by , 5 months ago
Patch needs improvement: | unset |
---|
comment:13 by , 5 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
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.