Skip to content

Commit 214db6d

Browse files
authored
Fix Async Tasks data cache issue (#997)
* Fix Task data cache issue * address comments
1 parent 22f741b commit 214db6d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

frontend/src/static/js/components/webstatus-overview-page.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import {consume} from '@lit/context';
1818
import {Task, TaskStatus} from '@lit/task';
1919
import {LitElement, type TemplateResult, html} from 'lit';
20-
import {customElement, state} from 'lit/decorators.js';
20+
import {customElement, state, property} from 'lit/decorators.js';
2121
import {type components} from 'webstatus.dev-backend';
2222

2323
import {
@@ -55,9 +55,12 @@ export class OverviewPage extends LitElement {
5555
data: null,
5656
};
5757

58-
@state()
58+
@property({type: Object})
5959
location!: {search: string}; // Set by router.
6060

61+
@state()
62+
currentLocation?: {search: string};
63+
6164
constructor() {
6265
super();
6366

@@ -67,7 +70,17 @@ export class OverviewPage extends LitElement {
6770
task: async ([apiClient, routerLocation]): Promise<
6871
components['schemas']['FeaturePage']
6972
> => {
70-
return this._fetchFeatures(apiClient, routerLocation);
73+
if (this.location.search !== this.currentLocation?.search) {
74+
// Reset taskTracker here due to a Task data cache issue.
75+
this.taskTracker = {
76+
status: TaskStatus.INITIAL,
77+
error: null,
78+
data: null,
79+
};
80+
this.currentLocation = this.location;
81+
return this._fetchFeatures(apiClient, routerLocation);
82+
}
83+
return this.taskTracker.data ?? {metadata: {total: 0}, data: []};
7184
},
7285
onComplete: page => {
7386
this.taskTracker = {

0 commit comments

Comments
 (0)