馃悰 Warn for amp-list[layout=container] without placeholder #32769
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
amp-list
withlayout=container
type should have aplaceholder
to function correctly. This PR knocks down the assertion to a warning, so that the element can continue building and laying out even if this requirement is not met. This is not harmful in a way that is end-user visible but can potentially lead to network requests on build for non-compliant usage forms, hence warning.Additional Info
We originally required it so that the element is expected to have some initial height, and would not pop up out of no where on layout. But in fact, if there is no placeholder, diffable placeholder, or children otherwise (more on this in a bit), the
amp-list
will have a height of0
and the runtime will not lay it out anyway. So there is already logic in place to ensure the user will provide placeholders for their component to work.Finally - on the other children. This is not a standard way to use amp-list but it is AMP valid to do so, so it would be prudent to plan for this scenario I think. I tried out a few cases (placeholder & extra children nodes & template, and different subsets of these) with amp-list and it seems to behave reasonably given the unconventional use:
amp-list
creates, so other direct children of theamp-list
are ignored during these operationslayout=container
case, we still measure initial height and ability to resize, and since the container element foramp-list
elements gets appended after all user-provided markup, the user will not see even see a portion of that content unless there is a placeholder taking up space to replaceIn particular, if you have
<amp-list layout="container" ...></amp-list>
or:If I recall correctly, these are the main cases we had wanted to guard against (no placeholders) and they are not behaving visibly harmfully on the page with the assertion removed. The only cost is that both are built (potentially performing a network request), and the one with children (non-0 height) lays out which is potentially more costly to append that content, but again, the end user would not see it without a placeholder to replace. I think that is a reasonable situation to warn rather than error, and doing so should mitigate the user-visible errors you described in the original bug report when the component fails to find the placeholder.
Fixes b/178971515
cc/ @dmanek