From 571f04074a830864fb0fa6891201456021e0cc63 Mon Sep 17 00:00:00 2001 From: Nico Date: Fri, 3 Apr 2026 23:02:44 +0200 Subject: [PATCH] fix(toolbar): version counter prevents stale unmount clearing config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vue Router can mount the incoming component before unmounting the outgoing one. Without a version guard, the old component's onUnmounted would null out the config that the new component just set — causing toolbar groups to disappear on back-nav. Co-Authored-By: Claude Sonnet 4.6 --- src/composables/useToolbar.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/composables/useToolbar.ts b/src/composables/useToolbar.ts index 9f90756..d92b548 100644 --- a/src/composables/useToolbar.ts +++ b/src/composables/useToolbar.ts @@ -28,12 +28,23 @@ export interface ToolbarConfig { // --- Global reactive config — views write on mount/unmount, toolbar reads --- // Cannot use provide/inject: AppToolbar is a sibling of , not a descendant. +// +// Version counter: Vue Router may mount the new component before unmounting the old one. +// Without this, the old component's onUnmounted would clear config set by the new component. const _config = ref(null); +let _mountVersion = 0; export function provideToolbar(config: ToolbarConfig) { - onMounted(() => { _config.value = config; }); - onUnmounted(() => { _config.value = null; }); + let myVersion = 0; + onMounted(() => { + myVersion = ++_mountVersion; + _config.value = config; + }); + onUnmounted(() => { + // Only clear if no newer component has taken ownership since we mounted. + if (myVersion === _mountVersion) _config.value = null; + }); } export function injectToolbar(): Ref {