Skip to content

Commit 3fd0925

Browse files
committed
fix: adjust query's promise implementation to properly allow chaining
Fixes #14486
1 parent d37f9df commit 3fd0925

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
@@ -162,15 +162,19 @@ export class Query {
162162
const p = this.#promise;
163163
this.#overrides.length;
164164

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

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

0 commit comments

Comments
 (0)