Skip to content

Fix actions fetching logic and loading state, prevent duplicate toasts #31124

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

Closed
wants to merge 14 commits into from

Conversation

silverwind
Copy link
Member

@silverwind silverwind commented May 27, 2024

  1. Fix the bug where action steps would not expand sometimes. This was because when a fetch was running and the user clicked "expand" it would not propagate the expansion request to the backend, leaving the UI state invalid. Fixed this by adding a force flag.
  2. When a fetch failed, it would just throw the error and the browser would dump it into the console, invisible to the user. Show a toast in such a case.
  3. Add a dedicated loading state to steps to ensure they can not get stuck in that state when cursor remains at null, for example when a fetch error happened.

Also, because in the actions view, fetches can fail repeatedly because of the refreshing, I saw the need to introduce a deduplication for toasts, so if an attempt is made to raise a toast with the same message and level, it will suppress opening them.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 27, 2024
@silverwind silverwind added the backport/v1.22 This PR should be backported to Gitea 1.22 label May 27, 2024
@lunny
Copy link
Member

lunny commented May 28, 2024

Could we split these as two PRs for easier review?

@silverwind
Copy link
Member Author

Can't easily split this because if I remove only the toast changes, there would be the problem of repeated error toasts every second because of that refresh mechanism. The only thing that could be done is to have a reduced backport that only fixes issue 1 with the force flag.

lunny
lunny previously approved these changes May 29, 2024
@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 May 29, 2024
@silverwind
Copy link
Member Author

BTW one reason we need the toast deduplication: Go to admin dashboard and disconnect your network:

image

@silverwind silverwind requested a review from wxiaoguang June 20, 2024 20:03
@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 Jun 23, 2024
@wxiaoguang wxiaoguang removed the backport/v1.22 This PR should be backported to Gitea 1.22 label Jun 23, 2024
Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

Missed this review request.

No block from my side (I don't use Actions and I haven't spent time on reading code), just share some opinions:

  1. the loadData state management becomes more and more complex and fragile, at first glance I can't tell whether it is complete but I guess there could be some edge cases, for example: force=true will reset other this.loading=true
  2. maybe there should be some tests to cover some functions (even without e2e test, we could mock and test some code blocks)
  3. the change of showToast is quite hacky
    • preventDuplicates should not default to true, it is a breaking behavior.
    • it should hide the existing toast, but not skip the new toast.
  4. it shouldn't be backported since the change is not covered by tests, and it doesn't fix blocker problems for end users.

@silverwind
Copy link
Member Author

silverwind commented Jun 25, 2024

maybe there should be some tests to cover some functions (even without e2e test, we could mock and test some code blocks)

Quite hard I assume unless Vue works in happy-dom, but I would doubt that. Maybe with some Vue-specific testing framework, but I have no experience with those.

preventDuplicates should not default to true, it is a breaking behavior.

It helps with other cases like systems stats flooding the page with error toasts when going offline.

it should hide the existing toast, but not skip the new toast.

This is actually a nice idea, I will try to implement.

it shouldn't be backported since the change is not covered by tests, and it doesn't fix blocker problems for end users.

It's quite annoying when you click an action step and nothing happens though. Happens to me like a third of the time.

@silverwind silverwind marked this pull request as draft June 25, 2024 00:30
@silverwind
Copy link
Member Author

Will also fix the boolean trap with loadData :)

@wxiaoguang
Copy link
Contributor

maybe there should be some tests to cover some functions (even without e2e test, we could mock and test some code blocks)

Quite hard I assume unless Vue works in happy-dom, but I would doubt that. Maybe with some Vue-specific testing framework, but I have no experience with those.

Maybe something like "Improve <SvgIcon> to make it output svg node and optimize performance (#23570)"

@silverwind
Copy link
Member Author

Right, this createApp + mount pattern I had a helper function in another PR, so likely tests could use it in place of this h function.

BTW, I think I will extract the toast changes to another PR. I have a few improvements in mind.

@silverwind
Copy link
Member Author

Ah, I see you went with the "default enabled" variant, so yes in this case we don't need to special-case these callers. I will remove all toast-related code from this commit.

@silverwind silverwind marked this pull request as draft June 26, 2024 13:58
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jun 26, 2024

OK, I am sure the state management is not right now. See the duplicate lines:

image

image

That's my first worry in #31124 (review)

@pull-request-size pull-request-size bot added size/M and removed size/L labels Jun 26, 2024
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jun 26, 2024

@silverwind you edited my comment ...... (reverted)

To answer:

Got some steps how to reproduce that?

I think the reason is still related to the "force" behavior: to produce, make the backend sleep 500-1500ms to respond to make the edge cases could easily be triggered, then toggle the steps multiple times, then since you use force to reset the loading, then there are multiple requests in flight, then they get duplicate results.

@silverwind
Copy link
Member Author

Sorry, meant to reply. I will rework this later.

@wxiaoguang wxiaoguang removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jun 26, 2024
@lunny lunny modified the milestones: 1.23.0, 1.24.0 Sep 7, 2024
@silverwind
Copy link
Member Author

FYI https://codeberg.org/forgejo/forgejo/pulls/6122 is related and deals with the same bug of the job step sometimes not expanding.

@wxiaoguang
Copy link
Contributor

FYI https://codeberg.org/forgejo/forgejo/pulls/6122 is related and deals with the same bug of the job step sometimes not expanding.

Just take a quick look, I do not think it is right, it seems to be a hacky patch.

@wxiaoguang
Copy link
Contributor

I will try to work on it in the following few days, to see whether we could properly fix it in 1.23

@wxiaoguang wxiaoguang modified the milestones: 1.24.0, 1.23.0 Dec 4, 2024
@wxiaoguang wxiaoguang self-assigned this Dec 4, 2024
@silverwind
Copy link
Member Author

silverwind commented Dec 4, 2024

I will try to work on it in the following few days, to see whether we could properly fix it in 1.23

Thanks, I haven't gotten around to this. I hope you can reproduce the issue. It happens when a job is expanded while the fetch is still running.

@wxiaoguang
Copy link
Contributor

Done, see this: Refactor RepoActionView.vue #32713

async loadJob() {
if (this.loading) return;
async loadData({force = false} = {}) {
if (this.loading && !force) return;
Copy link

Choose a reason for hiding this comment

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

In the event that a force request is received, I think that there will be a race condition that may cause a similar problem to the one that you're attempting to solve, occasionally:

There's loadData(A) which was already running, and then loadData(B) which was running with the force flag. If loadData(B) returns from the server first, and then loadData(A)'s data returns from the server afterwards, I believe the log data will be reverted back to the data from the first request.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, that's why I blocked this PR from merging #31124 (comment)

@lunny lunny dismissed their stale review December 5, 2024 00:38

replaced by #32713

@lunny
Copy link
Member

lunny commented Dec 6, 2024

Replaced by #32713 ?

@silverwind
Copy link
Member Author

Yes, that includes the most important fix. As for the other 2 topics, I think we can do them another time.

@silverwind silverwind closed this Dec 6, 2024
@silverwind silverwind deleted the afetch branch December 6, 2024 07:11
@GiteaBot GiteaBot removed this from the 1.23.0 milestone Dec 6, 2024
@wxiaoguang wxiaoguang removed their assignment Dec 6, 2024
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Mar 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/js type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants