-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Frontend Plan #17149
Comments
The draft is updated. Please help to improve. |
We should definitely move to vue3 and move away from jquery by rewriting parts as vue components but I hardly disagree on moving to JSX |
Another way: save server-templates front(maybe later simplify to base functionality) and in parallel start to rewrite new with vue and api |
About JSX:Pros
Cons
General speaking, I can see there is a lot of benefits when using JSX. If less a half of members disagree JSX, then we can continue? About server-templates and Vue and APIIn my mind, this frontend refactor should be done in one or two weeks, so we just make things clear first. I can not imagine that the frontend can be switched to Vue + API in short time, the frontend is big. It's OK for me to continue to use MVC templates (I can accept everything as long as it is clear and easy to maintain), so the MVC template is not a major problem now, and it is easy to debug and SEO-friendly. We can leave the rewriting work to each module, and choose the best solution one by one then. |
@lafriks vue3 also supports JSX, so I don't think JSX is totally unacceptable. I think we can mix template or JSX according the situations. |
Not true, as it's where hard to guess what's final HTML will look like especially for large components or pages, it's also hard to debug them. And in my opinion it looks very weird that JS is mixed with HTML without any separation.
Same with Vue templates
Same with Vue templates that are compiled to VDomNodes
Not true, you can write functional Vue components just as import any other utility code inside
We already have - As I already have said previously JSX looks like old shity PHP code when HTML was mixed all over the place with PHP. I have worked on large react apps where all frontend is in JSX and I know what pain in the as* it can be... 😆 There are things also in Vue that are pain to work with like vuex etc but JSX won't help with that either 😃 |
I also don't want to seem against other parts of proposal, I fully agree that we need to make an order in fronted part, it's just that one tiny thing (jsx) I don't agree with :) |
A note that we will also need to pay close attention to accessibility when updating the front end. Unrelated to the above, a casual suggestion for using tailwindcss in changes (I think v3 is out soon). |
@lafriks OK, I just thought JSX is nice to have (ps: I have most experiences in PHP among all languages, a good guideline makes PHP code as strict as other modern languages, JSX is similar). JSX is not a must, so we just use fomantic + Vue3 then. @techknowlogick there are so many codes depending on fomantic, it's not easy to switch to tailwindcss soon, maybe we can finish the first stage refactor soon (without introducing new frameworks), then discuss new frameworks later. |
About tailwind, we can have a try on some page and then make decision if it should be continued. |
sounds good! |
The PR #16770 uses the If this plan is generally acceptable, I hope the PR can be approved and merged soon, then we can move on. |
I have only one small nit about the Apart from that, I absolutely agree that such a mechanism is useful and needed. |
@delvh about I think PageData is better because:
====== Update: now we use |
Still we should refactor this so that all variables are named camelCase as per JS naming conventions |
This issue has fulfilled its mission. For frontend guidelines: https://docs.gitea.io/en-us/guidelines-frontend/ So we can close this one. |
Background
The frontend needs a big refactor now.
web_src/index.js
is too big to add new code (or modify/debug).initVueApp
/initVueComponents
is quite misleadingvar ActivityTopAuthors = {{Json .ActivityTopAuthors | SafeJS}};
is not a good idea.gitea/templates/repo/issue/view_content/sidebar.tmpl
Line 542 in d04e581
if ( $('.xxx').length == 0) return;
, we do not know what pages need this function, and these css class names may conflict. A little change may break something.document
, they may conflict. Add namespace to global click event #16833Guideline
kebab-case
.Plan
What frontend frameworks should be used?
I prefer fomantic + Vue3
How to pass backend data to frontend?
For simple data, it can be put into HTML
data-xxx
tag during template renderingFor complex data like array/map, it can be put into
window.config.pageData.xxx
. We write some common code to renderpageData
into JSON automatically in base template:Then backend work will be easy:
How to init frontend functions in a page?
We have two choices (I prefer keep and improve current mechanism)
Frontend functions depned on templates
It is the mechanism what we are using now. In
index.js
it calls every init function, every init function checks whehter current page has some DOM elements. If current page has the matched DOM elements, then the feature will be loaded.Pros:
Cons:
index.js
(maybe more than a hundred soon?)Templates call frontend init functions
index.js
exports init functions. Templates render scripts in HTML like this:When the page is loaded,
index.js
calls every function registered bywindow.config.ready
.Pros:
Cons:
Other suggestions?
TODO
Refactor Steps
(DONE) Complete a formal frontend guideline document in
docs/content/doc/developers/frontend.md
. The guideline can come from this draft.(DONE) Split
web_src/index.js
into small files inweb_src/features/
. Add function calls toinitXxx
inindex.js
as before. This step can be done ASAP, and must be reviewed and approved quickly to prevent from further conflicts. Any new feature should be placed inweb_src/features/
later.(DONE) Introduce a common mechanism to pass backend data to frontend. eg:
window.config.pageData
.(keep current mechanism) Introduce or improve a common mechanism to call page related
init
functions.[FUTURE] Upgrade Vue from 2 to 3.
[DONE] If a change is made to legacy frontend code, the author should also follow the guideline to refactor related modules.
[FUTURE] Implement common and reusable code to resolve legacy frontend issues.
The text was updated successfully, but these errors were encountered: