Skip to content
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 retethering issue when anchor refs are removed #95

Merged
merged 4 commits into from
Feb 5, 2016

Conversation

geoffdaigle
Copy link
Contributor

@zackbloom

I am working on a hubspot app that has a very dynamic, multi-page onboarding flow. The problem happens after the user finishes a flow and then decides to start it over. This situation might apply more broadly as well.

Current behavior (attaches to 0,0)

tether-problem-shepherd

Fixed behavior (attaches to element)

tether-problem-shepherd-fixed

The issue comes from the fact that the user options opts.element reference is overwritten when setting the element reference using document.getQuerySelector and stays in memory. Unless the steps are explicitly removed and added again (which, in practice, is not intuitive) the elements are never relieved of their reference and thus will always re-attach to the historical first reference that has no presence on the page.

(Additionally, a deep extend would have worked nicely here but it seems like that doesn't happen in Tether utils). Nevermind that doesn't apply here

if (typeof selector === 'string') {
opts.element = document.querySelector(selector);
returnOpts.on = opts.on;
if (opts.offset !== 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opts.offset really ends up the string 'undefined'? That doesn't seem right (not saying your code is wrong, saying if that's the case, it should probably be fixed).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh good eye, i meant typeof here

returnOpts.on = opts.on;
if (typeof opts.offset !== 'undefined') {
returnOpts.offset = opts.offset;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just do returnOpts = extend({}, opts)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - I got this confused with something else, it's only a single level of props so i wouldn't need deep copy anyway.

@geoffdaigle
Copy link
Contributor Author

@zackbloom anything else need tweaking before this is merged?

@marcneuwirth
Copy link

👍

@geoffdaigle
Copy link
Contributor Author

@zackbloom im going to merge this

geoffdaigle added a commit that referenced this pull request Feb 5, 2016
Fix retethering issue when anchor refs are removed
@geoffdaigle geoffdaigle merged commit 010665c into shipshapecode:master Feb 5, 2016
@timmfin
Copy link
Contributor

timmfin commented Feb 5, 2016

Publishing as 1.6.0 shortly...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants