From cf3b782cecbca77305728bff241efd7e083c06ba Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 24 Oct 2023 12:48:56 -0700 Subject: [PATCH] fragment: fix wait time Signed-off-by: Varun Patil --- src/services/utils/fragment.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/services/utils/fragment.ts b/src/services/utils/fragment.ts index 33a7c766..c918e430 100644 --- a/src/services/utils/fragment.ts +++ b/src/services/utils/fragment.ts @@ -127,6 +127,9 @@ export const fragment = { query: _m.route.query, hash: encodeFragment(list), }); + + // wait for the route to change + await new Promise((resolve) => setTimeout(resolve, 0)); }, /** @@ -151,6 +154,9 @@ export const fragment = { hash: encodeFragment(this.list.slice(0, -sfrag.index! - 1)), }); } + + // wait for the route to change + await new Promise((resolve) => setTimeout(resolve, 0)); }, /** @@ -163,13 +169,18 @@ export const fragment = { /** * Wrap a promise as a route fragment. + * Pushes a fragment before running the promise and + * pops it *before* the promise resolves. */ async wrap(promise: Promise, type: FragmentType, ...args: string[]): Promise { await this.push(type, ...args); try { - return await promise; - } finally { + const res = await promise; await this.pop(type); + return res; + } catch (e) { + await this.pop(type); + throw e; } },