Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6cc2f9b

Browse files
authored
Revert "[web] Accepts assetBase through JS config. (#40615)" (#40670)
This reverts commit f7d2571. This commit is causing problems with new lint rules: ``` info - test/engine/assets_test.dart:5:1 - This annotation must be attached to a library directive. Try attaching library annotations to library directives. - library_annotations ```
1 parent f7d2571 commit 6cc2f9b

File tree

4 files changed

+21
-211
lines changed

4 files changed

+21
-211
lines changed

lib/web_ui/lib/src/engine/assets.dart

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,26 @@ const Map<String, String> testFontUrls = <String, String>{
2424

2525
/// This class downloads assets over the network.
2626
///
27-
/// Assets are resolved relative to [assetsDir] inside the absolute base
28-
/// specified by [assetBase] (optional).
29-
///
30-
/// By default, URLs are relative to the `<base>` of the current website.
27+
/// The assets are resolved relative to [assetsDir] inside the directory
28+
/// containing the currently executing JS script.
3129
class AssetManager {
32-
/// Initializes [AssetManager] with paths.
33-
AssetManager({
34-
this.assetsDir = _defaultAssetsDir,
35-
String? assetBase,
36-
}) : assert(
37-
assetBase == null || assetBase.endsWith('/'),
38-
'`assetBase` must end with a `/` character.',
39-
),
40-
_assetBase = assetBase;
30+
/// Initializes [AssetManager] with path to assets relative to baseUrl.
31+
const AssetManager({this.assetsDir = _defaultAssetsDir});
4132

4233
static const String _defaultAssetsDir = 'assets';
4334

4435
/// The directory containing the assets.
4536
final String assetsDir;
4637

47-
/// The absolute base URL for assets.
48-
String? _assetBase;
49-
50-
// Cache a value for `_assetBase` so we don't hit the DOM multiple times.
51-
String get _baseUrl => _assetBase ??= _deprecatedAssetBase ?? '';
52-
53-
// Retrieves the `assetBase` value from the DOM.
54-
//
55-
// This warns the user and points them to the new initializeEngine style.
56-
String? get _deprecatedAssetBase {
57-
final DomHTMLMetaElement? meta = domWindow.document
58-
.querySelector('meta[name=assetBase]') as DomHTMLMetaElement?;
59-
60-
final String? fallbackBaseUrl = meta?.content;
61-
62-
if (fallbackBaseUrl != null) {
63-
// Warn users that they're using a deprecated configuration style...
64-
domWindow.console.warn('The `assetBase` meta tag is now deprecated.\n'
65-
'Use engineInitializer.initializeEngine(config) instead.\n'
66-
'See: https://docs.flutter.dev/development/platform-integration/web/initialization');
67-
}
68-
return fallbackBaseUrl;
38+
String? get _baseUrl {
39+
return domWindow.document
40+
.querySelectorAll('meta')
41+
.where((DomElement domNode) => domInstanceOfString(domNode,
42+
'HTMLMetaElement'))
43+
.map((DomElement domNode) => domNode as DomHTMLMetaElement)
44+
.firstWhereOrNull(
45+
(DomHTMLMetaElement element) => element.name == 'assetBase')
46+
?.content;
6947
}
7048

7149
/// Returns the URL to load the asset from, given the asset key.
@@ -89,7 +67,7 @@ class AssetManager {
8967
if (Uri.parse(asset).hasScheme) {
9068
return Uri.encodeFull(asset);
9169
}
92-
return Uri.encodeFull('$_baseUrl$assetsDir/$asset');
70+
return Uri.encodeFull('${_baseUrl ?? ''}$assetsDir/$asset');
9371
}
9472

9573
/// Loads an asset and returns the server response.
@@ -112,7 +90,7 @@ class AssetManager {
11290
}
11391

11492
/// An asset manager that gives fake empty responses for assets.
115-
class WebOnlyMockAssetManager extends AssetManager {
93+
class WebOnlyMockAssetManager implements AssetManager {
11694
/// Mock asset directory relative to base url.
11795
String defaultAssetsDir = '';
11896

@@ -135,6 +113,9 @@ class WebOnlyMockAssetManager extends AssetManager {
135113
@override
136114
String get assetsDir => defaultAssetsDir;
137115

116+
@override
117+
String get _baseUrl => '';
118+
138119
@override
139120
String getAssetUrl(String asset) => asset;
140121

@@ -146,7 +127,7 @@ class WebOnlyMockAssetManager extends AssetManager {
146127
status: 200,
147128
payload: MockHttpFetchPayload(
148129
byteBuffer: _toByteData(utf8.encode(defaultAssetManifest)).buffer,
149-
),
130+
)
150131
);
151132
}
152133
if (asset == getAssetUrl('FontManifest.json')) {
@@ -155,7 +136,7 @@ class WebOnlyMockAssetManager extends AssetManager {
155136
status: 200,
156137
payload: MockHttpFetchPayload(
157138
byteBuffer: _toByteData(utf8.encode(defaultFontManifest)).buffer,
158-
),
139+
)
159140
);
160141
}
161142

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -153,32 +153,6 @@ class FlutterConfiguration {
153153
// runtime. Runtime-supplied values take precedence over environment
154154
// variables.
155155

156-
/// The absolute base URL of the location of the `assets` directory of the app.
157-
///
158-
/// This value is useful when Flutter web assets are deployed to a separate
159-
/// domain (or subdirectory) from which the index.html is served, for example:
160-
///
161-
/// * Application: https://www.my-app.com/
162-
/// * Flutter Assets: https://cdn.example.com/my-app/build-hash/assets/
163-
///
164-
/// The `assetBase` value would be set to:
165-
///
166-
/// * `'https://cdn.example.com/my-app/build-hash/'`
167-
///
168-
/// It is also useful in the case that a Flutter web application is embedded
169-
/// into another web app, in a way that the `<base>` tag of the index.html
170-
/// cannot be set (because it'd break the host app), for example:
171-
///
172-
/// * Application: https://www.my-app.com/
173-
/// * Flutter Assets: https://www.my-app.com/static/companion/flutter/assets/
174-
///
175-
/// The `assetBase` would be set to:
176-
///
177-
/// * `'/static/companion/flutter/'`
178-
///
179-
/// Do not confuse this configuration value with [canvasKitBaseUrl].
180-
String? get assetBase => _configuration?.assetBase;
181-
182156
/// The base URL to use when downloading the CanvasKit script and associated
183157
/// wasm.
184158
///
@@ -288,10 +262,6 @@ external JsFlutterConfiguration? get _jsConfiguration;
288262
class JsFlutterConfiguration {}
289263

290264
extension JsFlutterConfigurationExtension on JsFlutterConfiguration {
291-
@JS('assetBase')
292-
external JSString? get _assetBase;
293-
String? get assetBase => _assetBase?.toDart;
294-
295265
@JS('canvasKitBaseUrl')
296266
external JSString? get _canvasKitBaseUrl;
297267
String? get canvasKitBaseUrl => _canvasKitBaseUrl?.toDart;

lib/web_ui/lib/src/engine/initialization.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ Future<void> initializeEngineServices({
211211
}
212212
};
213213

214-
assetManager ??= AssetManager(assetBase: configuration.assetBase);
214+
assetManager ??= const AssetManager();
215215
_setAssetManager(assetManager);
216216

217217
Future<void> initializeRendererCallback () async => renderer.initialize();

lib/web_ui/test/engine/assets_test.dart

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)