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

✨Manual management of amp-next-page document visibility #25388

Merged
merged 17 commits into from
Nov 8, 2019

Conversation

wassgha
Copy link
Contributor

@wassgha wassgha commented Nov 3, 2019

Closes #25069 , Partial for #15807 & #14059

Changes

  • Patches amp-next-page v0.1 (the change will land in v0.2) to allow it to override document visibility for the added shadow docs, fixing interactions with amp-pixel and possibly amp-analytics (previously all added "next" documents would be given the "visible" state even during pre-rendering which would immediately trigger an amp-pixel hit before the user reaches the next page).
  • Adds partial testing (most tests will come after e2e testing is implemented, see Add e2e tests for amp-next-page #24610 )
  • Cleans up tests
  • Adds a new type ShadowDoc which defines the Shadow document object (already generated by the AMP runtime but typed as Object)

Implementation details

Previous to this change, shadow docs appended by amp-next-page would follow their parent's visibility state which in most cases would be visible as the user is scrolling down the page. This causes multiple problems during the time between the pre-render phase (user is scrolling and the next page is loaded) and the visible phase (the user scrolled to the next page and is reading it).

One of the problems that have surfaced is the interaction with amp-pixel where the analytics call is gated by the document's visibility state. In this case, as the next page has been loaded (and thus adopts its parent's visible state), the amp-pixel triggers preemptively, before the user actually scrolls to the next page.

This change corrects the behavior by having amp-next-page manually override the visibility state of the next pages as follows:

  • Give documents an initial visibility state of PRERENDER (as opposed to the parent's visibility state)
  • As the user scrolls, switch the current page they are reading to be VISIBLE while other documents (excluding the host/first document) are either in the PRERENDER or HIDDEN states
  • Follow the parent's state when HIDDEN, PAUSED or INACTIVE but restore the previous states when the parent/first document becomes VISIBLE

visbility

Todo

  • Add tests (some will come at a later PR for e2e)
  • Maintain behavior after the parent's visibility state changes
  • Maintain the PRERENDER visibility state when scrolling back

/cc @nainar @kristoferbaxter

@wassgha wassgha marked this pull request as ready for review November 5, 2019 00:21
@wassgha wassgha requested review from sparhami, alanorozco and dvoytenko and removed request for alanorozco November 5, 2019 00:25
extensions/amp-next-page/0.1/next-page-service.js Outdated Show resolved Hide resolved
extensions/amp-next-page/0.1/next-page-service.js Outdated Show resolved Hide resolved
extensions/amp-next-page/0.1/next-page-service.js Outdated Show resolved Hide resolved
extensions/amp-next-page/0.1/next-page-service.js Outdated Show resolved Hide resolved
extensions/amp-next-page/0.1/next-page-service.js Outdated Show resolved Hide resolved
src/runtime.js Outdated Show resolved Hide resolved
extensions/amp-next-page/0.1/next-page-service.js Outdated Show resolved Hide resolved
@dvoytenko
Copy link
Contributor

@wassgha qq:

Patches amp-next-page v0.1 (the change will land in v0.2)

Can you clarify this? Are we bumping version? Is this component really launched?

@wassgha
Copy link
Contributor Author

wassgha commented Nov 6, 2019

@dvdyakonov let's talk about versioning offline but here's the (very incomplete) design doc https://docs.google.com/document/d/1x-TD4qWr3hWm2BzqUfrv4hHJyTJ4HBb6H3EcJUDDmyY/edit

@wassgha wassgha requested a review from sparhami November 6, 2019 22:59
@dvoytenko
Copy link
Contributor

@wassgha qq:

Patches amp-next-page v0.1 (the change will land in v0.2)

Can you clarify this? Are we bumping version? Is this component really launched?

Ping on this question.

@wassgha wassgha merged commit 325b0ce into ampproject:master Nov 8, 2019
@wassgha wassgha deleted the amp-next-page-refactor branch November 8, 2019 21:18
micajuine-ho pushed a commit to micajuine-ho/amphtml that referenced this pull request Dec 27, 2019
…#25388)

* Manual management of document visibility

* Edge cases and tests

* Fixed types

* Requested changes

* Fixed types

* Removed unnecessary cast

* Switched to using refs instead of indices

* Fixed non-nullable type

* Manual management of document visibility

* Edge cases and tests

* Fixed types

* Requested changes

* Fixed types

* Removed unnecessary cast

* Switched to using refs instead of indices

* Fixed non-nullable type
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.

Next Page pageview GA event fired in <amp-pixel> while using with <amp-next-page>
4 participants