fix: adjust query's promise implementation to properly allow chaining (#14859)
authorSimon H <5968653+dummdidumm@users.noreply.github.com>
Thu, 30 Oct 2025 17:11:09 +0000 (18:11 +0100)
committerGitHub <noreply@github.com>
Thu, 30 Oct 2025 17:11:09 +0000 (18:11 +0100)
Fixes #14486

.changeset/fuzzy-insects-sneeze.md [new file with mode: 0644]
packages/kit/src/runtime/client/remote-functions/query.svelte.js

diff --git a/.changeset/fuzzy-insects-sneeze.md b/.changeset/fuzzy-insects-sneeze.md
new file mode 100644 (file)
index 0000000..293e0eb
--- /dev/null
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+fix: adjust query's promise implementation to properly allow chaining
index d8569a49249b132b593c0285ee57e6d102b6bf79..196a959d25a722b01294b45e0ed9b8ca9cea72f9 100644 (file)
@@ -163,15 +163,19 @@ export class Query {
                const p = this.#promise;
                this.#overrides.length;
 
-               return async (resolve, reject) => {
-                       try {
+               return (resolve, reject) => {
+                       const result = (async () => {
                                await p;
                                // svelte-ignore await_reactivity_loss
                                await tick();
-                               resolve?.(/** @type {T} */ (this.#current));
-                       } catch (error) {
-                               reject?.(error);
+                               return /** @type {T} */ (this.#current);
+                       })();
+
+                       if (resolve || reject) {
+                               return result.then(resolve, reject);
                        }
+
+                       return result;
                };
        });
 
@@ -251,8 +255,14 @@ export class Query {
                this.#then;
                return (/** @type {any} */ fn) => {
                        return this.#then(
-                               () => fn(),
-                               () => fn()
+                               (value) => {
+                                       fn();
+                                       return value;
+                               },
+                               (error) => {
+                                       fn();
+                                       throw error;
+                               }
                        );
                };
        }