-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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 reloadExtension for amp-viewer-integration #24730
Fix reloadExtension for amp-viewer-integration #24730
Conversation
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.
Who is loading the viewer without using explicit RTVs for all scripts?
src/service/extensions-impl.js
Outdated
} | ||
// Some extensions don't have an attribute e.g. amp-viewer-integration. | ||
const elements = head./*OK*/ querySelectorAll( | ||
'script:not([custom-template]):not([custom-element])' + modifier |
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 could probably change this to `script[src*="/${extensionId}-"]`
to immediately find the script with the query selector.
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.
Something IE supports for once.
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.
Oops.
https://amp.gmail.dev/playground/ is affected by this. |
Co-Authored-By: Justin Ridgewell <justin@ridgewell.name>
The owners check issue is a known bug fixed in ampproject/amp-github-apps#477 , which is pending review. The bugfix should be rolled out in the next day or two. |
// Always ignore <script> elements that have a mismatched RTV. | ||
const modifier = | ||
':not([i-amphtml-loaded-new-version])' + | ||
(includeInserted ? '' : ':not([i-amphtml-inserted])'); |
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 don't understand why includeInserted
is necessary. The only caller is reloadExtension
? Is it trying to guard against a second call? (It won't work, the second call is guaranteed to throw because of this logic).
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.
Two callers:
preloadExtension
wantsincludeInserted == true
to avoid preloading inserted extensions.reloadExtension
wantsincludeInserted == false
to avoid reloading an inserted extension. The throw in this case is WAI.
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.
If we were to never add the :not([i-amphtml-inserted])
, what effectively changes? I think both cases will continue to work.
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 ask the person who added it. #24402 😋 Might want to keep and fix though, since we delete the extension holder on the second call and I'm not sure that's okay.
Anyways this is tangential since this PR preserves status quo. So we (you) can fix it later. :)
src/service/extensions-impl.js
Outdated
return null; | ||
const selectors = [ | ||
`script[${attr}="${extensionId}"]` + modifier, | ||
`script[src*="/${extensionId}-"]` + modifier, |
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.
If we want to, we can use this as the only query.
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.
Yea that's probably fine.
':not([i-amphtml-loaded-new-version])' + | ||
(includeInserted ? '' : ':not([i-amphtml-inserted])'); | ||
return this.win.document.head./*OK*/ querySelector( | ||
`script[src*="/${extensionId}-"]` + modifier |
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.
This regex is too wide. E.g. it catches both: amp-subscriptions
and amp-subscriptions-google
. I'll try to go back and use an exact attribute match.
Fixes runtime error on pages that use
amp-viewer-integration
with a mismatched RTV vs. v0.js.b/141559641