@@ -13,7 +13,6 @@ import 'package:js/js.dart';
13
13
import 'package:meta/meta.dart' ;
14
14
import 'package:ui/ui.dart' as ui;
15
15
16
- import '../engine.dart' show registerHotRestartListener;
17
16
import 'browser_detection.dart' ;
18
17
import 'navigation/history.dart' ;
19
18
import 'navigation/js_url_strategy.dart' ;
@@ -50,12 +49,8 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
50
49
engineDispatcher.windows[_windowId] = this ;
51
50
engineDispatcher.windowConfigurations[_windowId] = const ui.ViewConfiguration ();
52
51
if (_isUrlStrategySet) {
53
- _browserHistory =
54
- MultiEntriesBrowserHistory (urlStrategy: _customUrlStrategy);
52
+ _browserHistory = createHistoryForExistingState (_customUrlStrategy);
55
53
}
56
- registerHotRestartListener (() {
57
- window.resetHistory ();
58
- });
59
54
}
60
55
61
56
final Object _windowId;
@@ -67,7 +62,7 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
67
62
/// button, etc.
68
63
BrowserHistory get browserHistory {
69
64
return _browserHistory ?? =
70
- MultiEntriesBrowserHistory (urlStrategy : _urlStrategyForInitialization);
65
+ createHistoryForExistingState ( _urlStrategyForInitialization);
71
66
}
72
67
73
68
UrlStrategy ? get _urlStrategyForInitialization {
@@ -82,32 +77,50 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
82
77
_browserHistory; // Must be either SingleEntryBrowserHistory or MultiEntriesBrowserHistory.
83
78
84
79
Future <void > _useSingleEntryBrowserHistory () async {
80
+ // Recreate the browser history mode that's appropriate for the existing
81
+ // history state.
82
+ //
83
+ // If it happens to be a single-entry one, then there's nothing further to do.
84
+ //
85
+ // But if it's a multi-entry one, it will be torn down below and replaced
86
+ // with a single-entry history.
87
+ //
88
+ // See: https://github.com/flutter/flutter/issues/79241
89
+ _browserHistory ?? =
90
+ createHistoryForExistingState (_urlStrategyForInitialization);
91
+
85
92
if (_browserHistory is SingleEntryBrowserHistory ) {
86
93
return ;
87
94
}
88
95
89
- final UrlStrategy ? strategy;
90
- if (_browserHistory == null ) {
91
- strategy = _urlStrategyForInitialization;
92
- } else {
93
- strategy = _browserHistory? .urlStrategy;
94
- await _browserHistory? .tearDown ();
95
- }
96
+ // At this point, we know that `_browserHistory` is a non-null
97
+ // `MultiEntriesBrowserHistory` instance.
98
+ final UrlStrategy ? strategy = _browserHistory? .urlStrategy;
99
+ await _browserHistory? .tearDown ();
96
100
_browserHistory = SingleEntryBrowserHistory (urlStrategy: strategy);
97
101
}
98
102
99
103
Future <void > _useMultiEntryBrowserHistory () async {
104
+ // Recreate the browser history mode that's appropriate for the existing
105
+ // history state.
106
+ //
107
+ // If it happens to be a multi-entry one, then there's nothing further to do.
108
+ //
109
+ // But if it's a single-entry one, it will be torn down below and replaced
110
+ // with a multi-entry history.
111
+ //
112
+ // See: https://github.com/flutter/flutter/issues/79241
113
+ _browserHistory ?? =
114
+ createHistoryForExistingState (_urlStrategyForInitialization);
115
+
100
116
if (_browserHistory is MultiEntriesBrowserHistory ) {
101
117
return ;
102
118
}
103
119
104
- final UrlStrategy ? strategy;
105
- if (_browserHistory == null ) {
106
- strategy = _urlStrategyForInitialization;
107
- } else {
108
- strategy = _browserHistory? .urlStrategy;
109
- await _browserHistory? .tearDown ();
110
- }
120
+ // At this point, we know that `_browserHistory` is a non-null
121
+ // `SingleEntryBrowserHistory` instance.
122
+ final UrlStrategy ? strategy = _browserHistory? .urlStrategy;
123
+ await _browserHistory? .tearDown ();
111
124
_browserHistory = MultiEntriesBrowserHistory (urlStrategy: strategy);
112
125
}
113
126
0 commit comments