mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[web] Fix paths fetched by flutter.js (#118684)
This commit is contained in:
parent
bd7bee0f9e
commit
3bf79607dd
@ -20,6 +20,21 @@ _flutter.loader = null;
|
||||
|
||||
(function () {
|
||||
"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.
|
||||
*
|
||||
@ -120,8 +135,7 @@ _flutter.loader = null;
|
||||
}
|
||||
const {
|
||||
serviceWorkerVersion,
|
||||
serviceWorkerUrl = "flutter_service_worker.js?v=" +
|
||||
serviceWorkerVersion,
|
||||
serviceWorkerUrl = `${baseUri}flutter_service_worker.js?v=${serviceWorkerVersion}`,
|
||||
timeoutMillis = 4000,
|
||||
} = settings;
|
||||
|
||||
@ -239,7 +253,7 @@ _flutter.loader = null;
|
||||
* Returns undefined when an `onEntrypointLoaded` callback is supplied in `options`.
|
||||
*/
|
||||
async loadEntrypoint(options) {
|
||||
const { entrypointUrl = "main.dart.js", onEntrypointLoaded } =
|
||||
const { entrypointUrl = `${baseUri}main.dart.js`, onEntrypointLoaded } =
|
||||
options || {};
|
||||
|
||||
return this._loadEntrypoint(entrypointUrl, onEntrypointLoaded);
|
||||
|
||||
@ -852,6 +852,18 @@ void main() {
|
||||
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 {
|
||||
globals.fs.file('bin/cache/flutter_web_sdk/canvaskit/foo')
|
||||
..createSync(recursive: true)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user