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
dart2js: runtimeType.toString() is wrong when using minify #9217
Comments
Is this using the dart2dart minifier? Added NeedsInfo label. |
This comment was originally written by fra...@igindo.com I only tested using dart2js, however dart2dart would probably have the same problem? |
Thanks for the update. Added Area-Dart2JS, Triaged labels. |
As far as I know, this is the expected behavior. cc @gbracha. |
This comment was originally written by fra...@igindo.com I use runtimetype to dynamically add default CSS styles at runtime, Perhaps you could provide a new type property next to runtimeType which holds the original class name as a String? |
The underlying problem is this: a big part of the size reduction we achieve with minification is due to using shorter names. Retaining the original name is adds an overhead which we deem is too large. We are working on solving these issues, but if you really care about download size, you'll probably have do something like this: getName(foo) { We'll probably add annotations to control which names are preserved and which aren't. In that case, you might be able to write something like this: @UseClassNames(subclassesOf: const [Element]) |
Added this to the Later milestone. |
Added TriageForM5 label. |
Removed TriageForM5 label. |
Removed this from the Later milestone. |
Removed Oldschool-Milestone-Later label. |
Issue #20457 has been merged into this issue. |
1 similar comment
Issue #20457 has been merged into this issue. |
This comment was originally written by youyou333...@gmail.com I think it would be better to mention this behavior in runtimeType doc until this is fixed |
This is not just a minification issue. All classes have different JavaScript names, and the JavaScript name is strongly related (1-1) to the runtimeType name. We would have to substantially change the type representation to fix this. I'm not saying we should not fix this, just that it has a nontrivial implementation cost. We could store the full name against the minified name. This would increase the size of minifed programs by about 5%. Many of our customers do not believe this cost is justified and would need a way to make it opt-in. A consequence of the 1-1 correspondence is that even unminified programs can print the 'wrong' name.
|
I have same error with JSON Object. On Android, it is _InternalLinkedHashMap<String, dynamic>, on Web it's _JsonMap. But on release is mininy:ds. Don't use dynamic.runtimeType, replace with "object is Map<String,dynamic>" instead |
Found this to be a problem manifesting when building a Flutter project for release, if built for debug, the names where correct. example:
Here I get the following print results in console:
In release build:
You see, my expected type check didn't checkout because the expected Will file an issue for this in Flutter/dart... Thanx for mentioned this here! |
@RoarGronmo Don't compare types like this. Use
|
This issue was originally filed by fra...@igindo.com
Dart classes have a 'runtimeType' property
DivElement foo = new DivElement();
print(foo.runtimeType); // prints 'DivElement'
However, with the minify flag on, you get the minified class name returned
// --minify TRUE
print(foo.runtimeType); // prints 'cB' for example
The text was updated successfully, but these errors were encountered: