Skip to content

Prevent PWA bugs due to A4A's getCorrelator()#16233

Merged
dreamofabear merged 4 commits intoampproject:masterfrom
dreamofabear:pwa-ads-bug
Jun 22, 2018
Merged

Prevent PWA bugs due to A4A's getCorrelator()#16233
dreamofabear merged 4 commits intoampproject:masterfrom
dreamofabear:pwa-ads-bug

Conversation

@dreamofabear
Copy link
Copy Markdown

I think this fixes #16043.

The root problem is that getServiceForDoc(window.document) doesn't work in PWAs. This is because it relies on AmpDocService#getAmpDoc(node) which traverses up node's parents to find the service holder. However, in shadow AMP services live on the shadow root, which is a child of the document. So traversing up the document will fail to find the shadow root.

Instead, non-window service getters should always be passed the AMP element itself (or a nearby node), e.g. getServiceForDoc(myAmpElement). We have a long-standing initiative to refactor and improve this but it hasn't been prioritized yet (go/amp-roots).

/to @keithwrightbos For code review.
/to @danielrozenberg Can you try patching this into your local repro setup?

William Chou added 2 commits June 21, 2018 19:02
Copy link
Copy Markdown
Contributor

@keithwrightbos keithwrightbos left a comment

Choose a reason for hiding this comment

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

Ideally we would have some functional test that loads an amp-ad within a shadow root

@dreamofabear
Copy link
Copy Markdown
Author

Ideally we would have some functional test that loads an amp-ad within a shadow root

You can use describes.realWin with "shadow" config for that. Here's an example from amp-bind:

describes.realWin('in shadow ampdoc', {
amp: {
ampdoc: 'shadow',
runtimeOn: false,
},

@danielrozenberg
Copy link
Copy Markdown
Member

My local setup doesn't reproduce the error because of the localhost-specific logic, so patching this locally won't help diagnose the problem :(

@dreamofabear
Copy link
Copy Markdown
Author

Ah ok, I thought the experiment was the cause of the local repro failure. Keith just removed that entire code path so I think the bug will be fixed either way.

@dreamofabear dreamofabear merged commit 6f6b8d5 into ampproject:master Jun 22, 2018
@dreamofabear dreamofabear deleted the pwa-ads-bug branch June 22, 2018 17:33
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.

"Ampdoc for shell has not been installed" in shadow document

4 participants