-
Notifications
You must be signed in to change notification settings - Fork 5
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 iframe.js breaking links with hash URLs #1115
Conversation
@@ -13,6 +13,8 @@ webpack-config.js | |||
!config/global_config.json | |||
!config/locale_config.json | |||
!config/index.json | |||
!config/index.ar.json |
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 deleted these pages to speed up the testing loop. When I added them back I noticed they were missing from the gitignore. They were probably being tracked with git add --force
or something similar.
|
||
/** | ||
* Reloads the iframe with a recalculated src URL. | ||
* Does not reload the iframe if the URL has only changed its hash param. |
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 we'd still want regular query params to trigger a reload?
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 don't want to touch the preexisting behavior because we're not sure how it's being used or for what purpose it's there. This code was copy and pasted all at once from the AEB (answers experience builder created by Mcgin) and it doesn't seem possible to track that info down.
Previously, iframe.js would not work with links contains hash URLs, i.e. links like ```html <a id="skip-to-content-link" href="#main-content">Skip to content</a> ``` notice the URL starts with a hashtag. These links are different than normal HTML links, in that instead of redirecting to a new page, they will scroll the browser down to the element with the id matching the link. For the example above, it would scroll down to an element like ```html <div id="main-content">main content!</div> ``` However, iframe.js has an issue where, when one of these links are clicked, the iframe.js will reload and the parent frame's URL will be changed. This issue was caused by the following process: 1. iframe.js's has a window.popstate listener, which reloads the iframe whenever a popstate event was triggered (for instance by clicking on one of these links), 2. clicking a hash link will trigger this listener, reloading the iframe 3. reloading the iframe causes the inner iframe to send messages to the outer frame 4. these messages are received by iframe.js's onMessage listener, which then performs a history.replaceState (for certain types of messages) To avoid this situation, this PR updates the popstate listener to be a no-op if the new URL of the page is the same as the old one, ignoring any hash URLs J=TECHOPS-7401 TEST=manual ran the theme's test site, created a basic iframe implementation before this change, hash urls would have the broken behavior after the change, they would scroll down the page without reloading the iframe or changing the parent's URL
Previously, iframe.js would not work with links contains hash URLs, i.e. links like
notice the URL starts with a hashtag. These links are different than normal HTML links,
in that instead of redirecting to a new page, they will scroll the browser down to the element
with the id matching the link. For the example above, it would scroll down to an element like
However, iframe.js has an issue where, when one of these links are clicked, the iframe.js will reload
and the parent frame's URL will be changed.
This issue was caused by the following process:
whenever a popstate event was triggered (for instance by clicking on one of these links),
To avoid this situation, this PR updates the popstate listener to be a no-op if the new URL of the page is the same as the old one, ignoring any hash URLs
J=TECHOPS-7401
TEST=manual
ran the theme's test site, created a basic iframe implementation
before this change, hash urls would have the broken behavior
after the change, they would scroll down the page without reloading the iframe or changing the parent's URL