Skip to content

Commit 6602df4

Browse files
authored
Revert "[web] Fix url updates when using Router (flutter#24798)" (flutter#24870)
Seeing many web tests fail with errors like: ``` 00:07 +0 -11: test/cupertino/search_field_test.dart: clear button removes text ══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════ The following message was thrown: Could not navigate to initial route. The requested route name was: "/default" There was no corresponding route in the app, and therefore the initial route specified will be ignored and "/" will be used instead. ════════════════════════════════════════════════════════════════════════════════════════════════════ 00:07 +0 -12: test/cupertino/search_field_test.dart: clear button removes text [E] Test failed. See exception logs above. The test description was: clear button removes text ``` This reverts commit 510d2ab.
1 parent 49c1b7d commit 6602df4

File tree

2 files changed

+7
-68
lines changed

2 files changed

+7
-68
lines changed

lib/web_ui/lib/src/engine/window.dart

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,13 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
4444
/// button, etc.
4545
@visibleForTesting
4646
BrowserHistory get browserHistory {
47-
return _browserHistory ??=
48-
MultiEntriesBrowserHistory(urlStrategy: _urlStrategyForInitialization);
49-
}
50-
51-
UrlStrategy? get _urlStrategyForInitialization {
5247
final UrlStrategy? urlStrategy = _isUrlStrategySet
5348
? _customUrlStrategy
5449
: _createDefaultUrlStrategy();
5550
// Prevent any further customization of URL strategy.
5651
_isUrlStrategySet = true;
57-
return urlStrategy;
52+
return _browserHistory ??=
53+
MultiEntriesBrowserHistory(urlStrategy: urlStrategy);
5854
}
5955

6056
BrowserHistory? _browserHistory;
@@ -63,29 +59,17 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
6359
if (_browserHistory is SingleEntryBrowserHistory) {
6460
return;
6561
}
66-
67-
final UrlStrategy? strategy;
68-
if (_browserHistory == null) {
69-
strategy = _urlStrategyForInitialization;
70-
} else {
71-
strategy = _browserHistory?.urlStrategy;
72-
await _browserHistory?.tearDown();
73-
}
62+
final UrlStrategy? strategy = _browserHistory?.urlStrategy;
63+
await _browserHistory?.tearDown();
7464
_browserHistory = SingleEntryBrowserHistory(urlStrategy: strategy);
7565
}
7666

7767
Future<void> _useMultiEntryBrowserHistory() async {
7868
if (_browserHistory is MultiEntriesBrowserHistory) {
7969
return;
8070
}
81-
82-
final UrlStrategy? strategy;
83-
if (_browserHistory == null) {
84-
strategy = _urlStrategyForInitialization;
85-
} else {
86-
strategy = _browserHistory?.urlStrategy;
87-
await _browserHistory?.tearDown();
88-
}
71+
final UrlStrategy? strategy = _browserHistory?.urlStrategy;
72+
await _browserHistory?.tearDown();
8973
_browserHistory = MultiEntriesBrowserHistory(urlStrategy: strategy);
9074
}
9175

@@ -277,7 +261,7 @@ external set _jsSetUrlStrategy(_JsSetUrlStrategy? newJsSetUrlStrategy);
277261

278262
UrlStrategy? _createDefaultUrlStrategy() {
279263
return ui.debugEmulateFlutterTesterEnvironment
280-
? TestUrlStrategy.fromEntry(TestHistoryEntry('default', null, '/default'))
264+
? null
281265
: const HashUrlStrategy();
282266
}
283267

lib/web_ui/test/window_test.dart

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -128,51 +128,6 @@ void testMain() {
128128
expect(window.browserHistory.urlStrategy.getPath(), '/baz');
129129
});
130130

131-
test('initialize browser history with default url strategy (single)', () async {
132-
// On purpose, we don't initialize history on the window. We want to let the
133-
// window to self-initialize when it receives a navigation message.
134-
135-
Completer<void> callback = Completer<void>();
136-
window.sendPlatformMessage(
137-
'flutter/navigation',
138-
JSONMethodCodec().encodeMethodCall(MethodCall(
139-
'routeUpdated',
140-
<String, dynamic>{'routeName': '/bar'},
141-
)),
142-
(_) { callback.complete(); },
143-
);
144-
await callback.future;
145-
expect(window.browserHistory is SingleEntryBrowserHistory, true);
146-
// The url strategy should've been set to the default, and the path
147-
// should've been correctly set to "/bar".
148-
expect(window.browserHistory.urlStrategy, isNot(isNull));
149-
expect(window.browserHistory.urlStrategy.getPath(), '/bar');
150-
}, skip: browserEngine == BrowserEngine.webkit); // https://github.com/flutter/flutter/issues/50836
151-
152-
test('initialize browser history with default url strategy (multiple)', () async {
153-
// On purpose, we don't initialize history on the window. We want to let the
154-
// window to self-initialize when it receives a navigation message.
155-
156-
Completer<void> callback = Completer<void>();
157-
window.sendPlatformMessage(
158-
'flutter/navigation',
159-
JSONMethodCodec().encodeMethodCall(MethodCall(
160-
'routeInformationUpdated',
161-
<String, dynamic>{
162-
'location': '/baz',
163-
'state': null,
164-
},
165-
)),
166-
(_) { callback.complete(); },
167-
);
168-
await callback.future;
169-
expect(window.browserHistory is MultiEntriesBrowserHistory, true);
170-
// The url strategy should've been set to the default, and the path
171-
// should've been correctly set to "/baz".
172-
expect(window.browserHistory.urlStrategy, isNot(isNull));
173-
expect(window.browserHistory.urlStrategy.getPath(), '/baz');
174-
}, skip: browserEngine == BrowserEngine.webkit); // https://github.com/flutter/flutter/issues/50836
175-
176131
test('can disable location strategy', () async {
177132
// Disable URL strategy.
178133
expect(() => jsSetUrlStrategy(null), returnsNormally);

0 commit comments

Comments
 (0)