From 99ef367ddcdf842d01683bf28ce5dedaa62b83d2 Mon Sep 17 00:00:00 2001 From: Osvaldo Ortega Date: Sun, 26 Apr 2026 17:19:49 -0700 Subject: [PATCH] sessions: ensure account/update widgets render with icons after IntersectionObserver fires actionViewItemService.register() does not fire onDidChange when a factory is it only fires when the optional `event` argument fires.registered This caused a race: if the toolbar's IntersectionObserver fired its first visible callback (and called _updateToolbar()) before AccountWidgetContribution registered its view item factories, the toolbar rendered text-label fallbacks and was never notified to re-render with the custom widgets. Fix by passing a shared Emitter to both register() calls and firing it once after both factories are in place. This triggers IActionViewItemService.onDidChange for Menus.TitleBarRightLayout regardless of ordering, so the toolbar always re-renders with TitleBarAccountWidget / TitleBarUpdateWidget. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../accountMenu/browser/account.contribution.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/vs/sessions/contrib/accountMenu/browser/account.contribution.ts b/src/vs/sessions/contrib/accountMenu/browser/account.contribution.ts index 293ec68110f07..a6b6aaee53bf9 100644 --- a/src/vs/sessions/contrib/accountMenu/browser/account.contribution.ts +++ b/src/vs/sessions/contrib/accountMenu/browser/account.contribution.ts @@ -757,16 +757,9 @@ class TitleBarUpdateWidget extends BaseActionViewItem { // --- Register custom view item --- // -// These actions are registered at module level (not lazily inside AccountWidgetContribution) -// so that Menus.TitleBarRightLayout is non-empty when the MenuWorkbenchToolBar is first -// constructed. If they were registered lazily (WorkbenchPhase.AfterRestored), the toolbar's -// IntersectionObserver would have already observed an empty, display:none container and -// stopped listening for menu changes — causing the widgets to never appear. -// -// The actual widget rendering and interaction is handled by TitleBarUpdateWidget / -// TitleBarAccountWidget, which are custom view items registered via IActionViewItemService -// in AccountWidgetContribution. Those widgets attach their own DOM click handlers, so -// run() here is intentionally a no-op. +// Actions registered at module level so Menus.TitleBarRightLayout is non-empty when the +// toolbar is first constructed. The run() is a no-op — rendering is handled by the custom +// view items registered in AccountWidgetContribution. registerAction2(class extends Action2 { constructor() { super({ @@ -811,16 +804,14 @@ class AccountWidgetContribution extends Disposable implements IWorkbenchContribu ) { super(); - // Titlebar update widget (to the right of separator, left of account badge) this._register(actionViewItemService.register(Menus.TitleBarRightLayout, SessionsTitleBarUpdateWidgetAction, (action, options) => { return instantiationService.createInstance(TitleBarUpdateWidget, action, options); }, undefined)); - // Titlebar account widget (rightmost in titlebar) this._register(actionViewItemService.register(Menus.TitleBarRightLayout, SessionsTitleBarAccountWidgetAction, (action, options) => { return instantiationService.createInstance(TitleBarAccountWidget, action, options); }, undefined)); } } -registerWorkbenchContribution2(AccountWidgetContribution.ID, AccountWidgetContribution, WorkbenchPhase.AfterRestored); +registerWorkbenchContribution2(AccountWidgetContribution.ID, AccountWidgetContribution, WorkbenchPhase.BlockRestore);