Skip to content

Commit

Permalink
Wrap local results in Promise for query methods (#29161)
Browse files Browse the repository at this point in the history
These methods return promises. When we had the result already, either from another query request by the client or from an optimistic update, we were returning the raw value without wrapping it in a promise.

GitOrigin-RevId: 956a13525ddc1ef4c46467da12e320c2e8f03203
  • Loading branch information
sshader authored and Convex, Inc. committed Aug 26, 2024
1 parent e014ffb commit 58a90d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions npm-packages/convex/src/browser/simple_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ export class ConvexClient {
): Promise<Awaited<Query["_returnType"]>> {
if (this.disabled) throw new Error("ConvexClient is disabled");
const value = this.client.localQueryResult(getFunctionName(query), args) as
| Query["_returnType"]
| Awaited<Query["_returnType"]>
| undefined;
if (value !== undefined) return value;
if (value !== undefined) return Promise.resolve(value);

return new Promise((resolve, reject) => {
const { unsubscribe } = this.onUpdate(
Expand Down
2 changes: 1 addition & 1 deletion npm-packages/convex/src/react/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export class ConvexReactClient {
const watch = this.watchQuery(query, ...args);
const existingResult = watch.localQueryResult();
if (existingResult !== undefined) {
return existingResult;
return Promise.resolve(existingResult);
}
return new Promise((resolve, reject) => {
const unsubscribe = watch.onUpdate(() => {
Expand Down

0 comments on commit 58a90d4

Please sign in to comment.