Description
Description
When using a theme that contains semi-transparent backgrounds for UI elements, Gitea will throw a JS error due to the way the cards are sorted (see screenshot 1).
Due to this JS error, most functionality dependent on JS fails, such as edit or delete buttons.
The error (in the source code) leads to the file web_src/js/features/repo-projects.js
, lines 59
and 203
.
The error occurs because of the following reasons:
- Each project card may have a colour, or none.
- If the project card has no colour, the default CSS colour is used.
- Some themes have semi-transparent UI elements, with
background-color: rgba(0, 0, 0, 0.15);
, for example. repo_projects.js
wants to sort cards by colour.- The colour of the cards is extracted from the CSS.
- The colour is matched to the pattern
rgb(x, y, z)
, which does not take into account that themes may define colours asrgba(x, y, z, a)
. - (The colour is communicated through a PUT request).
Proposed Solutions
- Change the regex from
^rgb\((\d+),\s*(\d+),\s*(\d+)\)$
to^rgba?\((\d+),\s*(\d+),\s*(\d+)(.*)?\)$
and ignore the alpha channel from the sorting criteria. - Change the regex from
^rgb\((\d+),\s*(\d+),\s*(\d+)\)$
to^rgba?\((\d+),\s*(\d+),\s*(\d+)(,\s*(\d+(\.\d+)?))?\)$
(alpha channel is a float orNaN
on 5th group) and include the alpha channel in the sorting criteria. - Rethink on why you're reading colours out of the CSS in the first place, then reformat this sorting procedure.
History
Going back in the git history, this bug was implemented in commit ecfac78 with merge request #16647 on 17/08/2021 in order to get Kanban colour sorting.
Reproduce
- Get any instance of Gitea running
- Configure a theme with semi-transparent UI elements, for example 'hotpink' from theme.park:
- Add
data/gitea/templates/custom/body_outer_pre.tmpl
with body:{{ if .IsSigned }} {{ if and (ne .SignedUser.Theme "gitea") (ne .SignedUser.Theme "arc-green") }} <link rel="stylesheet" href="https://theme-park.dev/css/base/gitea/{{.SignedUser.Theme}}.css"> {{end}} {{ else if and (ne DefaultTheme "gitea") (ne DefaultTheme "arc-green") }} <link rel="stylesheet" href="https://theme-park.dev/css/base/gitea/{{DefaultTheme}}.css"> {{end}}
- Add to
data/gitea/conf/app.ini
:[ui] THEMES = gitea,arc-green,plex,aquamarine,dark,dracula,hotline,organizr,space-gray,hotpink,onedark,overseerr,nord DEFAULT_THEME = gitea
- Alternatively, pick any theme and add the CSS rule
.ui.segment { background: rgba(0, 0, 0, 0.28) !important; }
.
- Add
- Go to any repository, open the
Projects
tab, and open a project. - Make sure at least one board has no colour assigned.
- Error will pop up on the top of the screen.
Gitea Version
latest, v1.9.6
Can you reproduce the bug on the Gitea demo site?
Yes
Log Gist
No response
Screenshots
Screenshot 1 (JavaScript error)
Screenshot 2 (Semi-transparent UI elements)
Git Version
No response
Operating System
default docker image; Void Linux on Linux m-desktop 6.0.10_1 #1 SMP PREEMPT_DYNAMIC Mon Nov 28 03:42:58 UTC 2022 x86_64 GNU/Linux
How are you running Gitea?
This issue can be replicated on both the default Docker image and when building Gitea from source.
Database
None