@@ -7,7 +7,7 @@ import { createProviderLogo, providerName } from './providerLogo';
77export interface ProviderOpenControlOptions {
88 path : string ;
99 historyAgentIds : readonly AgentId [ ] ;
10- liveAgentIds : readonly AgentId [ ] ;
10+ liveAgentIds ( ) : readonly AgentId [ ] ;
1111 compact ?: boolean ;
1212 onOpen ( intent : ProjectOpenIntent ) : void ;
1313}
@@ -18,6 +18,15 @@ const outcomeKey: Record<ProviderOpenOutcome, string> = {
1818 new : 'open.status_new' ,
1919} ;
2020
21+ // One shared selection subscription updates only controls that are still in the document. Keeping
22+ // renderers in a WeakMap avoids retaining every control ever replaced by a view re-render.
23+ const primaryRenderers = new WeakMap < HTMLElement , ( ) => void > ( ) ;
24+ subscribeAgentSelection ( ( ) => {
25+ for ( const root of Array . from ( document . querySelectorAll < HTMLElement > ( '.provider-open' ) ) ) {
26+ primaryRenderers . get ( root ) ?.( ) ;
27+ }
28+ } ) ;
29+
2130/** One provider-aware Open control shared by project cards, project rows, and task rows. */
2231export function createProviderOpenControl ( opts : ProviderOpenControlOptions ) : HTMLElement {
2332 const root = document . createElement ( 'span' ) ;
@@ -86,7 +95,7 @@ export function createProviderOpenControl(opts: ProviderOpenControlOptions): HTM
8695
8796 const renderMenu = ( ) : void => {
8897 menu . replaceChildren ( ) ;
89- for ( const option of providerOpenOptions ( installedAgents ( ) , selectedAgent ( ) , opts . historyAgentIds , opts . liveAgentIds ) ) {
98+ for ( const option of providerOpenOptions ( installedAgents ( ) , selectedAgent ( ) , opts . historyAgentIds , opts . liveAgentIds ( ) ) ) {
9099 const row = document . createElement ( 'div' ) ; row . className = 'provider-open-row' ; row . setAttribute ( 'role' , 'none' ) ;
91100 const automatic = document . createElement ( 'button' ) ;
92101 automatic . type = 'button' ; automatic . className = 'provider-open-option' ; automatic . setAttribute ( 'role' , 'menuitem' ) ;
@@ -145,8 +154,7 @@ export function createProviderOpenControl(opts: ProviderOpenControlOptions): HTM
145154 menu . addEventListener ( 'keydown' , onMenuKey ) ;
146155
147156 renderPrimary ( ) ;
148- const unsubscribe = subscribeAgentSelection ( ( ) => {
149- if ( ! root . isConnected ) { unsubscribe ( ) ; return ; }
157+ primaryRenderers . set ( root , ( ) => {
150158 renderPrimary ( ) ;
151159 if ( open ) renderMenu ( ) ;
152160 } ) ;
0 commit comments