This repository was archived by the owner on Feb 22, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
lib/src/web/file_generators
test/general.shard/build_system/targets Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,21 @@ _flutter.loader = null;
2020
2121(function () {
2222 "use strict";
23+
24+ const baseUri = ensureTrailingSlash(getBaseURI());
25+
26+ function getBaseURI() {
27+ const base = document.querySelector("base");
28+ return (base && base.getAttribute("href")) || "";
29+ }
30+
31+ function ensureTrailingSlash(uri) {
32+ if (uri == "") {
33+ return uri;
34+ }
35+ return uri.endsWith("/") ? uri : `${uri}/`;
36+ }
37+
2338 /**
2439 * Wraps `promise` in a timeout of the given `duration` in ms.
2540 *
@@ -120,8 +135,7 @@ _flutter.loader = null;
120135 }
121136 const {
122137 serviceWorkerVersion,
123- serviceWorkerUrl = "flutter_service_worker.js?v=" +
124- serviceWorkerVersion,
138+ serviceWorkerUrl = `${baseUri}flutter_service_worker.js?v=${serviceWorkerVersion}`,
125139 timeoutMillis = 4000,
126140 } = settings;
127141
@@ -239,7 +253,7 @@ _flutter.loader = null;
239253 * Returns undefined when an `onEntrypointLoaded` callback is supplied in `options`.
240254 */
241255 async loadEntrypoint(options) {
242- const { entrypointUrl = " main.dart.js" , onEntrypointLoaded } =
256+ const { entrypointUrl = `${baseUri} main.dart.js` , onEntrypointLoaded } =
243257 options || {};
244258
245259 return this._loadEntrypoint(entrypointUrl, onEntrypointLoaded);
Original file line number Diff line number Diff line change @@ -852,6 +852,18 @@ void main() {
852852 contains ('"main.dart.js"' ));
853853 }));
854854
855+ test ('flutter.js sanity checks' , () {
856+ final String flutterJsContents = flutter_js.generateFlutterJsFile ();
857+ expect (flutterJsContents, contains ('"use strict";' ));
858+ expect (flutterJsContents, contains ('main.dart.js' ));
859+ expect (flutterJsContents, contains ('flutter_service_worker.js?v=' ));
860+ expect (flutterJsContents, contains ('document.createElement("script")' ));
861+ expect (flutterJsContents, contains ('"application/javascript"' ));
862+ expect (flutterJsContents, contains ('const baseUri = ' ));
863+ expect (flutterJsContents, contains ('document.querySelector("base")' ));
864+ expect (flutterJsContents, contains ('.getAttribute("href")' ));
865+ });
866+
855867 test ('flutter.js is not dynamically generated' , () => testbed.run (() async {
856868 globals.fs.file ('bin/cache/flutter_web_sdk/canvaskit/foo' )
857869 ..createSync (recursive: true )
You can’t perform that action at this time.
0 commit comments