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

🐛 Use anchor tags outside tooltip for linking #32181

Merged
merged 5 commits into from
Jan 27, 2021

Conversation

mszylkowski
Copy link
Contributor

@mszylkowski mszylkowski commented Jan 25, 2021

Linker cannot access anchor tag from tooltip since it's inside the shadow dom, so we create an anchor outside the shadow root and click it when the tooltip is clicked. Creating the tag and clicking it is considered a trusted user interaction since it's called inside the original click event listener

Demo at https://stories-demos-matias.web.app/examples/amp-story/analytics.html#page=p3. Clicking on the bottom and top links adds the cid to the url

Closes #32060

@mszylkowski mszylkowski self-assigned this Jan 25, 2021
@amp-owners-bot
Copy link

amp-owners-bot bot commented Jan 25, 2021

Hey @gmajoulet, @newmuis, @Enriqe! These files were changed:

extensions/amp-story/1.0/amp-story-embedded-component.js
extensions/amp-story/1.0/utils.js

@newmuis
Copy link
Contributor

newmuis commented Jan 25, 2021

High-level directional question: Is it possible to modify linker to be able to inspect links in shadow roots? The approach in this PR means we have to manually do this for all links in shadow DOM, and seems prone to us missing one somewhere (which, we're already missing some).

@mszylkowski
Copy link
Contributor Author

From the current way of the linker handles clicks, it seems that you'd need to attach a click listener to all the shadow roots, which is not easy because there's no way to know when they are created (or easily target them with CSS). We'd need extra code in the linker and each shadow dom, so it's more complex in the end. If there are other places where this happens, I could fix those in this PR as well

@rsimha rsimha removed the request for review from danielrozenberg January 25, 2021 20:17
@amp-bundle-size amp-bundle-size bot requested a review from rsimha January 25, 2021 20:23
@newmuis
Copy link
Contributor

newmuis commented Jan 25, 2021

☹️ ok

Info dialog, bookend (although deprecated), consent dialog, access (maybe? can't remember), interactive components, and inline page attachment come to mind

@mszylkowski
Copy link
Contributor Author

Oh yeah, looks like it's a number of places where users could potentially use the linker. However, I'd say most of these cases we would (on purpose) prevent linking for privacy reasons or just lack of usefulness (or being deprecated). Enabling linking on specific scenarios might work better than just enabling them on all (and we also avoid more code complexity for now), and we can start adding this functionality where users see a benefit and where we think it's a good use-case. How does that sound?

@rsimha rsimha removed their request for review January 25, 2021 21:22
@newmuis
Copy link
Contributor

newmuis commented Jan 25, 2021

Ok, diving deeper into that list, I think we can skip bookend (because it's deprecated) and access (it doesn't actually have a shadow root, which is surprising to me, but... 🤷‍♂️ )

The others, it seems like we should probably do.

Can you factor out the cloning into a util? Given that it's hacky, I wouldn't be surprised if we find problems with it down the line in some specific device/browser/content combination, and it'd be nice to not have to update every call site.

@rcebulko rcebulko removed their request for review January 25, 2021 22:29
@mszylkowski
Copy link
Contributor Author

Created a function clickAnchorOnDom so you can pass the original anchor and the context you want to use to click it (which will be the parent of the cloned node).

@Enriqe
Copy link
Contributor

Enriqe commented Jan 26, 2021

Could not test linker working properly since the localhost context doesn't trigger it

I think you should be able to test with the demo page you provided, no? It doesn't work there either?

@mszylkowski
Copy link
Contributor Author

Demo now works perfectly, I had to add the "proxyOnly": false to the linker which is not documented on amp.dev (had to find it in the code of linker-manager.js) so it triggers on non-cached sites.

extensions/amp-story/1.0/utils.js Outdated Show resolved Hide resolved
@gmajoulet
Copy link
Contributor

Enrique and Matias, since we do preventDefault() on the actual <a, can you double check the eventual amp-analytics implications? Is there anything we could be breaking?

@mszylkowski
Copy link
Contributor Author

Amp-analytics is triggered at the same time we do this, so they don't seem to clash from what I've seen. If other click events were added to the shadow dom that wanted to catch this click, that could be a problem. But on the analytics side it shouldn't break anything since they don't have access to the shadow dom (which is why this bug occurred)

Copy link
Contributor

@Enriqe Enriqe left a comment

Choose a reason for hiding this comment

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

Enrique and Matias, since we do preventDefault() on the actual <a, can you double check the eventual amp-analytics implications? Is there anything we could be breaking?

Did a quick sanity check and it seems to be working correctly. As Matias mentioned since we're only doing event.preventDefault on the shadow DOM we should be good because the events wouldn't bubble up to light DOM normally.

@mszylkowski
Copy link
Contributor Author

I'll add this functionality into amp-story-consent, info-dialog (from amp-viewer) and page-attachment on a followup PR

@gmajoulet
Copy link
Contributor

page-attachment inline content or link <a are not in a Shadow DOM, it should not need any further fix

@mszylkowski mszylkowski merged commit a69f1d6 into ampproject:master Jan 27, 2021
@mszylkowski mszylkowski deleted the ampstory_linkers branch January 27, 2021 15:47
PetrBlaha pushed a commit to PetrBlaha/amphtml that referenced this pull request Jan 28, 2021
* Create tag from tooltip

* CloneNode

* Move functionality into utils and hide anchor

* Added example and renamed util

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

Successfully merging this pull request may close these issues.

amp-analytics linkers config not working on all web stories links
5 participants