Skip to content

Truly independent web browser

2.1 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<div id="scroller" style="overflow: scroll; width: 300px; height: 200px;">
    <svg width="250" height="100" style="display: block;">
        <foreignObject width="250" height="100">
            <div xmlns="http://www.w3.org/1999/xhtml" style="height: 90px;">
                <span id="sticky" style="position: sticky; top: 10px;">sticky</span>
                <div id="filler" style="height: 30px;"></div>
            </div>
        </foreignObject>
    </svg>
    <div style="height: 1000px;"></div>
</div>
<script>
    // A partial SVG relayout recreates the line paintables of inline-level elements inside
    // <foreignObject>, which destroys their sticky insets and scroll frame indices while the
    // scroll state still holds a sticky frame for the old paintable. Refreshing the constraints
    // of the stale frame instead dereferences the dead paintable and crashes WebContent.
    // NOTE: All geometry reads happen before any println(), because printing mutates the DOM and
    //       forces a relayout that would mask missing invalidation.
    test(() => {
        const scroller = document.getElementById("scroller");
        const sticky = document.getElementById("sticky");
        const filler = document.getElementById("filler");

        scroller.scrollTop = 30;
        const stickyTopBefore = sticky.getBoundingClientRect().top;

        let stickyTopAfter;
        const work = layoutWork(() => {
            // Dirties layout inside the SVG subtree only, so the next layout update takes the partial
            // SVG relayout path instead of a full relayout. The filler is after the sticky element in
            // flow, so growing it must not move the sticky element.
            filler.style.height = "50px";

            stickyTopAfter = sticky.getBoundingClientRect().top;
        });

        println(`sticky position stable across partial SVG relayout: ${stickyTopAfter === stickyTopBefore}`);
        println(`layout passes: ${work.passes().join(" | ") || "(no layout)"}`);
    });
</script>