amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-render stuck at zero height

Open AaronMLB opened this issue 5 years ago • 9 comments

Description

I was fearing I've been trying to do something that is inherently impossible, but having now seen the template attribute validation issue and newness of amp-render generally, I wonder if I may have found a bug? Or both. Or a.n. other.

If it's not a bug and I'm just being an idiot, please feel free to delete/close/whatever this issue!

I have documented my problem at StackOverflow, but in short:

I am unable to render my dl-containing template in the correct position and size, with a variable number of dt/dd pairs to start with (pre-rendered into the page/template by my backend), and which may or may not return any additional data via the amp-render XHR, based on user permissions.

amp-render either renders in the correct position on the page but forces itself to zero height, leaving the content to spill underneath succeeding elements; or renders at a more correct size but absolutely positioned 0,0 in the viewport.

Reproduction Steps

<amp-render src="/api/data-source/1234" credentials="include" xssi-prefix=")]}\*" layout="flex-item"> <template type="amp-mustache"> <dl> <dt>1st item</dt> <dd>Definition</dd> <dt>2nd item</dt> <dd>Definition</dd> {{#isAuthorised}} <dt>3rd item</dt> <dd> <ul> {{#array}} <li>{{name}}</li> {{/array}} </ul> </dd> {{/isAuthorised}} </dl> </template> </amp-render>

Relevant Logs

No response

Browser(s) Affected

No response

OS(s) Affected

No response

Device(s) Affected

No response

AMP Version Affected

No response

AaronMLB avatar Jun 26 '21 14:06 AaronMLB

/cc @dmanek

micajuine-ho avatar Jun 28 '21 14:06 micajuine-ho

Hi @AaronMLB thanks for reporting this. From your description and the thread on stack overflow it seems like your trying to place amp-render in the middle of the page and have the runtime size it correctly, This is not possible as it will cause layout shift.

However, there is another approach you can take in addition to what Jay Gray describes. Once we roll out the resizeToContents actions support (PR #35028) you can use it to resize the <amp-render> component to fit the content on user action if that works for you. This should land in stable in the next ~2 weeks.

dmanek avatar Jun 28 '21 20:06 dmanek

Thanks @dmanek, that's what I feared - but it feels like such a common thing to want to do, I wanted to double check.

The amp-render is indeed in the middle of the page, although sufficiently far enough down that it will be below the fold on all but the most extremely elongated portrait viewport, so I'd hoped maybe there was a calculation to allow the (potential) shift of what is out of view.

Sadly the user action approach wouldn't suffice in this instance - although potentially will in others, so good to know the timeframe for that.

Failing some inspiration with amp-list, I suppose my only remaining course of action will be to redesign my page and/or system - or drop AMP! Again, thanks for your clarification.

AaronMLB avatar Jun 29 '21 11:06 AaronMLB

@AaronMLB perhaps you can try layout="container" once it's rolled out in the next couple of weeks. In the meanwhile, do u have a sample on glitch or jsbin I can take a look at?

dmanek avatar Jun 29 '21 18:06 dmanek

@AaronMLB perhaps you can try layout="container" once it's rolled out in the next couple of weeks. In the meanwhile, do u have a sample on glitch or jsbin I can take a look at?

Thanks @dmanek. I've not used either before so bear with me. Hopefully this is what you need, referring to the 'key details' section in the middle of the page: https://jsbin.com/calalohobo/edit?html,output

The returned JSON would be something like: )]}\*{"isAuthorised":true,"array":[{"urlTag":"page-one","title":"Another Page"}]}

AaronMLB avatar Jun 29 '21 18:06 AaronMLB

@AaronMLB thanks for sample jsbin. layout="container" works in this case when amp-render is below the fold.

dmanek avatar Jun 30 '21 17:06 dmanek

@AaronMLB thanks for sample jsbin. layout="container" works in this case when amp-render is below the fold.

Great! I'll look forward to the rollout. Thanks @dmanek, your time is appreciated.

(As an aside, if it's helpful to anyone of the context of the problem, the site is being being AMP-first and AMP-only, without a regular HTML variant - self-canonical.)

AaronMLB avatar Jun 30 '21 18:06 AaronMLB

@AaronMLB layout="container" is now supported. Please give it a shot & re-open this issue in case you run into any issues.

dmanek avatar Jul 14 '21 21:07 dmanek

Thanks @dmanek. I've not had a chance to try it out in the form I was originally describing, but I am presently getting this error reported on a much simpler straight replacement that does not have such variable height issues:

[CustomElement] Cannot resize element and overflow is not available (reported from log.js line 255)

<amp-render src="/api/auth/header/" layout="container" credentials="include" xssi-prefix=")]}\*" class="i-amphtml-element i-amphtml-layout-container i-amphtml-built i-amphtml-layout" i-amphtml-layout="container" style="--loader-delay-offset:1ms !important; overflow: hidden; height: 40px;" aria-live="polite">
                <div placeholder="" class="amp-hidden">Hello, you!</div>
                <template type="amp-mustache">
                {{{menu}}}
                </template>
            <div i-amphtml-rendered="true" loading="auto" aria-live="polite">
                <ul>
                    <li>
                    <a class="search-button"><i class="far fa-search fa-fw"></i><span class="sr-only">Search</span></a>
                    </li>
                    <li>
                    <a class="account-button"><i class="far fa-user-circle fa-fw"></i></a>
                    </li>
                </ul>
            </div>
</amp-render>

I also now note that the rendering has removed on="tap:..." from the a.search-button element.

AaronMLB avatar Jul 15 '21 15:07 AaronMLB