Skip to content

Commit 9eedd0e

Browse files
author
dudina-ma
committed
[tasks] fix task pagination race in project view
1 parent 999da96 commit 9eedd0e

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

frontend/src/lib/pages/project-tasks.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
let sort = $state("-created_at");
2727
let offset = $state(0);
2828
const limit = 50;
29+
let requestVersion = 0;
2930
3031
let filterStatuses = $state<string[]>([...ACTIVE_STATUSES]);
3132
let filterPriorities = $state<string[]>([]);
@@ -58,6 +59,7 @@
5859
5960
function load() {
6061
if (!slug) return;
62+
const version = ++requestVersion;
6163
loading = true;
6264
error = "";
6365
@@ -69,15 +71,18 @@
6971
7072
Promise.all([getProject(slug), listTasks(filters)])
7173
.then(([proj, res]) => {
74+
if (version !== requestVersion) return;
7275
project = proj;
7376
tasks = res.items;
7477
total = res.total;
7578
touchProject({ id: proj.id, name: proj.name });
7679
})
7780
.catch((e) => {
81+
if (version !== requestVersion) return;
7882
error = e.message || "Failed to load data";
7983
})
8084
.finally(() => {
85+
if (version !== requestVersion) return;
8186
loading = false;
8287
});
8388
}
@@ -138,7 +143,6 @@
138143
disabled={offset === 0}
139144
onclick={() => {
140145
offset = Math.max(0, offset - limit);
141-
load();
142146
}}
143147
>
144148
Previous
@@ -154,7 +158,6 @@
154158
disabled={offset + limit >= total}
155159
onclick={() => {
156160
offset = offset + limit;
157-
load();
158161
}}
159162
>
160163
Next

0 commit comments

Comments
 (0)