From 3fc13ca111b3f23190e8f0489bb55bd3d7fb17af Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Fri, 22 May 2026 11:57:34 +0200 Subject: [PATCH] Fix: put a deadline on index drain during navigation In certain edge-case scenarios navigation may be blocked for a long time (many seconds or longer) as indexing happens. This doesn't make sense, so let's put a 2s deadline on that. --- client/content_manager.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/content_manager.ts b/client/content_manager.ts index ee960fa1..b7ef9aae 100644 --- a/client/content_manager.ts +++ b/client/content_manager.ts @@ -47,7 +47,7 @@ export class ContentManager { .catch((e) => console.error("Error dispatching editor:updated event", e)); }, 1000); - constructor(private client: Client) {} + constructor(private client: Client) { } // Save the current page or document save(immediate = false): Promise { @@ -182,9 +182,14 @@ export class ContentManager { // Wait for index to process the saved page so the next page renders // with up-to-date widget data. Skip during initial indexing though: // the queue may contain hundreds of files and blocking navigation on - // a full drain would make the app feel unresponsive. + // a full drain would make the app feel unresponsive. Cap the wait so + // a backed-up queue (e.g. just after sync) doesn't stall navigation + // for many seconds: fresh widget data is a nice-to-have. if (await this.client.objectIndex.hasFullIndexCompleted()) { - await this.client.objectIndex.awaitIndexQueueDrain(); + await Promise.race([ + this.client.objectIndex.awaitIndexQueueDrain(), + new Promise((resolve) => setTimeout(resolve, 2000)), + ]); } }