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 reloadExtension for amp-viewer-integration #24730

Merged

Conversation

dreamofabear
Copy link

@dreamofabear dreamofabear commented Sep 25, 2019

Fixes runtime error on pages that use amp-viewer-integration with a mismatched RTV vs. v0.js.

extensions-impl.js:265 Uncaught (in promise) TypeError: Cannot read property 'removeAttribute' of null
    at gn.f.reloadExtension (extensions-impl.js:265)
    at sn (runtime.js:880)
    at pn (runtime.js:207)
    at un (runtime.js:324)
    at wj.kd (amp.js:118)
    at vj (chunk.js:192)
    at rj.Se (chunk.js:420)
    at chunk.js:471

b/141559641

Copy link
Contributor

@jridgewell jridgewell left a 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?

}
// 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
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

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

Oops.

@dreamofabear
Copy link
Author

https://amp.gmail.dev/playground/ is affected by this.

William Chou and others added 2 commits September 26, 2019 09:01
Co-Authored-By: Justin Ridgewell <justin@ridgewell.name>
@rcebulko
Copy link
Contributor

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

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

Copy link
Author

Choose a reason for hiding this comment

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

Two callers:

  • preloadExtension wants includeInserted == true to avoid preloading inserted extensions.
  • reloadExtension wants includeInserted == false to avoid reloading an inserted extension. The throw in this case is WAI.

Copy link
Contributor

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.

Copy link
Author

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. :)

return null;
const selectors = [
`script[${attr}="${extensionId}"]` + modifier,
`script[src*="/${extensionId}-"]` + modifier,
Copy link
Contributor

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.

Copy link
Author

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.

@dreamofabear dreamofabear merged commit d2f7aca into ampproject:master Oct 1, 2019
@dreamofabear dreamofabear deleted the reload-no-attribute-extensions branch October 1, 2019 21:00
':not([i-amphtml-loaded-new-version])' +
(includeInserted ? '' : ':not([i-amphtml-inserted])');
return this.win.document.head./*OK*/ querySelector(
`script[src*="/${extensionId}-"]` + modifier
Copy link
Contributor

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.

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

Successfully merging this pull request may close these issues.

5 participants