Skip to content

Commit c173e2e

Browse files
authored
Set meta tag in default index (#161493)
The bootstrapping for the DDC module format and library bundle module format contained a preamble to dynamically set the meta tag to ensure the document is parsed as utf-8. This doesn't work as the page has already been parsed at that point. Instead, it should go in the html directly. The meta tag should not affect the AMD module format, as require.js already ensures any loaded scripts are parsed as utf-8. This tag in general is needed to parse this string correctly: https://github.com/dart-lang/sdk/blob/main/sdk/lib/core/uri.dart#L4100 This is a follow-up to PR flutter/flutter#161276. ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing.
1 parent 8ef7b93 commit c173e2e

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

packages/flutter_tools/lib/src/isolated/devfs_web.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ typedef DwdsLauncher =
5050
required ToolConfiguration toolConfiguration,
5151
});
5252

53-
// A minimal index for projects that do not yet support web.
53+
// A minimal index for projects that do not yet support web. A meta tag is used
54+
// to ensure loaded scripts are always parsed as UTF-8.
5455
const String _kDefaultIndex = '''
5556
<html>
5657
<head>
58+
<meta charset='utf-8'>
5759
<base href="/">
5860
</head>
5961
<body>

packages/flutter_tools/lib/src/web/bootstrap.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ import 'package:package_config/package_config.dart';
66

77
/// Used to load prerequisite scripts such as ddc_module_loader.js
88
const String _simpleLoaderScript = r'''
9-
// Declare the character set of the document to align with require.js. Using a
10-
// meta element is preferable to changing the individual script elements'
11-
// `charset` as the scripts should inherit the document's character set, and
12-
// modifying a script element's character set is deprecated.
13-
var meta = document.createElement('meta');
14-
meta.charset = 'utf-8';
15-
document.head.insertBefore(meta, document.head.firstChild);
16-
179
window.$dartCreateScript = (function() {
1810
// Find the nonce value. (Note, this is only computed once.)
1911
var scripts = Array.from(document.getElementsByTagName("script"));

0 commit comments

Comments
 (0)