Open edbrims opened 5 years ago
This has to do with Dart2JS compiling / optimizing / tree-shaking each app separately.
We might consider having DDC warn (possibly at runtime) that a Dart object (a Dart Map in this case) leaked to JavaScript - somewhat akin to requiring allowInterop
for functions.
I'm sharing data between two apps using Dart2js's context. The first app runs code like this:
import 'dart:js'; ... final map = context['__thing'] ??= {}; map['string_key'] = true;
The second app does this:
import 'dart:js'; ... final map = context['__thing'] ??= {}; return map['string_key'] ?? false;
It works as intended in DDC: The first app creates context['__thing'] as a Dart map and populates it. The second app finds it and reads its values.
But when you deploy the code, Dart2js obfuscates the variable names, and you end up looking at different objects. The second app finds the map empty.
I can fix it by using a JsObject map instead of a Dart map: final map = context['__thing'] ??= JsObject.jsify({});
Should DDC somehow replicate the obfuscation in order to break in the same way?