mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-12 02:24:21 -05:00
[Proposal] Refactor frontend hide/hidden mechanism #10247
Closed
opened 2025-11-02 09:02:03 -06:00 by GiteaMirror
·
26 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16.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
v1.4.0-rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#10247
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @wxiaoguang on GitHub (Feb 10, 2023).
The Problem
There are at least 5 different "hiding" methods in code:
.hiddenclass[hidden]attribute.hideclassstyle="display: none"hide()(show/toggle)Some of these mechanisms just conflict:
[hidden]is the weakest one, it will be affected bydisplay: xxxdisplay: none !importantto overwrite other style'sdisplay: block.hiddenhas other definitions for different selectorshide()may not work well with somedisplay: none !importantThe Solution
.gt-hidden { display: none !important; }!importantis necessary because there are alwaysblockorflexelements need to be hiddenhide()and related functions to use our.gt-hidden.gt-hiddento hideFAQ
Why the
gu-prefix? (Or something else likegt-, etc...)@silverwind commented on GitHub (Feb 10, 2023):
Another problem with jQuery
hideandshowis that like any other inline CSS, it does not work without CSPunsafe-inline, so that is another reason to remove it. Als with the removal enable the eslint rulesjquery/no-hideandjquery/no-showto detect cases and forbid them in future code.I'm not sure about the classname prefix. I'm more of the opinion we should eventually migrate to tailwind or one of it's many "forks", and for this use case, we better match the helper names to those frameworks (thought I imagine we can not get around the
!importantrequirement for the helpers until we remove fomantic-ui completely.@wxiaoguang commented on GitHub (Feb 10, 2023):
Really? I think
unsafe-inlineonly forbids thestyle="xxx"in HTML, but it doesn't forbid changing style by JS, right? Correct me if I am wrong.About "eventually migrate to": I am not sure how long does "eventually" mean. If it means years, I wouldn't say that's practicable or feasible. I have explained the refactoring problem in the jQuery-dropping discussion: if there is no plan to guarantee that the refactoring can succeed in short time, people come and go, code using old framework always comes, then it will become a endless whack-a-mole game.
The prefix is a must.
.hiddenfrom#22845is different from tailwind or other frameworks. They would conflict in the end.Update: one more thing, the
!importantseems necessary in Gitea's frontend framework, because there are always someblockorflexelements need to be hidden.@wxiaoguang commented on GitHub (Feb 10, 2023):
Also call TOC here, go or no go.
@lunny @techknowlogick @6543 @zeripath @jolheiser @wolfogre
@wolfogre commented on GitHub (Feb 10, 2023):
TBH, I don't have enough front-end development experience to judge this. In response, I abstain and respect the opinions of other TOC.
@silverwind commented on GitHub (Feb 10, 2023):
It seems needlessly complex to me to introduce a gitea-specific class prefix. Some people are accustomed to tailwind classes, so I would make it easy for them and use the original class names (which may conflict with fomantic, but fomantic needs to go sooner or later anyways).
If possible, I'd like us to implement tailwind-compatible classes, but I'm not sure how the tooling can be made to parse the golang templates so their tree-shaking of classes can work. I imagine a special parser will be necessary to extract classes in-use from the go templates. Also, I'm pretty sure we will need the
!importantsuffix on all rules, at least until we get rid of fomantic.@wxiaoguang commented on GitHub (Feb 10, 2023):
Most people just copy & paste the existing code in project. They do not care what are the details behind it.
Your
.hiddenwith!importantis not really tailwind style. Tailwind's hidden doesn't have the!important, the different behavior may surprise developer much more.You can see there are:
.ui.checkbox input.hidden { z-index: -1;}.ui.menu .hidden { visibility: none;}Maybe more.
When?
@silverwind commented on GitHub (Feb 10, 2023):
Yes, tailwind by default assumes it is the only style system in use and in such a happy world, there is no need for
!important, but as soon as you add another, specificity issues are bound to happen and can only be remedied by!important.@wxiaoguang commented on GitHub (Feb 10, 2023):
So , do not make the
.hiddenharder to understand.Even with the
.gu-prefix, after removing the fomantic, you can do a global replace to rename it to anything you like. That's the good side of the prefix.@silverwind commented on GitHub (Feb 10, 2023):
BTW I'm tired of having to discuss this
!importanttopic again and again. It is a necessary evil that can not be removed unless you have a single style system which will not happen until at least fomantic is out.@wxiaoguang commented on GitHub (Feb 10, 2023):
I have said
!importantis necessary for this case (many times in this issue). My point is clear: do not make surprise for developers. Make every name clear and unique/dedicated.@wxiaoguang commented on GitHub (Feb 10, 2023):
OK, let's focus on this problem. Could you agree with:
.hiddenstyle, you do the refactoring (you choose the time).gu-hiddenstyle, I do the refactoring (I will try to finish it in a few days)@jolheiser commented on GitHub (Feb 10, 2023):
Tailwind or not, is there any way to do a gradual transition? And which style do you think would make that hypothetical transition easier?
If parsing the templates is doable, and we can post-process to add
!important, maybe that's feasible?@wxiaoguang commented on GitHub (Feb 10, 2023):
The transition plan is: removing Fomantic modules one by one, for example, the tooltip, image, ... modules have been removed, customized dropdown has been reverted to the official one, etc. Maybe the checkbox module could be removed next.
But this style discussion is not related to the transition. The
hiddenclass is an essential CSS class, it's the lowest-level design.The divergence is:
.hiddenname from Fomantic UI, which is (in my mind):.gu-hidden, then:There is nothing with the
!importantindeed, it is necessary for either.hiddenor.gu-hidden.Above is just my opinion, and I am open for TOC's final decision.
@wxiaoguang commented on GitHub (Feb 10, 2023):
One more thing worth to be mentioned: it's widely accepted to add prefixes for frameworks. For example, tailwind also supports prefix: https://tailwindcss.com/docs/configuration#prefix . If we want to introduce it, the prefix is always the best choice, to avoid unnecessary conflicts:
.tw-hidden,.tw-text-left, etc.@zeripath commented on GitHub (Feb 10, 2023):
I guess the question is do we have any other things that would have this proposed
gu-prefix?At present, this would stand out completely separately from the rest of our class names - and I'm not sure of the benefit when we could just use
.hidewhich is essentially your proposed style just lacking the!important.I think fomantic's
.hiddenhas different definitions for different selectors because the proposeddisplay: none !important;is a bit of blunderbuss and fomantic has its own semantics related to hidden that are not completely about making things absolutely invisible. Thus I think overloading that will be a bad idea.Of course I guess we could actually prefix all of those other
!importantclass modifiers that we have, e.g.mr-2becomesgu-mr-2that would at least make them less likely to conflict with things and make us more likely to just move them into classes - like they should be.In fact if we can just drop all of our modifications from base fomantic, and begin moving code on to
gitea-classes that might, just might, make extracting out fomantic easier.So:
.hidden- it will conflict with fomantic. We're already seeing issues where we've broken fomantic's styling and we blame it when it's often due to styling we've imposed on top of it.gu-prefix - having only one class with the prefix is janky as hell. If there are others then it makes more sense..hidemight be the answer - leave.hiddenfor fomantic.What's motivated you into looking in to this? Why now? Why this particular weirdness?
@lunny commented on GitHub (Feb 11, 2023):
I learnt something from introducing #21986 . If we want to do a big refactor, introduce a new method/mechanism is easier than replacing the old method/mechanism. If this is the beginning of the refactor from Fomantic-UI to Tailwind, I agree to have a prefix will be better for the progress of migrating. For the prefix name, we could have more thought than
gu.@wxiaoguang commented on GitHub (Feb 11, 2023):
Answer to:
I have been thinking about this problem since my first frontend refactoring plan (the time I started spending time on Gitea), see #17149 (I would suggest people to read it again .... those are all mistakes Gitea had made in history) and related https://docs.gitea.io/en-us/guidelines-frontend/#gitea-specific-guidelines :
I have realized at that time:
But there were a lot of obstructions for doing refactoring. Recently there is TOC for Gitea, I'd like to see whether it's possible to push the refactoring and make the codebase more healthy.
For the
hidingproblem itself:hiding-related bugs (maybe a lot), it wastes a lot of time (details in the The Problem section)@zeripath commented on GitHub (Feb 12, 2023):
OK, the #22845 farago has absolutely convinced me.
The helpers MUST have a prefix.
I've just looked at tailwind and now it's clear to me what's happening to our styling over time... and it's clear to me that we're going to have more and more conflict with fomantic over time and if we're going to do that, we should do it using a prefix. I guess the intention is that a tailwind website has no separate less/css and everything is just done with classes in the html? Well if we want to do that - it should be easy to just double add classes for fomantic and tailwind with the tailwind classes prefixed with
tw-and you can turn on and off styling with fomantic by switching in and out style file loading.(It would of course be better if we could get all fomantic classes to have a prefix too - e.g.
.fo-uibut that would any and all of the downstream themes and stylers, or get the fomantic classes to only fire if there is some root class but I don't think it can be done.)Therefore, in addition, we should start putting a prefix on all of own document-semantic classes because otherwise it's just too hard to separate them from fomantic's.
One thing that's clear to me is that as people are moving to tailwind one of the things we're going to lose is the ability to use fomantic's documentation as descriptors for prototyping. So if the intention is tailwind we're going to need common examples of what we we're going to use.
I do think it's worth saying again - our overloading of fomantic styling has and is causing a number of problems, for example, at some point we had in our less files:
.right { float: right;}(we may still have this), unsurprisingly this breaks lots of fomantic styling which uses/used.rightin a more complex and subtle way.This problem with
.hiddenabove is similar.Far too often we're not working with fomantic styling - we're working against it by treating it as if its tailwind when it is not - and this is at least partially due to the fact that we've already broken fomantic's styling in many places so when things are broken we're not aware of why and we blame fomantic unfairly.
However, I don't think we can go back to a situation where we can fix our styling to be compatible with plain fomantic anymore - certainly I don't think people want to. The fragility we have isn't going to get any better until we've got the templates not dependent on fomantic - so lets just do that.
Let's just follow the plan in here:
https://dev.carsonbain.com/blog/migrate-project-to-tailwind-css
Markup the templates with non-tailwind helpers having
g-h-prefixgt-has been chosen and tailwind classes with atw-prefix and then get it to a point where we can drop fomantic. Consider usingjs-class for hooks for javascript or id where appropriate and stickgitea-prefixes on specific components.But let's be honest about what's happening to our styling - it's being turned into tailwind - so let's just do that.
@wxiaoguang commented on GitHub (Feb 12, 2023):
I'm afraid we can not just follow everything in https://dev.carsonbain.com/blog/migrate-project-to-tailwind-css. It only works for a team with strong leadership.
TLDR: The migration needs detailed plan and guideline for Gitea.
There are some problems for Gitea:
!important, otherwise some Gitea's styles may need doube-important to overwrite the tailwind styles. So it requires that the new code should be clear on Gitea side.DashboardRepoListorRepoBranchTagDropdown-- which mix Go Template/Fomantic UI/Vue3/jQuery together. Maybe nobody wants to touch them (maybe except me because I had plan to refactor them ....)@zeripath commented on GitHub (Feb 12, 2023):
That's what I'm trying to suggest here.
It's clear that we're migrating to a tailwind situation already so let's stop pretending.
You want to help? Come back and let's just do that. A cabal of three people is all it needs.
@delvh commented on GitHub (Feb 12, 2023):
Okay, I'm also somewhat an outsider when it comes to UI development.
The following is purely based on my previous experience here, and what I read in this thread so far:
Current Behavior
!importants. How is anyone supposed to know what will work, and what won't?Expected Behavior
My opinion
From what I've seen now of tailwind, it seems to fix most of these problems, if we refactor everything.
I agree with you, @wxiaoguang, this will only work if we set a strict roadmap for how to approach that refactoring.
I am already surprised that we managed three partial major refactors for 1.19:
models/servicesimports insidemodulesI also don't think overloading classes used for other things already is a good idea.
Nor do I think it's a good idea to follow point three of the blog linked above (
everything !important).The other two points sound fine (
prefix for tailwind classes, andfreeze old code).Yes, if we keep consistent with our class prefixes, this should make a lot of things much easier.
I agree with @zeripath that the best prefix distribution is probably
tw-for tailwind classesgitea-for semantic classes (i.e.gitea-diff-box)js-for classes queried in JSRegarding how to
freeze old code: I think that's pretty simple to achieve:Simply change the corresponding filenames by prepending a
legacy-for example.That way, it's easy to see what is new, and what isn't.
Other refactors we also need to do at some point
ctxfor most methods as first parametermodels/servicesimports insidemodulesslogexp/maps/exp/slicesonce they are notexpanymore.How to manage all these refactorings
If we just do these things without a "roadmap", as you said, @wxiaoguang, things will fall apart or be left half-finished.
I think there's only one way to ensure all refactorings are completed:
We need a specific "refactoring manager" that is responsible for
Every other way will likely end in chaos:
@wxiaoguang commented on GitHub (Feb 12, 2023):
Hmm, I see. Maybe the tailwind topic is a little off-topic of this proposal.
Let's back to this proposal, and postpone the tailwind topic to another proposal.
TLDR: tailwind's
hiddencouldn't help Gitea at the moment, Gitea needs its ownhiddenmechanism.Details: This proposal's hiding-method problem should be resolved by Gitea itself, but can not be helped by tailwind. The reason is that there are still a lot of jQuery code need to do show/hide, and we need our
hiddenstyle to hide somedisplay: block/flexelements.So, I think it's better to start cleaning up the hiding-method problem as the first step.
@zeripath commented on GitHub (Feb 12, 2023):
I'm just looking at rewriting helpers.less to use
g-h-as a prefix and I've already found one conflict:This is used in chroma for its type to represent a string backtick but it has a helper class applied to it by the helpers.less that fortunately doesn't ruin the styling but is a conflict.
@lunny commented on GitHub (Feb 12, 2023):
Would you create a new issue about the frontend refactors? I prefer that we can have a principle like refactoring review/merge first, then we can keep fewer conflicts between refactors and features.
@wxiaoguang commented on GitHub (Feb 13, 2023):
About "Would you create a new issue about the frontend refactors?", see Add some guidelines for refactoring #22880
And the first step is ready for review: Extend jQuery with customized show/hide/toggle #22884
@wxiaoguang commented on GitHub (Feb 17, 2023):
The final step (all in one) Refactor hiding-methods, remove jQuery show/hide, remove .hide class, remove inline style=display:none #22950