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

Don't show loading indicators when refreshing the system status #30712

Merged
merged 14 commits into from Apr 27, 2024

Conversation

yardenshoham
Copy link
Member

@yardenshoham yardenshoham commented Apr 26, 2024

When I added this the dividers didn't render the loading indicators but I guess some CSS has changed since then. Now we render the loading indicator on a hidden element so it won't appear.

Before

before

After

after

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 26, 2024
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 26, 2024
@github-actions github-actions bot added the modifies/templates This PR modifies the template files label Apr 26, 2024
When I added this the dividers didn't render the loading indicators but I guess some CSS has changed since then. Now we render the loading indicators on hidden elements so they don't appear.

Signed-off-by: Yarden Shoham <git@yardenshoham.com>
@silverwind
Copy link
Member

silverwind commented Apr 26, 2024

Hmm,

The hx-indicator attribute allows you to specify the element that will have the htmx-request class added to it for the duration of the request

What's the point of .tw-hidden.htmx-request? Why not just remove hx-indicator if we don't want a indicator?

@yardenshoham
Copy link
Member Author

We want the indicator for other htmx-based requests such as subscribe and watch

@silverwind
Copy link
Member

Yeah but can't we remove it from this one element?

@yardenshoham
Copy link
Member Author

I didn't see any other option

@silverwind
Copy link
Member

silverwind commented Apr 26, 2024

So the problem is htmx can not distinguish between initial and subsequent requests, e.g. you can't conditionally show hx-indicator?

@@ -76,7 +76,7 @@
{{ctx.Locale.Tr "admin.dashboard.system_status"}}
</h4>
{{/* TODO: make these stats work in multi-server deployments, likely needs per-server stats in DB */}}
<div hx-get="{{$.Link}}/system_status" hx-swap="morph:innerHTML" hx-trigger="every 5s" hx-indicator=".divider" class="ui attached table segment">
<div hx-get="{{$.Link}}/system_status" hx-swap="morph:innerHTML" hx-trigger="every 5s" hx-indicator=".tw-hidden" class="ui attached table segment">

This comment was marked as outdated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it could also use something like hx-indicator="no-indicator" , because no-indicator also matches nothing.

Or even as simple as hx-indicator="no", we would never use <no> tag in HTML code, so it also matches nothing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that prints an error in the console on every request

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, then tw-hidden also doesn't seem good enough because tw-hidden might also not exist.

Ideally it could be like this:

Suggested change
<div hx-get="{{$.Link}}/system_status" hx-swap="morph:innerHTML" hx-trigger="every 5s" hx-indicator=".tw-hidden" class="ui attached table segment">
<div hx-get="{{$.Link}}/system_status" hx-swap="morph:innerHTML" hx-trigger="every 5s" hx-indicator=".hidden-loading-indicator" class="ui attached table segment">

Then put <div class="hidden-loading-indicator tw-hidden"></div> into "admin/system_status"

Then everything is clear and I think it reads better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And more details, .tw-hidden can't be right. It just adds the indicator to all the tw-hidden elements on this page, which causes various side effects

Think about a case:

<div class="panel tw-hidden"></div>
<div hx-get hx-indicator=".tw-hidden"></div>

The "panel" is not related to the hx-get.

When the loading-indicator is added to the "panel", and the request is still running, then the user shows the panel: surprise: they sees a "loading panel".

yardenshoham and others added 2 commits April 26, 2024 20:41
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@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 26, 2024
yardenshoham and others added 2 commits April 26, 2024 22:37
Co-authored-by: silverwind <me@silverwind.io>
Copy link
Member

@silverwind silverwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a hack, but I guess a barely acceptable one. Would prefer a solution in htmx to suppress indicator on specific elements.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 26, 2024
@wxiaoguang wxiaoguang enabled auto-merge (squash) April 27, 2024 11:20
@wxiaoguang wxiaoguang added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 27, 2024
@wxiaoguang wxiaoguang added skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/bug labels Apr 27, 2024
@wxiaoguang
Copy link
Contributor

Why revert? Here we can clearly see htmx is using querySelectorAll:

You forgot to change the related code.

@silverwind
Copy link
Member

silverwind commented Apr 27, 2024

Oh, I see, we should remove this useless element.

@silverwind silverwind removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 27, 2024
@silverwind silverwind self-requested a review April 27, 2024 12:00
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Apr 27, 2024
@silverwind
Copy link
Member

Will test it and then remove it.

@wxiaoguang
Copy link
Contributor

Oh, I seem we should remove this.

I do not see any reason to block merging this change.

@silverwind
Copy link
Member

Fixed and tested.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 27, 2024
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Apr 27, 2024

Fixed and tested.

NOOOOOOOOOOOOOOOO! See the discussion above.

#30712 (comment)

@silverwind
Copy link
Member

silverwind commented Apr 27, 2024

Hmm it does seem htmx falls back to the element if nothing matches:

https://github.com/bigskysoftware/htmx/blob/b176784f31a7bc4b55e40cec368dff571c4fb991/src/htmx.js#L2456-L2459

So your fix is better.

@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 27, 2024
@wxiaoguang
Copy link
Contributor

Hmm it does seem htmx falls back to the element if nothing matches:

It doens't fallback, it only returns an empty array. But there will be a lot of error messages in user's console, it would confuse users and developers. The root problem is that htmx insists to find something to show the indicator. If htmx could change its behavior to avoiding showing the indicator, life will be easier.

@silverwind
Copy link
Member

silverwind commented Apr 27, 2024

Anyways, I have to add a remark that I'm starting to despise htmx. It's clearly not a well thought-out framework.

@silverwind
Copy link
Member

It doens't fallback, it only returns an empty array. But there will be a lot of error messages in user's console, it would confuse users and developers

Right, querySelectorAll returns empty NodeList, never returns null.

@silverwind
Copy link
Member

Upstream issue: bigskysoftware/htmx#2515

@wxiaoguang wxiaoguang merged commit 51c28d9 into go-gitea:main Apr 27, 2024
26 checks passed
@wxiaoguang wxiaoguang deleted the fix-htmx-hidden branch April 27, 2024 13:05
@GiteaBot GiteaBot added this to the 1.23.0 milestone Apr 27, 2024
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 27, 2024
zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 27, 2024
* giteaofficial/main:
  Make Ctrl+Enter work for issue/comment edit (go-gitea#30720)
  Rename migration package name for 1.22-rc1 (go-gitea#30730)
  Issue card improvements (go-gitea#30687)
  Don't show loading indicators when refreshing the system status (go-gitea#30712)
  Add some tests to clarify the "must-change-password" behavior (go-gitea#30693)
  Prevent allow/reject reviews on merged/closed PRs (go-gitea#30686)
  Update JS dependencies (go-gitea#30713)
  Improve diff stats bar (go-gitea#30669)
  Remove unused parameter for some functions in `services/mirror` (go-gitea#30724)
  Update misspell to 0.5.1 and add `misspellings.csv` (go-gitea#30573)
  Suppress browserslist warning in webpack target (go-gitea#30571)
  [skip ci] Updated translations via Crowdin
  Diff color enhancements, add line number background (go-gitea#30670)
@wxiaoguang wxiaoguang modified the milestones: 1.23.0, 1.22.0 Apr 27, 2024
silverwind added a commit to silverwind/gitea that referenced this pull request Apr 27, 2024
* origin/main:
  Replace deprecated `math/rand` functions (go-gitea#30733)
  Make Ctrl+Enter work for issue/comment edit (go-gitea#30720)
  Rename migration package name for 1.22-rc1 (go-gitea#30730)
  Issue card improvements (go-gitea#30687)
  Don't show loading indicators when refreshing the system status (go-gitea#30712)
  Add some tests to clarify the "must-change-password" behavior (go-gitea#30693)
  Prevent allow/reject reviews on merged/closed PRs (go-gitea#30686)
  Update JS dependencies (go-gitea#30713)
  Improve diff stats bar (go-gitea#30669)
  Remove unused parameter for some functions in `services/mirror` (go-gitea#30724)
  Update misspell to 0.5.1 and add `misspellings.csv` (go-gitea#30573)
  Suppress browserslist warning in webpack target (go-gitea#30571)
  [skip ci] Updated translations via Crowdin
  Diff color enhancements, add line number background (go-gitea#30670)
  feat(api): enhance Actions Secrets Management API for repository (go-gitea#30656)
  Fix code search input for different views (go-gitea#30678)
  Fix incorrect object id hash function (go-gitea#30708)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/templates This PR modifies the template files size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants