From e2b6520742686d7831a249adc55a0c57f0133242 Mon Sep 17 00:00:00 2001 From: David Iglesias Date: Mon, 7 Oct 2024 17:16:23 -0700 Subject: [PATCH] [web] Warn users when picking a deprecated renderer. (flutter/engine#55709) Warn users when they pick a deprecated renderer for the web, and point them to the appropriate /go/ link. ## Issues * Part of https://github.com/flutter/flutter/issues/145954 * Fixes https://github.com/flutter/flutter/issues/154879 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../web_ui/lib/src/engine/configuration.dart | 6 ++-- .../lib/web_ui/lib/src/engine/renderer.dart | 13 +++++++ .../web_ui/test/html/deprecation_test.dart | 36 +++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 engine/src/flutter/lib/web_ui/test/html/deprecation_test.dart diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/configuration.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/configuration.dart index 33235af14c..edf168f3bb 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/configuration.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/configuration.dart @@ -167,7 +167,7 @@ class FlutterConfiguration { /// Auto detect which rendering backend to use. /// - /// Using flutter tools option "--web-render=auto" or not specifying one + /// Using flutter tools option "--web-renderer=auto" or not specifying one /// would set the value to true. Otherwise, it would be false. static const bool flutterWebAutoDetect = bool.fromEnvironment('FLUTTER_WEB_AUTO_DETECT', defaultValue: true); @@ -177,10 +177,10 @@ class FlutterConfiguration { /// Enable the Skia-based rendering backend. /// - /// Using flutter tools option "--web-render=canvaskit" would set the value to + /// Using flutter tools option "--web-renderer=canvaskit" would set the value to /// true. /// - /// Using flutter tools option "--web-render=html" would set the value to false. + /// Using flutter tools option "--web-renderer=html" would set the value to false. static const bool useSkia = bool.fromEnvironment('FLUTTER_WEB_USE_SKIA'); // Runtime parameters. diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/renderer.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/renderer.dart index df2c9eeff7..e0c3a59d63 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/renderer.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/renderer.dart @@ -38,6 +38,19 @@ abstract class Renderer { useCanvasKit = FlutterConfiguration.useSkia; } + // Warn users in development that anything other than canvaskit is deprecated. + assert(() { + if (!useCanvasKit) { + // The user requested 'html' or 'auto' either in the command-line or JS. + final String requested = + configuration.requestedRendererType ?? + (FlutterConfiguration.flutterWebAutoDetect ? 'auto' : 'html'); + printWarning( + 'The HTML Renderer is being deprecated. Stop using the "$requested" renderer mode.' + '\nSee: https://docs.flutter.dev/to/web-html-renderer-deprecation'); + } + return true; + }()); return useCanvasKit ? CanvasKitRenderer() : HtmlRenderer(); } } diff --git a/engine/src/flutter/lib/web_ui/test/html/deprecation_test.dart b/engine/src/flutter/lib/web_ui/test/html/deprecation_test.dart new file mode 100644 index 0000000000..f89e5a4d3a --- /dev/null +++ b/engine/src/flutter/lib/web_ui/test/html/deprecation_test.dart @@ -0,0 +1,36 @@ +// Copyright 2013 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 'package:test/bootstrap/browser.dart'; +import 'package:test/test.dart'; +import 'package:ui/src/engine.dart'; + +void main() { + internalBootstrapBrowserTest(() => testMain); +} + +void testMain() { + final List warnings = []; + late void Function(String) oldPrintWarning; + + setUpAll(() async { + oldPrintWarning = printWarning; + printWarning = (String warning) { + warnings.add(warning); + }; + }); + + tearDownAll(() { + printWarning = oldPrintWarning; + }); + + test('Emit a warning when the HTML Renderer was picked.', () { + final Renderer chosenRenderer = renderer; + + expect(chosenRenderer, isA()); + expect(warnings, contains( + contains('See: https://docs.flutter.dev/to/web-html-renderer-deprecation') + )); + }); +}