gitea icon indicating copy to clipboard operation
gitea copied to clipboard

Reviewing a lot of files resets the counter when loading more

Open kolaente opened this issue 1 year ago • 2 comments

Description

Steps to reproduce:

  1. Create a repo
  2. Create a PR with a lot of changed files (in my case 193)
  3. Start reviewing the PR, marking each reviewed file as "viewed" with the checkbox
  4. Once the first 100 files are marked as viewed, click the "load more" button at the end of the page to load the rest of the files
  5. Mark the 101st file as viewed

Expected behavior:

101 files are marked as viewed

Actual behavior:

99 files are marked as viewed

The very first file is un-marked as viewed when marking the 101st file as viewed. When I mark it as viewed again, 100 files are marked as viewed again. When I then try to mark another of the newly loaded files as viewed, it unmarks the first file again, resulting in 99 files are marked as viewed.

Gitea Version

1.17.0

Can you reproduce the bug on the Gitea demo site?

Probably (on the go right now, will try to reproduce it later)

How are you running Gitea?

Official docker image.

Database

MySQL

kolaente avatar Aug 05 '22 06:08 kolaente

Hmm. I have absolutely no idea what could cause this. I'm fairly certain I've tested the behavior on #19007, and there it worked correctly. To be fair, I only tested by marking some and not all files as viewed before loading more files dynamically, but still? I don't see anything in the code (I wrote) (web_src/js/features/pull-view-file.js) that would cause this, unless this.checked (where this is a checkbox) was inverted by default for some reason?

delvh avatar Aug 05 '22 09:08 delvh

Yep, just confirmed it on try.gitea.io (https://try.gitea.io/delvh/kanban-test/pulls/25/files). I had even stranger behavior: For me, the counter was reset to 0 (when loading more files), meaning that when I clicked on the 101st checkbox, the 1st checkbox was acted upon, and as that was already selected, it was de-selected, thus bringing the counter down to -1.

So, to me, the first issue appears to be an index issue where if x files are loaded initially, all subsequent ones use index - x (or index % x?) for the viewed checkbox JS. However, I still have no idea why this could be the case, and why I didn't notice it originally. The second issue is that the counter was reset to 0, which it shouldn't.

delvh avatar Aug 05 '22 17:08 delvh