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
Experimentally enable layout=container on <amp-list> #27911
Conversation
Hey @ampproject/wg-caching, these files were changed:
|
extensions/amp-list/amp-list.md
Outdated
@@ -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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this 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!
extensions/amp-list/amp-list.md
Outdated
@@ -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. |
There was a problem hiding this comment.
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?
extensions/amp-list/amp-list.md
Outdated
[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. |
There was a problem hiding this comment.
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?
extensions/amp-list/amp-list.md
Outdated
`<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. | ||
|
There was a problem hiding this comment.
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"
?
There was a problem hiding this 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. :)
@@ -191,6 +222,12 @@ export class AmpList extends AMP.BaseElement { | |||
); | |||
|
|||
this.loadMoreEnabled_ = this.element.hasAttribute('load-more'); | |||
userAssert( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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 :/
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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
Oh, we should probably remove the documentation changes until it's widely available. I'd consider only dark launching this for email until V2. |
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. |
Changes in discussion no longer present in this PR
Just went through the examples on deploy bot and it LGTM |
extensions/amp-list/0.1/amp-list.js
Outdated
* (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 |
There was a problem hiding this comment.
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.
I used Charles Proxy to test B&H on both #26873 (should be broken), and this branch.
|
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 😄 🎉 |
* 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
Allows an
amp-list
to be initialized withlayout=container
by default for AMP4Email or with the experimental flagamp-list-layout-container
for other formats.PR Deploy Bot Demos:
examples/amp-list.amp.html
examples/amp-list-layout-container.amp.html
amp-list-layout-container
experiment enabled.TODO:
Documentation changes regarding the experimental featureRelated to #26873 b/152928375 cc @zhangsu