Skip to content

Dart2's ResizeObserverEntry being broken by minifier #40975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
janvladimirmostert opened this issue Mar 11, 2020 · 1 comment
Open

Dart2's ResizeObserverEntry being broken by minifier #40975

janvladimirmostert opened this issue Mar 11, 2020 · 1 comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. web-libraries Issues impacting dart:html, etc., libraries

Comments

@janvladimirmostert
Copy link

I've logged a bug for ResizeObserver that was breaking when building with release mode (#40961), that is working now in 2.8 dev-13, but ResizeObserverEntry is still breaking.

import "dart:html";
import "dart:js";

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

  final void Function(List blah1, ResizeObserver blah2) callback = (blah1, _) {
    print("inside divResizeObserverCallback");
    blah1.forEach((entry) {
      context["console"].callMethod("log", [entry]);
      div2.style.height = "${entry.target.clientHeight}px";
    });
  };
  final ResizeObserver divResizeObserver = ResizeObserver(callback);
  divResizeObserver.observe(div1);
}

the console.log outputs that entry is of type DartObject which contains ResizeObserverEntry, casting entry to that however fails with a cast error and trying to access target from entry.target fails with:

Uncaught TypeError: J.d8(...).gv is not a function
    at Object.dD (bug_resize_observer.dart.js:1114)
    at c7.$1 (bug_resize_observer.dart.js:1995)
    at r.u (bug_resize_observer.dart.js:1419)
    at Object.dB (bug_resize_observer.dart.js:1109)
    at c8.$2 (bug_resize_observer.dart.js:1986)
    at eW (bug_resize_observer.dart.js:227)
    at ResizeObserver.<anonymous> (bug_resize_observer.dart.js:232)
dD @ bug_resize_observer.dart.js:1114
$1 @ bug_resize_observer.dart.js:1995
u @ bug_resize_observer.dart.js:1419
dB @ bug_resize_observer.dart.js:1109
$2 @ bug_resize_observer.dart.js:1986
eW @ bug_resize_observer.dart.js:227
(anonymous) @ bug_resize_observer.dart.js:232

Casting:

      div2.style.height = "${(entry as ResizeObserverEntry).target.clientHeight}px";
Uncaught CastError: Instance of 'ResizeObserverEntry': type 'minified:aC' is not a subtype of type 'minified:f7'
@keertip keertip added the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. label Mar 11, 2020
@joshualitt joshualitt added the web-libraries Issues impacting dart:html, etc., libraries label Nov 2, 2021
@vakenbolt
Copy link

vakenbolt commented Sep 5, 2022

I can confirm that this still broken:

Dart Version: 2.16.2

main.dart.js:384 Uncaught TypeError: Instance of 'ResizeObserverEntry': type 'minified:db' is not a subtype of type 'minified:SH'
    at Object.c (main.dart.js:384:3)
    at Object.L7 (main.dart.js:953:17)
    at cx.Qy [as a] (main.dart.js:948:3)
    at cx.QE (main.dart.js:920:10)
    at vL.$2 (main.dart.js:20958:34)
    at RG (main.dart.js:465:17)
    at ResizeObserver.<anonymous> (main.dart.js:472:51)

Steps to reproduce:

var resizeObserver = ResizeObserver(((entries, observer) {
  for (ResizeObserverEntry entry in entries) {
    print(entry);
  }
}

NOTE: The code above works fine when you are running it locally with pub serve however it breaks when the code is minified as mentioned by the OP.

If you try to work around the issue without adding a type:

var resizeObserver = ResizeObserver(((entries, observer) {
  for (var entry in entries) {
    print(entry);
  }
}

Still produces an error when minified:

main.dart.js:20990 Uncaught TypeError: r.gql is not a function
    at vO.$2 (main.dart.js:20990:3)
    at RK (main.dart.js:465:17)
    at ResizeObserver.<anonymous> (main.dart.js:472:51)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. web-libraries Issues impacting dart:html, etc., libraries
Projects
None yet
Development

No branches or pull requests

4 participants