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

Fix i-amphtml-sizer responsive issue #1319

Conversation

ediamin
Copy link
Contributor

@ediamin ediamin commented Apr 18, 2022

Fixes #1314

This PR fixes the responsive issue of the i-amphtml-sizer generated by the SSR when we have a heights attribute.

@ediamin ediamin changed the title Remove inline padding-top from responsive sizer Fix i-amphtml-sizer responsive issue Apr 18, 2022
Comment on lines 9 to 15
<i-amphtml-sizer slot="i-amphtml-svc" style="display:block;padding-top:100%"></i-amphtml-sizer>
<i-amphtml-sizer slot="i-amphtml-svc" style="display:block"></i-amphtml-sizer>
</amp-img>
<amp-img id="customId" height="100" width="100" layout="responsive" src="img2.png" class="i-amphtml-layout-responsive i-amphtml-layout-size-defined" i-amphtml-layout="responsive">
<i-amphtml-sizer slot="i-amphtml-svc" style="display:block;padding-top:100%"></i-amphtml-sizer>
<i-amphtml-sizer slot="i-amphtml-svc" style="display:block"></i-amphtml-sizer>
</amp-img>
<amp-img height="100" width="100" layout="responsive" src="img3.png" class="i-amphtml-layout-responsive i-amphtml-layout-size-defined" i-amphtml-layout="responsive" id="i-amp-1">
<i-amphtml-sizer slot="i-amphtml-svc" style="display:block;padding-top:100%"></i-amphtml-sizer>
<i-amphtml-sizer slot="i-amphtml-svc" style="display:block"></i-amphtml-sizer>
Copy link
Member

Choose a reason for hiding this comment

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

The elements in input.html do not have heights attributes. Is this change properly being limited to when heights is present?

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 amphtml source I've found when the padding-top is being set. I've update the code and now padding-top will set when heights attribute is missing.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see there in static-layout.js where the presence of the heights attribute determines whether padding-top is added. Maybe when the heights attribute is processed by the runtime, the padding-top later is removed/overridden? This appears so:

https://github.com/ampproject/amphtml/blob/160dcd9c93d34bb7da073a1240c287fc0cf14591/src/custom-element.js#L1068-L1078

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the confusion. I wanted to say the same. Yes, you're right. applyStaticLayout creates the sizer element first, then adds the padding-top based on the height and width attributes. Later it gets overridden if the heights attribute is present.

Copy link
Collaborator

@sebastianbenz sebastianbenz left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for fixing! One nit.

packages/optimizer/lib/transformers/ApplyLayout.js Outdated Show resolved Hide resolved
Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

LGTM

@sebastianbenz sebastianbenz merged commit 1abaa6b into ampproject:main Apr 19, 2022
@sebastianbenz
Copy link
Collaborator

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Responsive issue of i-amphtml-sizer created by the ServerSideRendering
3 participants