Skip to content

Commit 07c702f

Browse files
authored
[web] Warn users when picking a deprecated renderer. (flutter#55709)
Warn users when they pick a deprecated renderer for the web, and point them to the appropriate /go/ link. ## Issues * Part of flutter#145954 * Fixes flutter#154879 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 7d56a8c commit 07c702f

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

lib/web_ui/lib/src/engine/configuration.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class FlutterConfiguration {
167167

168168
/// Auto detect which rendering backend to use.
169169
///
170-
/// Using flutter tools option "--web-render=auto" or not specifying one
170+
/// Using flutter tools option "--web-renderer=auto" or not specifying one
171171
/// would set the value to true. Otherwise, it would be false.
172172
static const bool flutterWebAutoDetect =
173173
bool.fromEnvironment('FLUTTER_WEB_AUTO_DETECT', defaultValue: true);
@@ -177,10 +177,10 @@ class FlutterConfiguration {
177177

178178
/// Enable the Skia-based rendering backend.
179179
///
180-
/// Using flutter tools option "--web-render=canvaskit" would set the value to
180+
/// Using flutter tools option "--web-renderer=canvaskit" would set the value to
181181
/// true.
182182
///
183-
/// Using flutter tools option "--web-render=html" would set the value to false.
183+
/// Using flutter tools option "--web-renderer=html" would set the value to false.
184184
static const bool useSkia = bool.fromEnvironment('FLUTTER_WEB_USE_SKIA');
185185

186186
// Runtime parameters.

lib/web_ui/lib/src/engine/renderer.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ abstract class Renderer {
3838
useCanvasKit = FlutterConfiguration.useSkia;
3939
}
4040

41+
// Warn users in development that anything other than canvaskit is deprecated.
42+
assert(() {
43+
if (!useCanvasKit) {
44+
// The user requested 'html' or 'auto' either in the command-line or JS.
45+
final String requested =
46+
configuration.requestedRendererType ??
47+
(FlutterConfiguration.flutterWebAutoDetect ? 'auto' : 'html');
48+
printWarning(
49+
'The HTML Renderer is being deprecated. Stop using the "$requested" renderer mode.'
50+
'\nSee: https://docs.flutter.dev/to/web-html-renderer-deprecation');
51+
}
52+
return true;
53+
}());
4154
return useCanvasKit ? CanvasKitRenderer() : HtmlRenderer();
4255
}
4356
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:test/bootstrap/browser.dart';
6+
import 'package:test/test.dart';
7+
import 'package:ui/src/engine.dart';
8+
9+
void main() {
10+
internalBootstrapBrowserTest(() => testMain);
11+
}
12+
13+
void testMain() {
14+
final List<String> warnings = <String>[];
15+
late void Function(String) oldPrintWarning;
16+
17+
setUpAll(() async {
18+
oldPrintWarning = printWarning;
19+
printWarning = (String warning) {
20+
warnings.add(warning);
21+
};
22+
});
23+
24+
tearDownAll(() {
25+
printWarning = oldPrintWarning;
26+
});
27+
28+
test('Emit a warning when the HTML Renderer was picked.', () {
29+
final Renderer chosenRenderer = renderer;
30+
31+
expect(chosenRenderer, isA<HtmlRenderer>());
32+
expect(warnings, contains(
33+
contains('See: https://docs.flutter.dev/to/web-html-renderer-deprecation')
34+
));
35+
});
36+
}

0 commit comments

Comments
 (0)