Skip to content

Conversation

brianwa84
Copy link
Contributor

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!

@brianwa84
Copy link
Contributor Author

I've followed the instructions here https://github.com/tensorflow/tensorboard/blob/master/DEVELOPMENT.md to verify this fix works locally.

@nfelt nfelt self-assigned this Feb 12, 2018
@nfelt nfelt self-requested a review February 12, 2018 22:03
@nfelt
Copy link
Contributor

nfelt commented Feb 12, 2018

Thanks for this contribution! I'll take a look shortly.

Let user know which tags are missing per run (tensorflow#967)
Copy link
Member

@chihuahua chihuahua left a 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 {
Copy link
Member

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?

Copy link
Contributor

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 {
Copy link
Contributor

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);
Copy link
Contributor

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);

Copy link
Contributor

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.

Copy link
Contributor

@jart jart left a 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);
Copy link
Contributor

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.

@brianwa84
Copy link
Contributor Author

Not sure I totally understand the github workflow, I've made changes & committed them to my branch. Now what?

Copy link
Contributor

@nfelt nfelt left a 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.
Copy link
Contributor

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.

@nfelt nfelt merged commit ab0ceb7 into tensorflow:master Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants