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

♻️ amp-next-page v2 host page visibility + minor refactor #26778

Merged
merged 19 commits into from
Apr 9, 2020

Conversation

wassgha
Copy link
Contributor

@wassgha wassgha commented Feb 12, 2020

Closes #27635
Closes #26628

Changes

  • Adds logic for handling visibility of host page (fixes an issue with updating the page's URL)
  • Refactors logic for scroll direction and visibility updates into the visibility observer
  • Adds some minor changes coming from the deprecated ✨ Adds scroll-bound page transitions to <amp-next-page> v2 #26628
  • Fixes race condition where duplicate pages can be added on slow connections

@wassgha wassgha requested a review from alanorozco February 13, 2020 07:45
@wassgha wassgha marked this pull request as ready for review February 13, 2020 07:45
@wassgha
Copy link
Contributor Author

wassgha commented Feb 26, 2020

@alanorozco ping on this

extensions/amp-next-page/1.0/page.js Show resolved Hide resolved
extensions/amp-next-page/1.0/page.js Show resolved Hide resolved
extensions/amp-next-page/1.0/service.js Outdated Show resolved Hide resolved
extensions/amp-next-page/1.0/service.js Outdated Show resolved Hide resolved
extensions/amp-next-page/1.0/service.js Outdated Show resolved Hide resolved
extensions/amp-next-page/1.0/visibility-observer.js Outdated Show resolved Hide resolved
extensions/amp-next-page/1.0/visibility-observer.js Outdated Show resolved Hide resolved
extensions/amp-next-page/1.0/visibility-observer.js Outdated Show resolved Hide resolved
extensions/amp-next-page/1.0/visibility-observer.js Outdated Show resolved Hide resolved
@wassgha wassgha requested a review from alanorozco February 28, 2020 06:22
Copy link
Member

@alanorozco alanorozco left a comment

Choose a reason for hiding this comment

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

Questions about state flow. It looks like there are more shared concepts now, and I'm wondering if they need to be.

Could you specify the intention for each specific new object, and when they communicate?

extensions/amp-next-page/1.0/page.js Show resolved Hide resolved
extensions/amp-next-page/1.0/page.js Show resolved Hide resolved
extensions/amp-next-page/1.0/service.js Outdated Show resolved Hide resolved
extensions/amp-next-page/1.0/visibility-observer.js Outdated Show resolved Hide resolved
extensions/amp-next-page/1.0/visibility-observer.js Outdated Show resolved Hide resolved
* @param {!VisibilityObserverEntry} entry
* @return {?ViewportRelativePos}
*/
getRelativePosFromSentinel(entry) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused about state flow.

Why is the concept of sentinels spilling to this level? Should this be localized only when you need a sentinel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sentinel is actually the general case, the host page is a special case because we don't want to inject sentinel elements into the body of the document so we rely on the amp-next-page element position for calculations

@wassgha
Copy link
Contributor Author

wassgha commented Apr 8, 2020

Added @jridgewell to review the minor dom.js change

@wassgha wassgha requested a review from alanorozco April 8, 2020 10:27
@wassgha wassgha force-pushed the amp-next-page-host-visibility branch from a54d716 to d8e3603 Compare April 8, 2020 10:51
extensions/amp-consent/0.1/consent-ui.js Outdated Show resolved Hide resolved
@@ -224,6 +219,7 @@ export class Page {
if (
this.state_ === PageState.INSERTED ||
this.state_ === PageState.FETCHING ||
this.state_ === PageState.LOADED ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading, it seems like they were allowed to refetch after it was loaded, and we're disallowing that now. Was it intentionally done before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was unintentionally forgotten. We don't want a refetch during loading because it can cause duplicate insertion. After the LOADED state, it would either be FAILED or INSERTED and that's when we'd want to refetch or not.

extensions/amp-next-page/1.0/visibility-observer.js Outdated Show resolved Hide resolved
@@ -156,8 +169,106 @@ export default class VisibilityObserver {
constructor(ampdoc) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Dima is working on a IntersectionObserver polyfill, which will make InOb available everywhere. Can this be easily extended to InObs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it has the same InsersectionObserver behavior then no. The issue is when the element is bigger than the viewport, the IntersectionObserver stops serving updates whereas here we need to still be updated, hence this polyfill.

@wassgha wassgha requested a review from jridgewell April 9, 2020 00:33
@wassgha wassgha merged commit fd0e374 into ampproject:master Apr 9, 2020
metarag pushed a commit to metarag/amphtml that referenced this pull request Apr 9, 2020
…ct#26778)

* Added scroll-bound animation to amp-next-page

* Smoother animation

* Fix issue with tests

* Type checking fix

* Type checking fix

* Refactor visibility observer and adds visibility observing for the host page

* Reverted changes from old PR

* Second refactor

* Fixed tests

* Suggested changes

* Requested changes + title fixes

* Added missing check

* Review feedback
@seomaz
Copy link

seomaz commented Apr 10, 2020

@wassgha when these changes are live?

@sach185
Copy link

sach185 commented Aug 19, 2020

@wassgha are these changes live?

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-next-page URL doesn't update correctly when scrolling
7 participants