Skip to content

Commit

Permalink
Fix Async Tasks data cache issue (#997)
Browse files Browse the repository at this point in the history
* Fix Task data cache issue

* address comments
  • Loading branch information
KyleJu authored Dec 19, 2024
1 parent 22f741b commit 214db6d
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions frontend/src/static/js/components/webstatus-overview-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {consume} from '@lit/context';
import {Task, TaskStatus} from '@lit/task';
import {LitElement, type TemplateResult, html} from 'lit';
import {customElement, state} from 'lit/decorators.js';
import {customElement, state, property} from 'lit/decorators.js';
import {type components} from 'webstatus.dev-backend';

import {
Expand Down Expand Up @@ -55,9 +55,12 @@ export class OverviewPage extends LitElement {
data: null,
};

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

@state()
currentLocation?: {search: string};

constructor() {
super();

Expand All @@ -67,7 +70,17 @@ export class OverviewPage extends LitElement {
task: async ([apiClient, routerLocation]): Promise<
components['schemas']['FeaturePage']
> => {
return this._fetchFeatures(apiClient, routerLocation);
if (this.location.search !== this.currentLocation?.search) {
// Reset taskTracker here due to a Task data cache issue.
this.taskTracker = {
status: TaskStatus.INITIAL,
error: null,
data: null,
};
this.currentLocation = this.location;
return this._fetchFeatures(apiClient, routerLocation);
}
return this.taskTracker.data ?? {metadata: {total: 0}, data: []};
},
onComplete: page => {
this.taskTracker = {
Expand Down

0 comments on commit 214db6d

Please sign in to comment.