Skip to content

Commit

Permalink
🐛 Warn for amp-list[layout=container] without placeholder (#32769)
Browse files Browse the repository at this point in the history
* Warn instead of assert

* Remove test

* Keep assertion for web

* (empty)
  • Loading branch information
caroqliu committed Feb 24, 2021
1 parent d274beb commit 55e618b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
26 changes: 19 additions & 7 deletions extensions/amp-list/0.1/amp-list.js
Expand Up @@ -194,17 +194,29 @@ export class AmpList extends AMP.BaseElement {
isLayoutSupported(layout) {
if (layout === Layout.CONTAINER) {
const doc = this.element.ownerDocument;
const isEmail = doc && isAmp4Email(doc);
const hasPlaceholder =
this.getPlaceholder() ||
(this.element.hasAttribute('diffable') &&
this.queryDiffablePlaceholder_());
if (isEmail) {
if (!hasPlaceholder) {
user().warn(
TAG,
'amp-list[layout=container] should have a placeholder to establish an initial size. ' +
'See https://go.amp.dev/c/amp-list/#placeholder-and-fallback. %s',
this.element
);
}
return (this.enableManagedResizing_ = true);
}
userAssert(
(doc && isAmp4Email(doc)) ||
isExperimentOn(this.win, 'amp-list-layout-container'),
isExperimentOn(this.win, 'amp-list-layout-container'),
'Experiment "amp-list-layout-container" is not turned on.'
);
const hasDiffablePlaceholder =
this.element.hasAttribute('diffable') &&
this.queryDiffablePlaceholder_();
userAssert(
this.getPlaceholder() || hasDiffablePlaceholder,
'amp-list[layout=container] requires a placeholder to establish an initial size. ' +
hasPlaceholder,
'amp-list[layout=container] should have a placeholder to establish an initial size. ' +
'See https://go.amp.dev/c/amp-list/#placeholder-and-fallback. %s',
this.element
);
Expand Down
18 changes: 14 additions & 4 deletions extensions/amp-list/0.1/test/test-amp-list.js
Expand Up @@ -315,11 +315,21 @@ describes.repeated(

it('should require placeholder', () => {
list.getPlaceholder = () => null;
allowConsoleError(() => {
expect(() => list.isLayoutSupported('container')).to.throw(
/amp-list\[layout=container\] requires a placeholder/
if (variant.type === 'experiment') {
allowConsoleError(() => {
expect(() =>
list.isLayoutSupported('container')
).to.throw(
/amp-list\[layout=container\] should have a placeholder/
);
});
} else {
expect(() =>
list.isLayoutSupported('container')
).to.not.throw(
/amp-list\[layout=container\] should have a placeholder/
);
});
}
});

it('should unlock height for layout=container with successful attemptChangeHeight', () => {
Expand Down

0 comments on commit 55e618b

Please sign in to comment.