Skip to content

Dart2's ResizeObserver being broken by Dart minifier #40961

Closed
@janvladimirmostert

Description

@janvladimirmostert

When using ResizeObserver in Dart2 and compiling for release (i'm assuming it uses dart2js), it stops working. Have reproduced this issue in Dart 2.7.

ResizeObserver works when doing a regular webdev serve:

pub global run webdev serve web:9999

ResizeObserver stops working when building for release:

pub global run webdev build --output=web:build --release

Test HTML file to reproduce issue:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div class="div1" style="background-color: red">
        <textarea style="padding: 10px; margin: 10px;">
            TESTING
        </textarea>
    </div>
    <div class="div2" style="background-color: blue">
        .
    </div>
    <script defer src="bug_resize_observer.dart.js"></script>
</body>
</html>

Test Dart file to reproduce issue:

import "dart:html";

void main() {
  final DivElement div1 = querySelector("div.div1");
  final DivElement div2 = querySelector("div.div2");

  final ResizeObserver divResizeObserver = ResizeObserver((List<ResizeObserverEntry> blah1, ResizeObserver blah2) {
    print("inside divResizeObserverCallback");
    for (ResizeObserverEntry entry in blah1) {
        div2.style.height = "${entry.target.clientHeight}px";
    }
  });
  divResizeObserver.observe(div1);
}

When doing a regular webdev serve, it works fine, when you do a build with release mode, the ResizeObserver stops working. It would seem that minification is breaking it.

DevMode working (resizing text area and the blue div resizes as well):

Screenshot_20200310_213850

Release Mode not working (resizing text area and the blue div does nothing and errors appear in the console):

Screenshot_20200310_214030

Screenshot_20200310_214058

I've documented in a lot of detail the problem here and all the workarounds i've tried without success:
https://stackoverflow.com/questions/60620940/dart2s-resizeobserver-being-broken-by-dart-minifier

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions