@@ -72,38 +72,6 @@ export interface SessionSceneNavigation {
7272let sessionNavigation : SessionSceneNavigation | undefined ;
7373let navigationRequest = 0 ;
7474
75- export function registerSessionSceneNavigation ( adapter : SessionSceneNavigation ) : ( ) => void {
76- sessionNavigation = adapter ;
77- return ( ) => {
78- if ( sessionNavigation === adapter ) {
79- sessionNavigation = undefined ;
80- navigationRequest ++ ;
81- if ( useSceneStore . getState ( ) . pendingTabId !== null ) useSceneStore . setState ( { pendingTabId : null } ) ;
82- }
83- } ;
84- }
85-
86- /** Every navigation path, including history and close fallback, uses this gate. */
87- function navigateToScene ( id : SceneTabId | null , commit : ( ) => void , session ?: SessionSceneTarget ) : void {
88- const hadPendingNavigation = useSceneStore . getState ( ) . pendingTabId !== null ;
89- const request = ++ navigationRequest ;
90- const adapter = sessionNavigation ;
91- const target = session ?? useSceneStore . getState ( ) . openTabs . find ( tab => tab . id === id ) ?. session ;
92- const isCurrent = ( ) => request === navigationRequest && adapter === sessionNavigation ;
93- if ( ! target || ! adapter || ( ! hadPendingNavigation && adapter . isActive ( target ) ) ) {
94- if ( useSceneStore . getState ( ) . pendingTabId !== null ) useSceneStore . setState ( { pendingTabId : null } ) ;
95- commit ( ) ;
96- return ;
97- }
98-
99- useSceneStore . setState ( { pendingTabId : id } ) ;
100- void adapter . activate ( target , isCurrent ) . then ( activated => {
101- if ( activated && isCurrent ( ) ) commit ( ) ;
102- } ) . finally ( ( ) => {
103- if ( isCurrent ( ) ) useSceneStore . setState ( { pendingTabId : null } ) ;
104- } ) ;
105- }
106-
10775function resolveNavSceneId ( sceneId : SceneTabId | null ) : SceneTabId | null {
10876 if ( sceneId === null ) return null ;
10977 return getSceneNav ( sceneId ) ? sceneId : null ;
@@ -314,6 +282,38 @@ export const useSceneStore = create<SceneState>((set, get) => ({
314282 } ,
315283} ) ) ;
316284
285+ export function registerSessionSceneNavigation ( adapter : SessionSceneNavigation ) : ( ) => void {
286+ sessionNavigation = adapter ;
287+ return ( ) => {
288+ if ( sessionNavigation === adapter ) {
289+ sessionNavigation = undefined ;
290+ navigationRequest ++ ;
291+ if ( useSceneStore . getState ( ) . pendingTabId !== null ) useSceneStore . setState ( { pendingTabId : null } ) ;
292+ }
293+ } ;
294+ }
295+
296+ /** Every navigation path, including history and close fallback, uses this gate. */
297+ function navigateToScene ( id : SceneTabId | null , commit : ( ) => void , session ?: SessionSceneTarget ) : void {
298+ const hadPendingNavigation = useSceneStore . getState ( ) . pendingTabId !== null ;
299+ const request = ++ navigationRequest ;
300+ const adapter = sessionNavigation ;
301+ const target = session ?? useSceneStore . getState ( ) . openTabs . find ( tab => tab . id === id ) ?. session ;
302+ const isCurrent = ( ) => request === navigationRequest && adapter === sessionNavigation ;
303+ if ( ! target || ! adapter || ( ! hadPendingNavigation && adapter . isActive ( target ) ) ) {
304+ if ( useSceneStore . getState ( ) . pendingTabId !== null ) useSceneStore . setState ( { pendingTabId : null } ) ;
305+ commit ( ) ;
306+ return ;
307+ }
308+
309+ useSceneStore . setState ( { pendingTabId : id } ) ;
310+ void adapter . activate ( target , isCurrent ) . then ( activated => {
311+ if ( activated && isCurrent ( ) ) commit ( ) ;
312+ } ) . finally ( ( ) => {
313+ if ( isCurrent ( ) ) useSceneStore . setState ( { pendingTabId : null } ) ;
314+ } ) ;
315+ }
316+
317317function openSceneTarget ( id : SceneTabId , session ?: SessionSceneTarget ) : void {
318318 const get = useSceneStore . getState ;
319319 const set = useSceneStore . setState ;
0 commit comments