Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/web_ui/lib/src/engine/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions lib/web_ui/lib/src/engine/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ abstract class Renderer {
useCanvasKit = FlutterConfiguration.useSkia;
}

// Warn users in development that anything other than canvaskit is deprecated.
assert(() {
if (!useCanvasKit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this trigger if you pick auto but are debugging in desktop Chrome (I imagine it's the most common case)? I think we want if (['html', 'auto'].contains(configuration.requestedRendererType)).

Copy link
Member Author

@ditman ditman Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we hit this if, we know that the HTMLRenderer is going to be chosen, this is only trying to reconstruct why.

I think the only corner case that this won't pick up at runtime is if the user has set --web-renderer=auto but then used renderer: canvaskit in their load() call.

That's why we need a tool change in flutter build as well.

Copy link
Contributor

@yjbanov yjbanov Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the value of useCanvasKit when you do --web-renderer=auto and test in desktop Chrome?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the value of useCanvasKit when you do --web-renderer=auto and test in desktop Chrome?

true (as expected, no?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could've done:

if (FlutterConfiguration.flutterWebAutoDetect || !useCanvasKit) {

to capture all cases we want to warn against.

// 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();
}
}
Expand Down
36 changes: 36 additions & 0 deletions lib/web_ui/test/html/deprecation_test.dart
Original file line number Diff line number Diff line change
@@ -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<String> warnings = <String>[];
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<HtmlRenderer>());
expect(warnings, contains(
contains('See: https://docs.flutter.dev/to/web-html-renderer-deprecation')
));
});
}