From b648fe445367fb4fcc369db17504e42b39b7dbef Mon Sep 17 00:00:00 2001 From: Partouf Date: Sat, 6 Jun 2026 00:18:44 +0200 Subject: [PATCH] fix: apply shortlink libraries before compiling after lazy-load The lazy-load change (#8549) made the LibsWidget fetch its available library list from the API, so applying the saved state (selecting the libraries from a shortlink) became asynchronous. The compiler/executor panes called initLibraries without awaiting it and then immediately compiled and persisted state, so the saved libraries were not yet selected (e.g. /z/jMdjdahn6 loaded without beman_any_view selected). Expose a stateLoaded promise on LibsWidget that resolves once loadState has run, await it in initLibraries, and await initLibraries in postInit. Also refresh the libraries button after loadState so its count is correct. Co-Authored-By: Claude Opus 4.8 (1M context) --- static/panes/compiler.ts | 4 +++- static/panes/executor.ts | 4 +++- static/widgets/libs-widget.ts | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/static/panes/compiler.ts b/static/panes/compiler.ts index 6ed08a8f1..00d15bdb1 100644 --- a/static/panes/compiler.ts +++ b/static/panes/compiler.ts @@ -363,7 +363,7 @@ export class Compiler extends MonacoPane { diff --git a/static/panes/executor.ts b/static/panes/executor.ts index 9208f0152..fdc8d969a 100644 --- a/static/panes/executor.ts +++ b/static/panes/executor.ts @@ -186,7 +186,7 @@ export class Executor extends Pane { this.compilerIsVisible, ); - this.initLibraries(state); + await this.initLibraries(state); this.updateCompilerInfo(); this.updateState(); @@ -906,6 +906,8 @@ export class Executor extends Pane { this.compiler?.remote ?? undefined, ), ); + // Wait for the lazily-loaded libraries to be selected before compiling or persisting state. + await this.libsWidget.stateLoaded; } onFontScale(): void { diff --git a/static/widgets/libs-widget.ts b/static/widgets/libs-widget.ts index dcbbb4ebe..4ac24aac8 100644 --- a/static/widgets/libs-widget.ts +++ b/static/widgets/libs-widget.ts @@ -139,6 +139,9 @@ export class LibsWidget { private readonly onChangeCallback: () => void; + // Resolves once the saved state has been applied to the lazily-loaded library list. + public readonly stateLoaded: Promise; + private readonly availableLibs: AvailableLibs; private readonly filters: PopupAlertFilter[] = [ (compilerId, langId) => { @@ -176,9 +179,10 @@ export class LibsWidget { this.initButtons(); this.onChangeCallback = onChangeCallback; this.availableLibs = {}; - this.updateAvailableLibs(possibleLibs, true).then(() => { + this.stateLoaded = this.updateAvailableLibs(possibleLibs, true).then(() => { this.loadState(state); this.fullRefresh(); + this.updateButton(); }); const searchInput = this.domRoot.find('.lib-search-input');