[web] Split initialization of the _flutter namespace and loader object. (flutter/engine#51294)

This makes it possible to more flexibly compose `{{flutter_js}}` and `{{flutter_build_options}}` in @eyebrowsoffire's [bootstrapping improvements PR](https://github.com/flutter/flutter/pull/144434).

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
David Iglesias
2024-03-11 16:21:17 -07:00
committed by GitHub
parent 41a13ea3e5
commit e62c718145
2 changed files with 14 additions and 4 deletions

View File

@@ -554,13 +554,21 @@ class BrowserPlatform extends PlatformPlugin {
(CompileConfiguration config) => _makeBuildConfigString(scriptBase, config)
).join(',\n');
final String bootstrapScript = '''
<script src="/flutter_js/flutter.js"></script>
<script>
// Define this before loading flutter.js to test PR flutter/engine#51294
if (!window._flutter) {
window._flutter = {};
}
</script>
<script>
_flutter.buildConfig = {
builds: [
$buildConfigsString
]
};
</script>
<script src="/flutter_js/flutter.js"></script>
<script>
_flutter.loader.load({
config: {
canvasKitBaseUrl: "/canvaskit/",

View File

@@ -5,7 +5,9 @@
import { FlutterLoader } from './loader.js';
if (!window._flutter) {
window._flutter = {
loader: new FlutterLoader()
};
window._flutter = {};
}
if (!window._flutter.loader) {
window._flutter.loader = new FlutterLoader();
}