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
3 changes: 3 additions & 0 deletions lib/web_ui/lib/src/engine/initialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ Future<void> initializeEngineUi() async {
RawKeyboard.initialize(onMacOs: ui_web.browser.operatingSystem == ui_web.OperatingSystem.macOs);
KeyboardBinding.initInstance();

// Ensures Flutter renders a global "generator" meta-tag.
ensureMetaTag('generator', 'Flutter');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do this in flutter.js so it's loaded asap?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, just saw your comment:

Added it here, instead of flutter.js so we can have a proper test for the feature.

I think we should add it to flutter.js if it's the more appropriate place for it. For testing, I think we have a couple of flutter.js tests already that we can steal ideas from. Alternatively, we can write an integration test on the flutter/flutter side. We're merging repos soon anyway, so the disadvantages of cross-repo testing will go away.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that flutter.js has the advantage of injecting the meta tag earlier, but I would like us to keep in mind that flutter.js is optional (is this not the case anymore?). So we still need to ensureMetaTag here to guarantee that the tag is always added.

If we want to add the meta tag in the absolute earliest moment, we could add it in index.html. But again, we still need to do it in initializeEngineUi as a backup.


if (!configuration.multiViewEnabled) {
final EngineFlutterWindow implicitView =
ensureImplicitViewInitialized(hostElement: configuration.hostElement);
Expand Down
13 changes: 13 additions & 0 deletions lib/web_ui/lib/src/engine/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,19 @@ void setThemeColor(ui.Color? color) {
}
}

/// Ensure a "meta" tag with [name] and [content] is set on the page.
void ensureMetaTag(String name, String content) {
final DomElement? existingTag =
domDocument.querySelector('meta[name=$name][content=$content]');

if (existingTag == null) {
final DomHTMLMetaElement meta = createDomHTMLMetaElement()
..name = name
..content = content;
domDocument.head!.append(meta);
}
}

bool? _ellipseFeatureDetected;

/// Draws CanvasElement ellipse with fallback.
Expand Down
5 changes: 5 additions & 0 deletions lib/web_ui/test/engine/initialization_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:js/js_util.dart' as js_util;
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart' as engine;
import 'package:ui/src/engine/dom.dart';
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;

@JS('_flutter')
Expand Down Expand Up @@ -76,6 +77,10 @@ void testMain() {
// Check that the object we captured is actually a loader
expect(pluginsRegistered, isTrue, reason: 'Plugins should be immediately registered in autoStart mode.');
expect(appRan, isTrue, reason: 'App should run immediately in autoStart mode');

// After starting the engine, the meta-generator tag should be on the page
final DomElement? meta = domDocument.querySelector('meta[name=generator][content=Flutter]');
expect(meta, isNotNull, reason: 'The generator meta-tag should be added when Flutter initializes its UI.');
});

// We cannot test anymore, because by now the engine has registered some stuff that can't be rewound back.
Expand Down