Unverified Commit 3bf79607 authored by Mouad Debbar's avatar Mouad Debbar Committed by GitHub

[web] Fix paths fetched by flutter.js (#118684)

parent bd7bee0f
...@@ -20,6 +20,21 @@ _flutter.loader = null; ...@@ -20,6 +20,21 @@ _flutter.loader = null;
(function () { (function () {
"use strict"; "use strict";
const baseUri = ensureTrailingSlash(getBaseURI());
function getBaseURI() {
const base = document.querySelector("base");
return (base && base.getAttribute("href")) || "";
}
function ensureTrailingSlash(uri) {
if (uri == "") {
return uri;
}
return uri.endsWith("/") ? uri : `${uri}/`;
}
/** /**
* Wraps `promise` in a timeout of the given `duration` in ms. * Wraps `promise` in a timeout of the given `duration` in ms.
* *
...@@ -120,8 +135,7 @@ _flutter.loader = null; ...@@ -120,8 +135,7 @@ _flutter.loader = null;
} }
const { const {
serviceWorkerVersion, serviceWorkerVersion,
serviceWorkerUrl = "flutter_service_worker.js?v=" + serviceWorkerUrl = `${baseUri}flutter_service_worker.js?v=${serviceWorkerVersion}`,
serviceWorkerVersion,
timeoutMillis = 4000, timeoutMillis = 4000,
} = settings; } = settings;
...@@ -239,7 +253,7 @@ _flutter.loader = null; ...@@ -239,7 +253,7 @@ _flutter.loader = null;
* Returns undefined when an `onEntrypointLoaded` callback is supplied in `options`. * Returns undefined when an `onEntrypointLoaded` callback is supplied in `options`.
*/ */
async loadEntrypoint(options) { async loadEntrypoint(options) {
const { entrypointUrl = "main.dart.js", onEntrypointLoaded } = const { entrypointUrl = `${baseUri}main.dart.js`, onEntrypointLoaded } =
options || {}; options || {};
return this._loadEntrypoint(entrypointUrl, onEntrypointLoaded); return this._loadEntrypoint(entrypointUrl, onEntrypointLoaded);
......
...@@ -852,6 +852,18 @@ void main() { ...@@ -852,6 +852,18 @@ void main() {
contains('"main.dart.js"')); contains('"main.dart.js"'));
})); }));
test('flutter.js sanity checks', () {
final String flutterJsContents = flutter_js.generateFlutterJsFile();
expect(flutterJsContents, contains('"use strict";'));
expect(flutterJsContents, contains('main.dart.js'));
expect(flutterJsContents, contains('flutter_service_worker.js?v='));
expect(flutterJsContents, contains('document.createElement("script")'));
expect(flutterJsContents, contains('"application/javascript"'));
expect(flutterJsContents, contains('const baseUri = '));
expect(flutterJsContents, contains('document.querySelector("base")'));
expect(flutterJsContents, contains('.getAttribute("href")'));
});
test('flutter.js is not dynamically generated', () => testbed.run(() async { test('flutter.js is not dynamically generated', () => testbed.run(() async {
globals.fs.file('bin/cache/flutter_web_sdk/canvaskit/foo') globals.fs.file('bin/cache/flutter_web_sdk/canvaskit/foo')
..createSync(recursive: true) ..createSync(recursive: true)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment