Skip to content
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

Rewrite and restyle reaction selector and enable no-sizzle eslint rule #30453

Merged
merged 20 commits into from
Apr 14, 2024

Conversation

silverwind
Copy link
Member

@silverwind silverwind commented Apr 13, 2024

Enable no-sizzle lint rule, there was only one use in initCompReactionSelector which I have rewritten as follows:

  • Remove all jQuery except the necessary fomantic dropdown init
  • Remove the recursion, instead bind event listeners to common parent container nodes

Did various tests, works with our without attachments, in diff view and in diff comments inside comment list.

Additionally the style of reactions now matches between code comments and issue comments:

Screenshot 2024-04-13 at 14 58 10

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 13, 2024
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 13, 2024
@silverwind silverwind added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Apr 13, 2024
@silverwind
Copy link
Member Author

Found one pre-existing bug in diff comments where all reactions go missing after clicking a existing reaction in the emoji button.

@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 13, 2024
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files labels Apr 13, 2024
@wxiaoguang
Copy link
Contributor

Major changes:

  • clean up unnecessary CSS styles
  • make the selectors have clear names (now we can search select-reaction and comment-reaction-button globally to see how they work)
  • simplify the JS code, some logic are dead code from legacy, and I think the code reads better now

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 13, 2024
@wxiaoguang wxiaoguang merged commit 4b1063f into go-gitea:main Apr 14, 2024
26 checks passed
@GiteaBot GiteaBot added this to the 1.23.0 milestone Apr 14, 2024
GiteaBot added a commit to GiteaBot/gitea that referenced this pull request Apr 14, 2024
go-gitea#30453)

Enable `no-sizzle` lint rule, there was only one use in `initCompReactionSelector` and:

- Remove all jQuery except the necessary fomantic dropdown init
- Remove the recursion, instead bind event listeners to common parent container nodes

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Giteabot <teabot@gitea.io>
@GiteaBot GiteaBot added backport/done All backports for this PR have been created and removed reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels Apr 14, 2024
@silverwind silverwind deleted the nosizzle branch April 14, 2024 11:32
silverwind added a commit that referenced this pull request Apr 14, 2024
#30453) (#30473)

Backport #30453 by @silverwind

Enable `no-sizzle` lint rule, there was only one use in
`initCompReactionSelector` which I have rewritten as follows:

- Remove all jQuery except the necessary fomantic dropdown init
- Remove the recursion, instead bind event listeners to common parent
container nodes

Did various tests, works with our without attachments, in diff view and
in diff comments inside comment list.

Additionally the style of reactions now matches between code comments
and issue comments:

<img width="275" alt="Screenshot 2024-04-13 at 14 58 10"
src="https://github.com/go-gitea/gitea/assets/115237/9d08f188-8661-4dd9-bff4-cad6d6d09cab">

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@silverwind
Copy link
Member Author

Hmm, I get 500 now:

Render failed, failed to render template: repo/issue/view, error: template error: builtin(static):repo/issue/view_content/reactions:3:33 : executing "repo/issue/view_content/reactions" at <ctx>: invalid value; expected int64
----------------------------------------------------------------------
	{{$hasReacted := $value.HasUser ctx.RootData.SignedUserID}}

Hmm I'm getting this now after a make clean-all when viewing certain PRs.

@silverwind
Copy link
Member Author

It seems ctx.RootData.SignedUserID is nil.

@wxiaoguang
Copy link
Contributor

Hmm I'm getting this now after a make clean-all when viewing certain PRs.

Is it reproducible?

@silverwind
Copy link
Member Author

It's strange, it only happens on one specific PR in my dev instance, others work.

@wxiaoguang
Copy link
Contributor

Could you add {{DumpVar ctx.RootData}} to see its content?

@silverwind
Copy link
Member Author

It seems NewTemplateContextForWeb is not being called.

@silverwind
Copy link
Member Author

{{DumpVar ctx.RootData}}

dumpVar: <nil> null

@wxiaoguang
Copy link
Contributor

It seems NewTemplateContextForWeb is not being called.

That seems impossible ... if NewTemplateContextForWeb isn't called, then NewWebContext isn't called, then the whole ctx system is impossible to work.


Then what's the {{DumpVar ctx}} ?

@silverwind
Copy link
Member Author

{{DumpVar ctx}}

It's there, and massive.

dumpVar: context.TemplateContext
{
  "AvatarUtils": {},
  "Locale": {
    "Lang": "en-US",
    "LangName": "English",
    "Locale": {}
  },
  "_ctx": {
    "Base": {
      "Data": {
        "AllLangs": [
          {

@silverwind
Copy link
Member Author

So something else must be rendering the template before NewWebContext is ran.

@wxiaoguang
Copy link
Contributor

{{DumpVar ctx}}

It's there, and massive.

Do you see RootData in the output? If no, it means that you are running a incorrect backend.

@silverwind
Copy link
Member Author

Errors is happening here:

2024/04/14 16:36:47 .../context_response.go:87:HTML() [E] Render failed: failed to render template: repo/issue/view, error: template error: builtin(static):repo/issue/view_content/reactions:4:33 : executing "repo/issue/view_content/reactions" at <ctx>: invalid value; expected int64
----------------------------------------------------------------------
	{{$hasReacted := $value.HasUser ctx.RootData.SignedUserID}}
	                                ^
----------------------------------------------------------------------

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Apr 14, 2024

{{DumpVar ctx}}

It's there, and massive.

Do you see RootData in the output? If no, it means that you are running a incorrect backend.

Do you see RootData (the map key) in the {{DumpVar ctx}} output? If no, it means that you are running a incorrect backend.

@silverwind
Copy link
Member Author

silverwind commented Apr 14, 2024

Ok I found it, there was a zombie process, presumably from unclean make watch termination, killed it, now it's ok. I wonder if I can make make watch more reliably kill the processes.

@wxiaoguang
Copy link
Contributor

That's why I said many times I don't use make watch ........... so my code is generally stable enough 😁

@silverwind
Copy link
Member Author

silverwind commented Apr 14, 2024

That's why I said many times I don't use make watch ........... so my code is generally stable enough 😁

I think the problem is air sometimes not killing off the child, I think #30477 should help, at least on subsequent air runs.

silverwind added a commit to silverwind/gitea that referenced this pull request Apr 14, 2024
* origin/main: (35 commits)
  Remove fomantic button module (go-gitea#30475)
  Improve "must-change-password" logic and document (go-gitea#30472)
  Fix commitstatus summary (go-gitea#30431)
  Remove fomantic menu module (go-gitea#30325)
  Use `flex-container` for dashboard layout (go-gitea#30214)
  Rewrite and restyle reaction selector and enable no-sizzle eslint rule (go-gitea#30453)
  Pulse page improvements (go-gitea#30149)
  Fix JS error when opening to expanded code comment (go-gitea#30463)
  fix: Fix to delete cookie when AppSubURL is non-empty (go-gitea#30375)
  Add `interface{}` to `any` replacement to `make fmt`, exclude `*.pb.go` (go-gitea#30461)
  Fix network error when open/close organization/individual projects and redirect to project page (go-gitea#30387)
  Avoid losing token when updating mirror settings (go-gitea#30429)
  Fix label rendering (go-gitea#30456)
  Add comment for ContainsRedirectURI about the exact match (go-gitea#30457)
  Update JS and PY deps, lock eslint and related plugins (go-gitea#30452)
  Refactor cache and disable go-chi cache (go-gitea#30417)
  Fix admin notice view-detail (go-gitea#30450)
  Fix mirror error when mirror repo is empty (go-gitea#30432)
  Add `/public/assets/img/webpack` to ignore files again (go-gitea#30451)
  Lock a few tool dependencies to major versions (go-gitea#30439)
  ...
silverwind added a commit to silverwind/gitea that referenced this pull request Apr 14, 2024
* origin/main:
  Improve flex ellipsis (go-gitea#30479)
  Remove fomantic button module (go-gitea#30475)
  Improve "must-change-password" logic and document (go-gitea#30472)
  Fix commitstatus summary (go-gitea#30431)
  Remove fomantic menu module (go-gitea#30325)
  Use `flex-container` for dashboard layout (go-gitea#30214)
  Rewrite and restyle reaction selector and enable no-sizzle eslint rule (go-gitea#30453)
  Pulse page improvements (go-gitea#30149)
  Fix JS error when opening to expanded code comment (go-gitea#30463)
  fix: Fix to delete cookie when AppSubURL is non-empty (go-gitea#30375)
  Add `interface{}` to `any` replacement to `make fmt`, exclude `*.pb.go` (go-gitea#30461)
  Fix network error when open/close organization/individual projects and redirect to project page (go-gitea#30387)
  Avoid losing token when updating mirror settings (go-gitea#30429)
zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 15, 2024
* giteaofficial/main:
  [skip ci] Updated licenses and gitignores
  Revert 100% label max-width (go-gitea#30481)
  Improve flex ellipsis (go-gitea#30479)
  Remove fomantic button module (go-gitea#30475)
  Improve "must-change-password" logic and document (go-gitea#30472)
  Fix commitstatus summary (go-gitea#30431)
  Remove fomantic menu module (go-gitea#30325)
  Use `flex-container` for dashboard layout (go-gitea#30214)
  Rewrite and restyle reaction selector and enable no-sizzle eslint rule (go-gitea#30453)
  Pulse page improvements (go-gitea#30149)
@wxiaoguang wxiaoguang added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Apr 27, 2024
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jul 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created backport/v1.22 This PR should be backported to Gitea 1.22 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code modifies/internal modifies/js modifies/templates This PR modifies the template files size/L Denotes a PR that changes 100-499 lines, ignoring generated files. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants