Skip to content

Commit 1e847f2

Browse files
cdeilmdebbar
andauthored
[flutter_tools] Include flutter.js.map in web builds (flutter#192257)
The prebuilt Flutter web loader ends with a reference to `flutter.js.map`. The matching source map is already part of the Flutter web SDK, but `WebBuiltInAssets` only copies `flutter.js` and CanvasKit into `build/web`. As a result, browser developer tools request a file that is missing from every web build, and tools such as error reporters cannot resolve stack frames from the loader. This change declares `flutter.js.map` as a built-in web output and copies it alongside `flutter.js`. The copy is intentionally independent of `--[no-]source-maps`. That option controls source maps produced while compiling the application, while `flutter.js` is a prebuilt SDK artifact that always references its own prebuilt map. Fixes flutter#145111. ## Validation - `./bin/dart --enable-asserts dev/bots/analyze.dart` - `../../bin/dart test test/general.shard/build_system/targets/web_test.dart` (626 tests) - `bin/flutter-dev build web` - incremental rebuild after removing `build/web/flutter.js.map` - `bin/flutter-dev build web --source-maps` - `bin/flutter-dev build web --wasm` - verified the emitted map is byte-for-byte identical to the Flutter web SDK artifact No changes to `flutter/tests` are required. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Mouad Debbar <[email protected]>
1 parent 9c93149 commit 1e847f2

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

  • packages/flutter_tools

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ class WebBuiltInAssets extends Target {
14901490
@override
14911491
List<Source> get outputs => <Source>[
14921492
const Source.pattern('{BUILD_DIR}/flutter.js'),
1493+
const Source.pattern('{BUILD_DIR}/flutter.js.map'),
14931494
for (final File file in _canvasKitFiles)
14941495
Source.pattern('{BUILD_DIR}/canvaskit/${_filePathRelativeToCanvasKitDirectory(file)}'),
14951496
];
@@ -1506,15 +1507,15 @@ class WebBuiltInAssets extends Target {
15061507
file.copySync(targetPath);
15071508
}
15081509

1509-
// Write the flutter.js file
1510-
final String flutterJsOut = fileSystem.path.join(environment.outputDir.path, 'flutter.js');
1511-
final File flutterJsFile = fileSystem.file(
1512-
fileSystem.path.join(
1513-
globals.artifacts!.getHostArtifact(HostArtifact.flutterJsDirectory).path,
1514-
'flutter.js',
1515-
),
1510+
// Write the Flutter loader and its source map.
1511+
final Directory flutterJsDirectory = fileSystem.directory(
1512+
globals.artifacts!.getHostArtifact(HostArtifact.flutterJsDirectory).path,
15161513
);
1517-
flutterJsFile.copySync(flutterJsOut);
1514+
for (final fileName in <String>['flutter.js', 'flutter.js.map']) {
1515+
final File sourceFile = flutterJsDirectory.childFile(fileName);
1516+
final File targetFile = environment.outputDir.childFile(fileName);
1517+
sourceFile.copySync(targetFile.path);
1518+
}
15181519
}
15191520
}
15201521

‎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
@@ -84,6 +84,9 @@ name: foo
8484
globals.fs
8585
.file('bin/cache/flutter_web_sdk/flutter_js/flutter.js')
8686
.createSync(recursive: true);
87+
globals.fs
88+
.file('bin/cache/flutter_web_sdk/flutter_js/flutter.js.map')
89+
.createSync(recursive: true);
8790
globals.fs
8891
.file('engine/src/flutter/txt/third_party/fonts/Roboto-Regular.ttf')
8992
.createSync(recursive: true);
@@ -1730,6 +1733,25 @@ _flutter.loader.load();
17301733
}),
17311734
);
17321735

1736+
test(
1737+
'WebBuiltInAssets declares and copies the Flutter loader source map',
1738+
() => testbed.run(() async {
1739+
final File flutterJsMapInput = globals.fs.file(
1740+
'bin/cache/flutter_web_sdk/flutter_js/flutter.js.map',
1741+
)..createSync(recursive: true);
1742+
flutterJsMapInput.writeAsStringSync('source map', flush: true);
1743+
globals.fs.directory('bin/cache/flutter_web_sdk/canvaskit').createSync(recursive: true);
1744+
1745+
final target = WebBuiltInAssets(globals.fs);
1746+
expect(target.outputs, contains(const Source.pattern('{BUILD_DIR}/flutter.js.map')));
1747+
await target.build(environment);
1748+
1749+
final File flutterJsMapOutput = environment.outputDir.childFile('flutter.js.map');
1750+
expect(flutterJsMapOutput, exists);
1751+
expect(flutterJsMapOutput.readAsStringSync(), 'source map');
1752+
}),
1753+
);
1754+
17331755
test(
17341756
'WebBuiltInAssets copies over canvaskit again if the web sdk changes',
17351757
() => testbed.run(() async {

0 commit comments

Comments
 (0)