@@ -3441,6 +3441,36 @@ ${["b", "h"].map((id, i) => ` <div data-composition-id="${id}" data-compositi
34413441 ] ) ;
34423442 } ) ;
34433443
3444+ it ( "lets a scene wait when its script only marks a node in its own root or reads an attribute off <html>" , async ( ) => {
3445+ const scene = ( id : string , script : string ) =>
3446+ `<template id="${ id } -template"><div data-composition-id="${ id } " id="r-${ id } "><p>${ id } </p>
3447+ <script>${ script } </script></div></template>` ;
3448+ const claim = ( id : string ) =>
3449+ `const root = (function(){var a=document.querySelectorAll('[id="r-${ id } "]');for(var i=0;i<a.length;i++){if(!a[i].__hfClaimed){a[i].__hfClaimed=1;return a[i];}}return document.getElementById('r-${ id } ');})();` ;
3450+ const dir = makeTempProject ( {
3451+ "index.html" : `<!doctype html><html><head></head><body>
3452+ <div data-composition-id="main" data-width="1920" data-height="1080" data-duration="8">
3453+ ${ [ "g" , "h" , "i" , "j" ] . map ( ( id , i ) => ` <div data-composition-id="${ id } " data-composition-src="compositions/${ id } .html" data-start="${ i * 2 } " data-duration="2"></div>` ) . join ( "\n" ) }
3454+ </div></body></html>` ,
3455+ "compositions/g.html" : scene ( "g" , claim ( "g" ) ) ,
3456+ "compositions/h.html" : scene (
3457+ "h" ,
3458+ 'JSON.parse(document.documentElement.getAttribute("data-composition-variables") || "[]");' ,
3459+ ) ,
3460+ "compositions/i.html" : scene ( "i" , "document.documentElement.classList.add('dark');" ) ,
3461+ "compositions/j.html" : scene ( "j" , "window.__hfClaimed = true;" ) ,
3462+ } ) ;
3463+ const doc = parseHTML ( await bundleToSingleHtml ( dir , { sceneParts : true } ) ) . document ;
3464+ const eager = ( id : string ) =>
3465+ doc . querySelector ( `div[data-hf-scene="${ id } "]` ) ?. getAttribute ( "data-hf-scene-eager" ) ;
3466+ expect ( [ "g" , "h" , "i" , "j" ] . map ( eager ) ) . toEqual ( [
3467+ null ,
3468+ null ,
3469+ "its script uses documentElement" ,
3470+ "its script uses window.__hfClaimed" ,
3471+ ] ) ;
3472+ } ) ;
3473+
34443474 it ( "marks a scene whose own script leaves work running as not swappable, and only that scene" , async ( ) => {
34453475 const dir = makeTempProject ( {
34463476 "index.html" : `<!doctype html><html><head>
0 commit comments