Skip to content

Commit b57c59b

Browse files
Invalidate the WebStaticAssets target if the web sdk changes. (#123739)
Invalidate the `WebStaticAssets` target if the web sdk changes.
1 parent 06f015a commit b57c59b

File tree

2 files changed

+27
-3
lines changed
  • packages/flutter_tools

2 files changed

+27
-3
lines changed

packages/flutter_tools/lib/src/build_system/targets/web.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ class WebReleaseBundle extends Target {
494494
/// Static assets provided by the Flutter SDK that do not change, such as
495495
/// CanvasKit.
496496
///
497-
/// These assets can be cached forever and are only invalidated when the
498-
/// Flutter SDK is upgraded to a new version.
497+
/// These assets can be cached until a new version of the flutter web sdk is
498+
/// downloaded.
499499
class WebBuiltInAssets extends Target {
500500
const WebBuiltInAssets(this.fileSystem, {required this.isWasm});
501501

@@ -512,7 +512,9 @@ class WebBuiltInAssets extends Target {
512512
List<String> get depfiles => const <String>[];
513513

514514
@override
515-
List<Source> get inputs => const <Source>[];
515+
List<Source> get inputs => const <Source>[
516+
Source.hostArtifact(HostArtifact.flutterWebSdk),
517+
];
516518

517519
@override
518520
List<Source> get outputs => const <Source>[];

packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,4 +946,26 @@ void main() {
946946
.childFile('canvaskit.wasm')
947947
.existsSync(), true);
948948
}));
949+
950+
test('wasm copies over canvaskit again if the web sdk changes', () => testbed.run(() async {
951+
final File canvasKitInput = globals.fs.file('bin/cache/flutter_web_sdk/canvaskit/canvaskit.wasm')
952+
..createSync(recursive: true);
953+
canvasKitInput.writeAsStringSync('foo', flush: true);
954+
955+
await WebBuiltInAssets(globals.fs, isWasm: true).build(environment);
956+
957+
final File canvasKitOutputBefore = environment.outputDir.childDirectory('canvaskit')
958+
.childFile('canvaskit.wasm');
959+
expect(canvasKitOutputBefore.existsSync(), true);
960+
expect(canvasKitOutputBefore.readAsStringSync(), 'foo');
961+
962+
canvasKitInput.writeAsStringSync('bar', flush: true);
963+
964+
await WebBuiltInAssets(globals.fs, isWasm: true).build(environment);
965+
966+
final File canvasKitOutputAfter = environment.outputDir.childDirectory('canvaskit')
967+
.childFile('canvaskit.wasm');
968+
expect(canvasKitOutputAfter.existsSync(), true);
969+
expect(canvasKitOutputAfter.readAsStringSync(), 'bar');
970+
}));
949971
}

0 commit comments

Comments
 (0)