Skip to content

Commit

Permalink
[24.0] Fix hasOwner function for histories in client
Browse files Browse the repository at this point in the history
The `hasOwner` function in `api/index.ts` was checking:
```
return "user_id" in history;
```

whereas, it also needed to check:
```
return "user_id" in history && history.user_id !== null;
```

because we assume histories (summaries) initally fetched for the `historyStore` without user_id are owned by the current user, but the key is still present in the backend return.

This was causing a really troublesome bug in the `HistoryScrollList` found in the history selector modal, where we could constantly keep fetching `api/histories/count` since we didn't have the expected no. of histories loaded in the component; because `historiesProxy` (which only contains owned histories) would end up being empty.
  • Loading branch information
ahmedhamidawan committed Apr 2, 2024
1 parent e331ccb commit 09f77f4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion client/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,5 @@ export function userOwnsHistory(user: User | AnonymousUser | null, history: AnyH
}

function hasOwner(history: AnyHistory): history is HistorySummaryExtended {
return "user_id" in history;
return "user_id" in history && history.user_id !== null;
}

0 comments on commit 09f77f4

Please sign in to comment.