Unverified Commit 0d52630e authored by Pavel Mazhnik's avatar Pavel Mazhnik Committed by GitHub

[web] cache the base URL as root index.html (#136594)

Fixes https://github.com/flutter/flutter/issues/136593

Caching of the base url was introduced in https://github.com/flutter/flutter/pull/53666 but resources can contain multiple `index.html` files, and currently hash of the **latest** asset will be assigned to the base url, which is not necessarily the root index.html
parent f830e4be
...@@ -586,7 +586,7 @@ class WebServiceWorker extends Target { ...@@ -586,7 +586,7 @@ class WebServiceWorker extends Target {
final String hash = md5.convert(await file.readAsBytes()).toString(); final String hash = md5.convert(await file.readAsBytes()).toString();
urlToHash[url] = hash; urlToHash[url] = hash;
// Add an additional entry for the base URL. // Add an additional entry for the base URL.
if (environment.fileSystem.path.basename(url) == 'index.html') { if (url == 'index.html') {
urlToHash['/'] = hash; urlToHash['/'] = hash;
} }
} }
......
...@@ -1020,14 +1020,22 @@ void main() { ...@@ -1020,14 +1020,22 @@ void main() {
environment.outputDir environment.outputDir
.childFile('index.html') .childFile('index.html')
.createSync(recursive: true); .createSync(recursive: true);
environment.outputDir
.childFile('assets/index.html')
..createSync(recursive: true)
..writeAsStringSync('A');
await WebServiceWorker(globals.fs, WebRendererMode.auto, isWasm: false).build(environment); await WebServiceWorker(globals.fs, WebRendererMode.auto, isWasm: false).build(environment);
expect(environment.outputDir.childFile('flutter_service_worker.js'), exists); expect(environment.outputDir.childFile('flutter_service_worker.js'), exists);
// Contains file hash for both `/` and index.html. // Contains the same file hash for both `/` and the root index.html file.
const String rootIndexHash = 'd41d8cd98f00b204e9800998ecf8427e';
expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(),
contains('"/": "$rootIndexHash"'));
expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(), expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(),
contains('"/": "d41d8cd98f00b204e9800998ecf8427e"')); contains('"index.html": "$rootIndexHash"'));
// Make sure `assets/index.html` has a different hash than `index.html`.
expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(), expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(),
contains('"index.html": "d41d8cd98f00b204e9800998ecf8427e"')); contains('"assets/index.html": "7fc56270e7a70fa81a5935b72eacbe29"'));
expect(environment.buildDir.childFile('service_worker.d'), exists); expect(environment.buildDir.childFile('service_worker.d'), exists);
})); }));
......
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