@@ -647,6 +647,22 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
647647 if ( Option . isSome ( next ) ) yield * emit ( tabId , next . value ) ;
648648 } ) ;
649649
650+ /**
651+ * Pushes a tab's zoom factor onto whichever guest it currently owns, reading
652+ * both at call time. Anything that applies zoom after an await goes through
653+ * here: a snapshot taken before the await can be older than a zoom action that
654+ * landed in between, and re-applying it would roll that action back.
655+ */
656+ const assertTabZoom = Effect . fn ( "PreviewManager.assertTabZoom" ) ( function * ( tabId : string ) {
657+ const tab = ( yield * SynchronizedRef . get ( tabsRef ) ) . get ( tabId ) ;
658+ if ( ! tab || tab . webContentsId == null ) return ;
659+ const wc = webContents . fromId ( tab . webContentsId ) ;
660+ if ( ! wc || wc . isDestroyed ( ) ) return ;
661+ yield * attempt ( { operation : "assertTabZoom" , tabId, webContentsId : wc . id } , ( ) =>
662+ wc . setZoomFactor ( tab . zoomFactor ) ,
663+ ) . pipe ( Effect . ignore ) ;
664+ } ) ;
665+
650666 const requireWebContents = Effect . fn ( "PreviewManager.requireWebContents" ) ( function * (
651667 tabId : string ,
652668 ) {
@@ -1714,10 +1730,10 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
17141730 const annotationTheme = yield * Ref . get ( annotationThemeRef ) ;
17151731 const currentAttachment = attached . get ( webContentsId ) ;
17161732 if ( tab . webContentsId === webContentsId && currentAttachment ?. webContents === wc ) {
1717- yield * attempt ( { operation : "registerWebview.restoreZoomFactor" , tabId , webContentsId } , ( ) =>
1718- wc . setZoomFactor ( tab . zoomFactor ) ,
1719- ) ;
1720- yield * update ( tabId , { zoomFactor : tab . zoomFactor } ) ;
1733+ // The guest we already own re-announced itself, so nothing about the tab
1734+ // changed. Only push its zoom back down — Chromium may have just handed
1735+ // this guest the app window's zoom level.
1736+ yield * assertTabZoom ( tabId ) ;
17211737 yield * attempt ( { operation : "registerWebview.sendTheme" , tabId, webContentsId } , ( ) =>
17221738 wc . send ( ANNOTATION_THEME_CHANNEL , annotationTheme ) ,
17231739 ) ;
@@ -1748,13 +1764,10 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
17481764 }
17491765 // Always assert the tab's own zoom rather than reading the guest's: a guest
17501766 // attaching while the app UI is zoomed starts at the embedder's inherited
1751- // zoom level, which is not the preview's zoom.
1752- const zoomFactor = yield * attempt (
1753- { operation : "registerWebview.restoreZoomFactor" , tabId, webContentsId } ,
1754- ( ) => {
1755- wc . setZoomFactor ( currentTab . zoomFactor ) ;
1756- return currentTab . zoomFactor ;
1757- } ,
1767+ // zoom level, which is not the preview's zoom. Done before the guest is
1768+ // published so it never paints a frame at the inherited zoom.
1769+ yield * attempt ( { operation : "registerWebview.restoreZoomFactor" , tabId, webContentsId } , ( ) =>
1770+ wc . setZoomFactor ( currentTab . zoomFactor ) ,
17581771 ) ;
17591772 yield * attachListeners ( tabId , wc ) ;
17601773 const registeredAt = yield * currentIso ;
@@ -1779,7 +1792,6 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
17791792 navStatus : pendingUrl === null ? computeNavStatus ( wc ) : current . navStatus ,
17801793 canGoBack : wc . navigationHistory . canGoBack ( ) ,
17811794 canGoForward : wc . navigationHistory . canGoForward ( ) ,
1782- zoomFactor,
17831795 updatedAt : registeredAt ,
17841796 } ;
17851797 return [
@@ -1801,6 +1813,9 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
18011813 return yield * new PreviewTabNotFoundError ( { tabId } ) ;
18021814 }
18031815 const { state : registered , pendingUrl } = registration . value ;
1816+ // A zoom action that landed while this attach was in flight addressed the
1817+ // guest this one replaced, so settle the new guest on the committed factor.
1818+ yield * assertTabZoom ( tabId ) ;
18041819 runFork ( restoreControlSession ( tabId , wc ) ) ;
18051820 yield * emit ( tabId , registered ) ;
18061821 yield * attempt ( { operation : "registerWebview.sendTheme" , tabId, webContentsId } , ( ) =>
@@ -2101,19 +2116,8 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
21012116 * window's zoom changes (see DesktopWindow.zoomMain).
21022117 */
21032118 const reapplyZoom = Effect . fn ( "PreviewManager.reapplyZoom" ) ( function * ( ) {
2104- const tabs = yield * SynchronizedRef . get ( tabsRef ) ;
2105- yield * Effect . forEach (
2106- tabs . values ( ) ,
2107- ( tab ) => {
2108- if ( tab . webContentsId === null ) return Effect . void ;
2109- const wc = webContents . fromId ( tab . webContentsId ) ;
2110- if ( ! wc || wc . isDestroyed ( ) ) return Effect . void ;
2111- return attempt ( { operation : "reapplyZoom" , tabId : tab . tabId , webContentsId : wc . id } , ( ) =>
2112- wc . setZoomFactor ( tab . zoomFactor ) ,
2113- ) . pipe ( Effect . ignore ) ;
2114- } ,
2115- { discard : true } ,
2116- ) ;
2119+ const tabIds = Array . from ( ( yield * SynchronizedRef . get ( tabsRef ) ) . keys ( ) ) ;
2120+ yield * Effect . forEach ( tabIds , assertTabZoom , { discard : true } ) ;
21172121 } ) ;
21182122
21192123 const applyZoom = Effect . fn ( "PreviewManager.applyZoom" ) ( function * (
0 commit comments