Skip to content

Width of container with IFrame inside resets when a link in the IFrame is clicked #12554

Closed

Description

@samuknet

Width of container with IFrame inside resets when a link in the IFrame is clicked. The issue only occurs when the container has a transition on the width property.

See test case at: https://samuknet.github.io/test_cases/iframeWidthReset/

There is an IFrame in a container 'strip'. The IFrame is styled to have a width and height of 100% of the container.

When the page loads, JavaScript expands the container width to 100vw. The issue occurs whens clicking a link inside the IFrame. This causes the parent container to unexpectedly revert to the original width, 'resetting' the width property that had been applied with JavaScript.

The parent container has a CSS transition on the width property so that the initial change of width to 100vw is animated. Crucially, removing this CSS transition stops the container collapsing when clicking a link in the IFrame, suggesting that the issue is related to the transition property.

Activity

  1. jdm commented on Jul 22, 2016

    @jdm
    Member

    Reduced:

    <!doctype html>
    <html>
    <head>
            <meta charset="utf-8" />
            <style>
            .iframe-container {
                width: 120px;
                background-color: #DD545C;
                transition: width 2s ease-in-out; /* Commenting out this transition property stops the issue occuring*/
            }
    
            iframe {
                width: 100%;
             }
            </style>
            <script>
                    window.addEventListener('load', function() {
                            var container = document.querySelector('.iframe-container');
                            container.style.width = '100vw';
                    });
            </script>
    </head>
    
    <body>
    <article class="iframe-container">
            <iframe src="data:text/html,<a href='data:text/html,hello'>a link</a>"></iframe>
    </article>
    </body>
    </html>
  2. jdm commented on Jul 22, 2016

    @jdm
    Member

    Interestingly, this doesn't reproduce if incremental layout is disabled (using -i).

  3. added
    C-has-manual-testcase
    on Jul 22, 2016
  4. jdm commented on Jul 25, 2016

    @jdm
    Member

    @notriddle I've been flailing around in the layout code trying to figure this out and getting nowhere. Are you interested in taking a crack at it?

  5. jdm commented on Jul 25, 2016

    @jdm
    Member
  6. notriddle commented on Jul 25, 2016

    @notriddle
    Contributor

    Yes, I'm interested.

  7. self-assigned this
    on Jul 25, 2016
  8. notriddle commented on Jul 25, 2016

    @notriddle
    Contributor

    Seems to be a generic bug related to all replaced content:

    <!doctype html>
    <html>
    <head>
            <meta charset="utf-8" />
            <style>
            .img-container {
                width: 120px;
                background-color: #DD545C;
                transition: width 2s ease-in-out; /* Commenting out this transition property stops the issue occuring*/
            }
    
            img {
                width: 100%;
             }
            </style>
            <script>
                    window.addEventListener('load', function() {
                            var container = document.querySelector('.img-container');
                            container.style.width = '100vw';
                    });
            </script>
    </head>
    
    <body>
    <article class="img-container">
            <img src="data:image/png,">
    </article>
    <a href="#" onclick="document.getElementsByTagName('img')[0].src = '1'">click me</a>
    </body>
    </html>
  9. notriddle commented on Jul 26, 2016

    @notriddle
    Contributor

    It also applies to a similarly setup test with color instead of width.

  10. notriddle commented on Jul 26, 2016

    @notriddle
    Contributor

    It also has nothing to do with replaced content:

    <!doctype html>
    <html>
    <head>
            <meta charset="utf-8" />
            <style>
            .container {
                width: 120px;
                background-color: red;
                transition: background-color 2s ease-in-out; /* Commenting out this transition property stops the issue occuring*/
            }
            </style>
            <script>
                    window.addEventListener('load', function() {
                            var container = document.querySelector('.container');
                            container.style.backgroundColor = "black";
                    });
                    window.setInterval(function() {
                            var container = document.querySelector('.container');
                            console.log(window.getComputedStyle(container).backgroundColor);
                    }, 100);
            </script>
    </head>
    
    <body>
    <article class="container">
    <div>a</div>
    </article>
    <a href="#" onclick="document.getElementsByTagName('div')[0].innerHTML = 'b'">click me</a>
    </body>
    </html>

    Current working theory: the fact that getComputedValues() isn't changed by the transition (which is also a bug, by the way) is related to this bug. We're cloning the Arc corresponding to this DOM node, attaching it to the fragment. We perform the animation on the fragment's copy, but not on the node's. When we rebuild the fragment without restyling it, we make a new clone of the node's computed style, which has not been updated by the animation, thus reverting it.

  11. jdm commented on Jul 27, 2016

    @jdm
    Member

    @notriddle getComputedStyle may be a separate bug, since the original one was fixed by turning off incremental layout, but the most recent test case is not.

  12. added 2 commits that reference this issue on Jul 28, 2016
    8e3eafb
    27d8fb3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-layout/incrementalC-has-manual-testcase

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions