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

Experimentally enable layout=container on <amp-list> #27911

Merged
merged 26 commits into from Apr 29, 2020

Conversation

caroqliu
Copy link
Contributor

@caroqliu caroqliu commented Apr 21, 2020

Allows an amp-list to be initialized with layout=container by default for AMP4Email or with the experimental flag amp-list-layout-container for other formats.

PR Deploy Bot Demos:

TODO:

  • Add validator rules/tests
  • Documentation changes regarding the experimental feature

Related to #26873 b/152928375 cc @zhangsu

extensions/amp-list/0.1/amp-list.js Show resolved Hide resolved
extensions/amp-list/0.1/amp-list.js Show resolved Hide resolved
extensions/amp-list/0.1/amp-list.js Outdated Show resolved Hide resolved
extensions/amp-list/0.1/amp-list.js Outdated Show resolved Hide resolved
extensions/amp-list/0.1/amp-list.js Outdated Show resolved Hide resolved
@amp-owners-bot
Copy link

amp-owners-bot bot commented Apr 24, 2020

Hey @ampproject/wg-caching, these files were changed:

validator/testdata/amp4email_feature_tests/amp_list.html
validator/testdata/amp4email_feature_tests/amp_list.out

@@ -220,6 +220,13 @@ In several cases, we may need the `<amp-list>` to resize on user interaction. Fo
</amp-list>
```

[filter formats="websites, stories"]
The following feature is available with the `amp-list-layout-container` [experiment](https://amp.dev/documentation/guides-and-tutorials/learn/experimental/) enabled.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CrystalOnScript Is there a more appropriate syntactic format to designate an experiment in the documentation? Also as a note, the bit about the feature being experimental only applies to websites and stories.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's no specific syntax, but it may be helpful to give it an alternative heading for websites and stories - maybe just Experimental feature: dynamic resizing. wdyt?

Copy link
Contributor

@CrystalOnScript CrystalOnScript left a comment

Choose a reason for hiding this comment

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

Just have a quick question and a heading suggestion - thanks for looping me in!

@@ -220,6 +220,13 @@ In several cases, we may need the `<amp-list>` to resize on user interaction. Fo
</amp-list>
```

[filter formats="websites, stories"]
The following feature is available with the `amp-list-layout-container` [experiment](https://amp.dev/documentation/guides-and-tutorials/learn/experimental/) enabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no specific syntax, but it may be helpful to give it an alternative heading for websites and stories - maybe just Experimental feature: dynamic resizing. wdyt?

[filter formats="websites, stories"]
The following feature is available with the `amp-list-layout-container` [experiment](https://amp.dev/documentation/guides-and-tutorials/learn/experimental/) enabled.
[/filter]<!-- formats="websites, stories" -->
`<amp-list>` can also be initialized with `layout="CONTAINER"` with two caveats: (1) A list with changing contents must have a determinable initial height from a fixed-height placeholder, and (2) once content changes inside the list, resize will occur _only_ if it does not cause content jumping. This is enforced by locking the height of the list prior to rendering contents and conditionally unlocking it accordingly.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason CONTAINER is all caps? Does it have to be? Does it matter if this value if caps or not?

`<amp-list>` can also be initialized with `layout="CONTAINER"` with two caveats: (1) A list with changing contents must have a determinable initial height from a fixed-height placeholder, and (2) once content changes inside the list, resize will occur _only_ if it does not cause content jumping. This is enforced by locking the height of the list prior to rendering contents and conditionally unlocking it accordingly.

When an `<amp-list>` is initialized with `layout="CONTAINER"`, the publisher is opting into the managed resizing behavior described above. This means that other dynamic resizing mechanisms such as a mutation to `[is-layout-container]` and the `changeToLayoutContainer` action will be ineffective.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you provide a brief explanation on why someone would want amp-list to be initialized with layout="container"?

Copy link

@dreamofabear dreamofabear left a comment

Choose a reason for hiding this comment

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

Looks good overall. Let's run through the manual test/examples just before merge. :)

extensions/amp-list/0.1/amp-list.js Show resolved Hide resolved
@Gregable Gregable added WG: caching WG: Caching: Triaged Initial triage from wg-caching complete. Remove label if new input required. labels Apr 27, 2020
@@ -191,6 +222,12 @@ export class AmpList extends AMP.BaseElement {
);

this.loadMoreEnabled_ = this.element.hasAttribute('load-more');
userAssert(
Copy link
Member

@samouri samouri Apr 27, 2020

Choose a reason for hiding this comment

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

For my own learning: whats the benefit of having the userAssert that load-more and layout=container are incompatible within buildCallback vs. layoutCallback?

nit: On a similar note, can we assume that this invariant is true in later callbacks/methods? For example, within resetIfNecessary_ we double check that !this.loadMoreEnabled_ && this.enableManagedResizing_, but if we gated enabling that flag based on load-more's absence, then we could remove that check from later points.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In regards to why place the assertion in buildCallback as opposed to layoutCallback, in this case the intention was to place it as close as possible to the load-more attribute being read. If we know it's going to cause issues, we might as well error at the earlier possible opportunity so as not to use more resources.

And to go deeper, the reason the load-more attribute is read in the buildCallback is because this is generally where internal state is set in a component instance, including reading attributes.

One might put it in layoutCallback if a critical piece of the assertion is costly, dealing with rendering or loading resources.

Building an AMP Extension is a really helpful resource we have that describes the usage of these callbacks.

re: your other note, yes that's a reasonable assumption for the current state of the code, but I don't think it hurts to be explicit that these are treated as exclusive features, especially if say, in the future, someone else decides to set the internal loadMoreEnabled_ variable without knowing the implicit dependencies here.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for the thorough explanation and links! Its making me realize that I never got around to reading all of our dev-facing docs after skimming them on my first week 😱. I'll read up on it! Something tells me it will make more sense to me now than it did the last time

toggleExperiment(win, 'amp-list-layout-container', false);
});

it('should require placeholder', () => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: feels like there has to be a better way than duplicating all the layout=container tests for amp4email and feature flag cases :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, thanks for catching this! Used describes.repeated() here.

Copy link
Member

Choose a reason for hiding this comment

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

whoa, awesome diff! TIL about describes.repeated, super useful

Copy link
Member

@samouri samouri left a comment

Choose a reason for hiding this comment

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

nice work, its a great feature. had some nits/questions

@dreamofabear
Copy link

Oh, we should probably remove the documentation changes until it's widely available. I'd consider only dark launching this for email until V2.

@caroqliu
Copy link
Contributor Author

Thanks for the thorough review @CrystalOnScript! Looks like we are not adding documentation changes in this PR, but I'll be sure to come back for your comments when we do.

@caroqliu caroqliu dismissed CrystalOnScript’s stale review April 28, 2020 13:29

Changes in discussion no longer present in this PR

@samouri
Copy link
Member

samouri commented Apr 28, 2020

Just went through the examples on deploy bot and it LGTM

* (1) requiring a placeholder to detect initial sizing and
* (2) fixing height on content change to prevent content jumping
*
* TODO: This configuration should eventually allow resizing to
Copy link
Member

Choose a reason for hiding this comment

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

How would the mechanism change here? It would be useful to add an issue describing it.

@samouri
Copy link
Member

samouri commented Apr 28, 2020

I used Charles Proxy to test B&H on both #26873 (should be broken), and this branch.

#26873 #27911 (this branch)
description Could not resize the <amp-list> and displays no text after clicking "Reviews" Works! I'm seeing <amp-bind> warnings as well as an analytics error, but I'm also getting those in production.
screenshot )

@caroqliu
Copy link
Contributor Author

Thanks @samouri for lending a second set of eyes for manual testing on this, and doing it so thoroughly! Also for walking me through how to use the proxy 😄 🎉

@caroqliu caroqliu merged commit 72fbcb0 into ampproject:master Apr 29, 2020
ldoroshe pushed a commit to ldoroshe/amphtml that referenced this pull request May 8, 2020
* Allow layout=container for email or experiment

* Define and use lockHeight/unlockHeight

* Don't apply fill content for layout=container

* Isolate feature from existing APIs

* Return attemptChangeHeight promise

* Move assertions to buildCallback (blocking)

* Add todos, comments, assertions

* Add unit tests

* Add checks for existing unit tests

* Add example markup

* Move TAG in param order

* Will comments

* Make promise thenable

* Will comments

* Modify unit tests to include isLayoutSupported

* Add validator allowance in email and upate tests

* Update documentation on amp-list

* Add assertion in `unlockHeightInsideMutate_`

* Return correct type

* Add layout=container test case

* Assert expect(...).not.called;

* Use describes.repeated()

* Remove documentation changes

* Remove documentation in infinite scroll section

* Link PR in TODO comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes PR use: In Beta / Experimental PR use: In Stable WG: Caching: Triaged Initial triage from wg-caching complete. Remove label if new input required. WG: caching
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants