-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Makes the back button work across tensorboard index (/) landing page #970
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
Conversation
This allows the back button to work when you navigate to the index (/) URL.
I've followed the instructions here https://github.com/tensorflow/tensorboard/blob/master/DEVELOPMENT.md to verify this fix works locally. |
Thanks for this contribution! I'll take a look shortly. |
Let user know which tags are missing per run (tensorflow#967)
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.
I verified that this works as intended. When a user visits TensorBoard from a different web page, clicking back reverts to that web page. When a user switches dashboards, clicking back reverts to the previous dashboard.
Just have 1 nit.
window.location.hash = component; | ||
if (useLocationReplace) { | ||
window.location.replace(window.location.origin + window.location.pathname + '#' + component); | ||
} else { |
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.
nit: After pathname
, could you concatenate window.location.search
?
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.
Actually, you can just do: window.location.replace('#' + component);
Any preceding parts of the replacement URL not given will resolve against the current URL, including the query string. This is the same reason why you can use <a href="#top">Go to Top</a>
and similar things inline in a page.
window.location.hash = component; | ||
if (useLocationReplace) { | ||
window.location.replace(window.location.origin + window.location.pathname + '#' + component); | ||
} else { |
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.
Actually, you can just do: window.location.replace('#' + component);
Any preceding parts of the replacement URL not given will resolve against the current URL, including the query string. This is the same reason why you can use <a href="#top">Go to Top</a>
and similar things inline in a page.
@@ -592,6 +592,7 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.” | |||
if (activeDashboards && selectedDashboard == null) { | |||
selectedDashboard = activeDashboards[0] || null; | |||
if (selectedDashboard != null) { | |||
tf_storage.setString(tf_storage.TAB, selectedDashboard, /*useLocalStorage=*/false, /*useLocationReplace=*/true); |
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.
Could you add a comment that explains why we're using location.replace here, i.e. to ensure that navigating back doesn't result in a loop? Also maybe note that the call to tf_storage.setString() in this case will supersede the one that will be invoked by _selectedDashboardChanged() once we update _selectedDashboard below.
Also, this line is a bit long, can you wrap it e.g. to
tf_storage.setString(
tf_storage.TAB,
selectedDashboard,
/*useLocalStorage=*/false,
/*useLocationReplace=*/true);
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.
HTML files should follow 100 char limit.
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.
LGTM. Please note actionable items in other comments.
@@ -592,6 +592,7 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.” | |||
if (activeDashboards && selectedDashboard == null) { | |||
selectedDashboard = activeDashboards[0] || null; | |||
if (selectedDashboard != null) { | |||
tf_storage.setString(tf_storage.TAB, selectedDashboard, /*useLocalStorage=*/false, /*useLocationReplace=*/true); |
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.
HTML files should follow 100 char limit.
Not sure I totally understand the github workflow, I've made changes & committed them to my branch. Now what? |
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.
LGTM, thanks again for fixing this!
Yep, you just make changes, commit to your branch, and push and they show up here for us to take another look.
@@ -592,6 +592,11 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.” | |||
if (activeDashboards && selectedDashboard == null) { | |||
selectedDashboard = activeDashboards[0] || null; | |||
if (selectedDashboard != null) { | |||
// Use location.replace for this call to avoid breaking back-button navigation. | |||
// Note that this will precede the update to tf_storage triggered by updating | |||
// _selectedDashboard. |
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.
nit: maybe just add "... and make it a no-op" to the end of this comment for maximum clarity.
Currently, if you come in via link to a tensorboard page on /, a plugin hash will immediately get appended (/#scalars). No amount of back button clicking will get you back to the linking page because the history item for / will get you immediately js-redirected back to /#scalars (or whatever).
This pull request allows us to specify that the storage state set call should be history-replacing (i.e. use 'window.location.replace(...)' instead of 'window.location.hash ='. Now when you link into a tensorboard server, you will be able to navigate back!