-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix tabs deeplink history to work with back button within page #9674
Conversation
@ahebrank and @xhezairi you have both worked in this code recently, can you review this PR? Thanks |
dom-serializer@0, dom-serializer@~0.1.0: | ||
version "0.1.0" | ||
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.0.tgz#073c697546ce0780ce23be4a28e293e40bc30c82" | ||
dom-serializer@0, dom-serializer@~0.0.0: |
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.
We should update yarn time to time, but not in this PR.
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.
Good point, incidental, will fix.
@@ -365,6 +371,7 @@ class Tabs { | |||
} | |||
} | |||
|
|||
$(window).off('popstate', this._checkDeepLink); |
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.
No check for this.options.deepLink
?
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.
we can, but shouldn't matter. If the handler isn't there it's a noop
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 think we should explicitly show that a piece of code is only required by an option.
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.
One year later: that was a stupid idea.
Options can changes, listeners can be created in complex tests, remplaced, created dynamically. Here we only want to clear everything. No need for that check.
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.
True. So do we need further changes here?
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.
No, don't worry. I seen that while working on #11077
@@ -114,9 +93,32 @@ class Tabs { | |||
} | |||
} | |||
|
|||
this._checkDeepLink = this._checkDeepLink.bind(this); |
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.
Why ?
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.
So that we can
- Count on
this
within the function being a reference to the plugin - have a single representation of the function (rather than doing bind at the time we add the handler), letting us remove it using
off
Thanks, haven't been eating my dogfood and didn't see this glitch. Two minor armchair things:
So, at L96:
The only other thing I'm wondering is if the popstate event should check
|
@ahebrank can you clarify a little what you meant by anonymizing it? The reason I set it up this way was to be able to remove explicitly this handler on destroy, so as not to have to mess with other handlers... That said, maybe we should implement a global popstate handler similar to how we handle resize/scroll. Thoughts @coreysyms? |
@kball, here's a diff that should clarify: fix-tabs-history...ahebrank:fix-tabs-history |
Righto, makes sense. Will push up an update later today. Thanks @ahebrank |
the updateHistory got a little problem in _handleTabChange if it get's handled by the deeplink check it shouldn't pushState again. |
@designerno1 @ahebrank @ncoden Updated to address all of the concerns raised, please take another look thanks |
looks good to me |
@@ -297,7 +304,7 @@ class Tabs { | |||
* @param {jQuery | String} elem - jQuery object or string of the id of the pane to display. | |||
* @function |
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.
@@ -206,7 +213,7 @@ class Tabs { | |||
* @fires Tabs#change |
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.
- @param {boolean} - browser has already handled a history update
Needs a comment for the new function parameter, but otherwise thumbs up. |
Fix tabs deeplink history to work with back button within page
I noticed while working on a lesson on tabs deep linking that the history feature was a little flaky - while it added the history to the URL, clicking back did not appropriately open the previous tab. This fixes this bug by moving the deep link logic into a function and calling it on popstate.