@@ -76,6 +76,36 @@ interface ResolvedTransition {
7676export const PAGE_COMPOSITOR_CANVAS_ID = "__hf-page-side-compositor" ;
7777export const PAGE_COMPOSITOR_BUILD_CANARY = "__hf_page_compositor_v1__" ;
7878
79+ export interface ClonePinStyle {
80+ left : string ;
81+ top : string ;
82+ width : string ;
83+ height : string ;
84+ }
85+
86+ /**
87+ * Style values to pin a cloned scene root to the box its source measured
88+ * WHILE STILL LIVE in the document — never the composition's full pixel size.
89+ * A live-document `getBoundingClientRect()` already resolves `inset:0` (and
90+ * any authored explicit width/height) correctly against the real ancestor
91+ * chain; reapplying that exact box to the clone fixes the 0x0 collapse a
92+ * detached `inset:0` clone would otherwise have inside the staging canvas's
93+ * layout subtree, without ever overriding an author's own sizing.
94+ */
95+ export function clonePinStyleFor ( rect : {
96+ left : number ;
97+ top : number ;
98+ width : number ;
99+ height : number ;
100+ } ) : ClonePinStyle {
101+ return {
102+ left : `${ rect . left } px` ,
103+ top : `${ rect . top } px` ,
104+ width : `${ rect . width } px` ,
105+ height : `${ rect . height } px` ,
106+ } ;
107+ }
108+
79109export function isPageSideCompositingSupported ( ) : boolean {
80110 if ( typeof window === "undefined" || typeof document === "undefined" ) return false ;
81111 if ( ! isHtmlInCanvasCaptureSupported ( ) ) return false ;
@@ -232,6 +262,17 @@ export function installPageSideCompositor(options: PageCompositorInstallOptions)
232262 pWin . __hf_page_composite_pending = false ;
233263 return false ;
234264 }
265+ // Measure each scene's rendered box WHILE STILL LIVE — a scene root sized
266+ // only by `position:absolute; inset:0` resolves to 0x0 once cloned into
267+ // the staging canvas's layout subtree (no containing-block dimensions
268+ // there), and the transition textures blank out (wild report: explicit
269+ // 1080x1920 anchors fixed both transitions). The live document already
270+ // resolves inset:0 (and any authored explicit width/height) correctly
271+ // against the real ancestor chain, so pinning the clone to THIS measured
272+ // box fixes the collapse without ever overriding an author's own sizing.
273+ const fromPin = clonePinStyleFor ( fromEl . getBoundingClientRect ( ) ) ;
274+ const toPin = clonePinStyleFor ( toEl . getBoundingClientRect ( ) ) ;
275+
235276 while ( fromStaging . firstChild ) fromStaging . removeChild ( fromStaging . firstChild ) ;
236277 while ( toStaging . firstChild ) toStaging . removeChild ( toStaging . firstChild ) ;
237278 const fromClone = fromEl . cloneNode ( true ) as HTMLElement ;
@@ -244,20 +285,17 @@ export function installPageSideCompositor(options: PageCompositorInstallOptions)
244285 // paint record" and the shader degrades to a hard cut. The shader blends from
245286 // full-opacity textures via u_progress, so force the clones visible. Cf.
246287 // forceSceneVisibleInClone (html2canvas path).
247- for ( const clone of [ fromClone , toClone ] ) {
288+ for ( const [ clone , pin ] of [
289+ [ fromClone , fromPin ] ,
290+ [ toClone , toPin ] ,
291+ ] as const ) {
248292 clone . style . opacity = "1" ;
249293 clone . style . visibility = "visible" ;
250- // A scene root sized only by `position:absolute; inset:0` resolves to
251- // 0x0 inside the staging canvas's layout subtree (no containing-block
252- // dimensions there) — the clone then paints nothing and the transition
253- // textures are blank (wild report: explicit 1080x1920 anchors fixed
254- // both transitions). Pin the clone to the composition's pixel size;
255- // scenes that already carry explicit dimensions are unaffected.
256294 clone . style . position = "absolute" ;
257- clone . style . left = "0" ;
258- clone . style . top = "0" ;
259- clone . style . width = ` ${ width } px` ;
260- clone . style . height = ` ${ height } px` ;
295+ clone . style . left = pin . left ;
296+ clone . style . top = pin . top ;
297+ clone . style . width = pin . width ;
298+ clone . style . height = pin . height ;
261299 clone . querySelectorAll < HTMLElement > ( "[data-start]" ) . forEach ( ( el ) => {
262300 el . style . opacity = "1" ;
263301 el . style . visibility = "visible" ;
0 commit comments