-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Unify JS configuration. Make it available from initEngine. #37187
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, with a small nitpick.
One suggestion, take it or leave it: It might be nice if FlutterConfiguration
and JSFlutterConfiguration
shared the same base class with the different configuration getters on it. That way, if a new field is added to the configuration, the analyzer will tell you that you need to add it to both classes. I'm not sure if this gets weird with the static interop stuff, so if it's too much of a pain feel free to ignore.
import 'js_interop/js_loader.dart'; | ||
import 'js_interop/js_promise.dart'; | ||
|
||
/// The type of a function that initializes an engine (in Dart) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: end dartdocs with a period.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, do +1 here: https://github.com/dart-lang/linter/issues/1433 :P
lib/web_ui/test/canvaskit/initialization/initialization_stores_config.dart
Outdated
Show resolved
Hide resolved
@eyebrowsoffire I think that extending js-interop classes with dart classes (and vice versa?) is a big no-no. (Maybe that's why the FlutterConfiguration currently just wraps the JsFlutterConfiguration?) This is a great suggestion, though! (I'd try it if I didn't have the suspicion that it can break wasm interop :P) One drawback: wouldn't that mean that people need to specify the getter name in 3 places, rather than 2? Also, if they forget to set it in the base class, but not in the JS/Dart implementations, everything would Still Work™. If I could define the getters somehow ONCE, I'd be 100% sold. |
I think I addressed all the comments in the PR. PTAL @yjbanov, @eyebrowsoffire! And thanks for the review! |
Please, do make sure we like the names for the new JsFlutterConfiguration values that this PR is adding:
once this lands, they become public API (the other 4 values already existed in the object). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// | ||
/// Both methods are **disallowed** to be used at the same time. | ||
/// | ||
/// Example (Before): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove the "before" parts, let's boldly step into the new world! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree, I'll remove these docs when we clean up the deprecated code. What I'm going to do, however, is move the new style to the top (and not call it "after"/"new" or anything), and move the legacy style underneath.
@eyebrowsoffire @ditman I've always been suspicious about using inheritance for classes used to pass data, as opposed to delivering behavior. There are some expectations that come with inheritance that may not be appropriate. For example, there's the Liskov substitution principle which doesn't make sense for this case. I've always preferred composition for data over inheritance. |
* Extend configuration.dart * Reuse JsFlutterConfiguration JS-interop as the configuration source both for initEngine, and the window.flutterConfig object. * Add 'renderer' and 'targetElement' fields to the JsFlutterConfiguration object. * Modify the `FlutterConfiguration` object so that it supports more than one configuration source. Return the first non-null value that was most recently set, or fall back to a default.
* runtimeConfig -> configuration (as unnamed function parameter) * runtimeConfiguration -> jsConfiguration (as named function parameter, to prevent clashes with the configuration singleton in the engine code) * initEngine -> initializeEngine (because no need to abbreviate that)
7ab4b89
to
86f663d
Compare
Rebased to see if it heals the failing "impeller" tests. |
…114728) * 24c3a9f51 fix recursive self calls (flutter/engine#37321) * 2a1be6d4d Roll Skia from dc49f35e1ac6 to 7a98accb20d5 (6 revisions) (flutter/engine#37328) * ba390f2a7 [web] Unify JS configuration. Make it available from initEngine. (flutter/engine#37187)
…tter#37187) * Add the 'windows' parameter to the initializeEngine function. * Wire the initEngine configuration into the engine. * Extend configuration.dart * Reuse JsFlutterConfiguration JS-interop as the configuration source both for initEngine, and the window.flutterConfig object. * Add 'renderer' and 'targetElement' fields to the JsFlutterConfiguration object. * Modify the `FlutterConfiguration` object so that it supports more than one configuration source. Return the first non-null value that was most recently set, or fall back to a default. * Silence bootstrap initialization log to debug level. * targetElement to hostElement * jsParams -> runtimeConfiguration * Add configuration_test.dart * Add test to check init stores config. * Renamed test so it actually runs. * Update configuration object. Make it throwy at init/override. * Use new config object, tweak some docs. * Tweak warn/assert messages. * Some renaming: * runtimeConfig -> configuration (as unnamed function parameter) * runtimeConfiguration -> jsConfiguration (as named function parameter, to prevent clashes with the configuration singleton in the engine code) * initEngine -> initializeEngine (because no need to abbreviate that) * Ensure init test does not use global config. * Sort JsFlutterConfiguration getters alphabetically. * Addresses PR comments.
…lutter#114728) * 24c3a9f51 fix recursive self calls (flutter/engine#37321) * 2a1be6d4d Roll Skia from dc49f35e1ac6 to 7a98accb20d5 (6 revisions) (flutter/engine#37328) * ba390f2a7 [web] Unify JS configuration. Make it available from initEngine. (flutter/engine#37187)
…lutter#114728) * 24c3a9f51 fix recursive self calls (flutter/engine#37321) * 2a1be6d4d Roll Skia from dc49f35e1ac6 to 7a98accb20d5 (6 revisions) (flutter/engine#37328) * ba390f2a7 [web] Unify JS configuration. Make it available from initEngine. (flutter/engine#37187)
Changes
This PR does most of the configuration work (including a stretch goal) described in this document.
In particular, it extends the currently existing plumbing to pass and store Flutter engine configuration from JS (through the
initializeEngine
method).The configuration system now behaves like this:
JsFlutterConfiguration
JS-interop class is reused in the flutter.jsEngineInitializer
object so config passing from HTML -> Flutter stays the same across: the global variable, and initEngine call.window.flutterConfiguration
andwindow.flutterWebRenderer
) are now deprecated, and that they should useengineInitializer.initializeEngine(config)
instead.initializeEngine
call).Demo
This PR, not only adds a
hostElement
parameter (unused for now), but also all the properties defined in theconfiguration.dart
file. For now:Here's a demo of an app running this code, and configuring everything from its index.html.
Note that the demo has a warning, because it's using a deprecated configuration style:
The demo does fail with an assertion in development mode:
TL;DR API:
Issues
Testing
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.