Skip to content

Commit 5d76111

Browse files
authored
fix: adjust query's promise implementation to properly allow chaining (#14859)
Fixes #14486
1 parent d9bbf66 commit 5d76111

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

.changeset/fuzzy-insects-sneeze.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: adjust query's promise implementation to properly allow chaining

packages/kit/src/runtime/client/remote-functions/query.svelte.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,19 @@ export class Query {
163163
const p = this.#promise;
164164
this.#overrides.length;
165165

166-
return async (resolve, reject) => {
167-
try {
166+
return (resolve, reject) => {
167+
const result = (async () => {
168168
await p;
169169
// svelte-ignore await_reactivity_loss
170170
await tick();
171-
resolve?.(/** @type {T} */ (this.#current));
172-
} catch (error) {
173-
reject?.(error);
171+
return /** @type {T} */ (this.#current);
172+
})();
173+
174+
if (resolve || reject) {
175+
return result.then(resolve, reject);
174176
}
177+
178+
return result;
175179
};
176180
});
177181

@@ -251,8 +255,14 @@ export class Query {
251255
this.#then;
252256
return (/** @type {any} */ fn) => {
253257
return this.#then(
254-
() => fn(),
255-
() => fn()
258+
(value) => {
259+
fn();
260+
return value;
261+
},
262+
(error) => {
263+
fn();
264+
throw error;
265+
}
256266
);
257267
};
258268
}

0 commit comments

Comments
 (0)