[flutter_tools] hot reload/restart update for asset manager change (#66742)
Do not upload all assets on initial devFS sync. This should increase the reliability of the initial connection, even in the face of flaky devfs behavior, in addition to a moderate perf improvement. Updates fast-start to build assets as part of the initial bundle Requires flutter/engine#21436 Requires flutter/engine#21586 Requires flutter/engine#21611
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import 'test_data/hot_reload_with_asset.dart';
|
||||
import 'test_driver.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
void main() {
|
||||
Directory tempDir;
|
||||
final HotReloadWithAssetProject project = HotReloadWithAssetProject();
|
||||
FlutterRunTestDriver flutter;
|
||||
|
||||
setUp(() async {
|
||||
tempDir = createResolvedTempDirectorySync('hot_reload_test.');
|
||||
await project.setUpIn(tempDir);
|
||||
flutter = FlutterRunTestDriver(tempDir);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await flutter?.stop();
|
||||
tryToDelete(tempDir);
|
||||
});
|
||||
|
||||
testWithoutContext('hot reload does not need to sync assets on the first reload', () async {
|
||||
final Completer<void> onFirstLoad = Completer<void>();
|
||||
final Completer<void> onSecondLoad = Completer<void>();
|
||||
|
||||
flutter.stdout.listen((String line) {
|
||||
// If the asset fails to load, this message will be printed instead.
|
||||
// this indicates that the devFS was not able to locate the asset
|
||||
// after the hot reload.
|
||||
if (line.contains('FAILED TO LOAD')) {
|
||||
fail('Did not load asset: $line');
|
||||
}
|
||||
if (line.contains('LOADED DATA')) {
|
||||
onFirstLoad.complete();
|
||||
}
|
||||
if (line.contains('SECOND DATA')) {
|
||||
onSecondLoad.complete();
|
||||
}
|
||||
});
|
||||
flutter.stdout.listen(print);
|
||||
await flutter.run();
|
||||
await onFirstLoad.future;
|
||||
|
||||
project.uncommentHotReloadPrint();
|
||||
await flutter.hotReload();
|
||||
await onSecondLoad.future;
|
||||
});
|
||||
|
||||
testWithoutContext('hot restart does not need to sync assets on the first reload', () async {
|
||||
final Completer<void> onFirstLoad = Completer<void>();
|
||||
final Completer<void> onSecondLoad = Completer<void>();
|
||||
|
||||
flutter.stdout.listen((String line) {
|
||||
// If the asset fails to load, this message will be printed instead.
|
||||
// this indicates that the devFS was not able to locate the asset
|
||||
// after the hot reload.
|
||||
if (line.contains('FAILED TO LOAD')) {
|
||||
fail('Did not load asset: $line');
|
||||
}
|
||||
if (line.contains('LOADED DATA')) {
|
||||
onFirstLoad.complete();
|
||||
}
|
||||
if (line.contains('SECOND DATA')) {
|
||||
onSecondLoad.complete();
|
||||
}
|
||||
});
|
||||
flutter.stdout.listen(print);
|
||||
await flutter.run();
|
||||
await onFirstLoad.future;
|
||||
|
||||
project.uncommentHotReloadPrint();
|
||||
await flutter.hotRestart();
|
||||
await onSecondLoad.future;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import '../test_utils.dart';
|
||||
import 'project.dart';
|
||||
|
||||
class HotReloadWithAssetProject extends Project {
|
||||
@override
|
||||
final String pubspec = '''
|
||||
name: test
|
||||
environment:
|
||||
sdk: ">=2.0.0-dev.68.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
flutter:
|
||||
assets:
|
||||
- pubspec.yaml
|
||||
''';
|
||||
|
||||
@override
|
||||
final String main = r'''
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
final ByteData message = const StringCodec().encodeMessage('AppLifecycleState.resumed');
|
||||
await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', message, (_) { });
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
rootBundle.evict('pubspec.yaml');
|
||||
rootBundle.load('pubspec.yaml').then((_) {
|
||||
print('LOADED DATA');
|
||||
}, onError: (dynamic error, StackTrace stackTrace) {
|
||||
print('FAILED TO LOAD');
|
||||
});
|
||||
return Container();
|
||||
}
|
||||
}
|
||||
''';
|
||||
|
||||
void uncommentHotReloadPrint() {
|
||||
final String newMainContents = main.replaceAll(
|
||||
'LOADED DATA',
|
||||
'SECOND DATA',
|
||||
);
|
||||
writeFile(fileSystem.path.join(dir.path, 'lib', 'main.dart'), newMainContents);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user