mirror of
https://github.com/flutter/flutter
synced 2024-10-30 01:59:05 +00:00
[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
This commit is contained in:
parent
f830e4be4d
commit
0d52630ef1
2 changed files with 12 additions and 4 deletions
|
@ -586,7 +586,7 @@ class WebServiceWorker extends Target {
|
|||
final String hash = md5.convert(await file.readAsBytes()).toString();
|
||||
urlToHash[url] = hash;
|
||||
// Add an additional entry for the base URL.
|
||||
if (environment.fileSystem.path.basename(url) == 'index.html') {
|
||||
if (url == 'index.html') {
|
||||
urlToHash['/'] = hash;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1020,14 +1020,22 @@ void main() {
|
|||
environment.outputDir
|
||||
.childFile('index.html')
|
||||
.createSync(recursive: true);
|
||||
environment.outputDir
|
||||
.childFile('assets/index.html')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('A');
|
||||
await WebServiceWorker(globals.fs, WebRendererMode.auto, isWasm: false).build(environment);
|
||||
|
||||
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('"/": "d41d8cd98f00b204e9800998ecf8427e"'));
|
||||
contains('"/": "$rootIndexHash"'));
|
||||
expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(),
|
||||
contains('"index.html": "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(),
|
||||
contains('"assets/index.html": "7fc56270e7a70fa81a5935b72eacbe29"'));
|
||||
expect(environment.buildDir.childFile('service_worker.d'), exists);
|
||||
}));
|
||||
|
||||
|
|
Loading…
Reference in a new issue