-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[web] Freeze window.defaultRouteName #15565
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,8 +99,10 @@ class EngineWindow extends ui.Window { | |
/// Simulates clicking the browser's back button. | ||
Future<void> webOnlyBack() => _browserHistory.back(); | ||
|
||
String _defaultRouteName; | ||
|
||
@override | ||
String get defaultRouteName => _browserHistory.currentPath; | ||
String get defaultRouteName => _defaultRouteName ??= _browserHistory.currentPath; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be frozen on construction, or when the browser window opens rather than on first access? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to delay the initialization of But once the app gets the value of the default route name, it shouldn't change after that. |
||
|
||
/// Change the strategy to use for handling browser history location. | ||
/// Setting this member will automatically update [_browserHistory]. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:test/test.dart'; | ||
import 'package:ui/src/engine.dart'; | ||
|
||
TestLocationStrategy _strategy; | ||
TestLocationStrategy get strategy => _strategy; | ||
set strategy(TestLocationStrategy newStrategy) { | ||
window.locationStrategy = _strategy = newStrategy; | ||
} | ||
|
||
void main() { | ||
test('window.defaultRouteName should not change', () { | ||
strategy = TestLocationStrategy.fromEntry(TestHistoryEntry('initial state', null, '/initial')); | ||
expect(window.defaultRouteName, '/initial'); | ||
|
||
strategy.replaceState(null, null, '/newpath'); | ||
expect(window.defaultRouteName, '/initial'); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a while to realize (found the
??=
in the code) that this is lazy-initialized and cached route name. I think a comment would be useful.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.