amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

AMP Binds not functioning correctly

Open rickbairstow opened this issue 5 years ago • 3 comments

What's the issue?

Adding as a GH issue as per a thread on Slack.

We've encountered an issue where some functionality does not work for amp binds. Specifically on our basket page the binds we attach to our 'Delivery Method' selector and 'Discount Code' box aren't opening the relevant sections. For example clicking the discount code does correctly set the state for basketDiscountCode (toggles true/fals), however the [hidden]="!basketDiscountCode" we use to show the discount input in the DOM doesn't trigger, even though the state seems correct.

  • If I first interact with the 'Delivery To' amp-selector and select a country, then everything else kicks in and works.
  • If I remove the 'Delivery To' completely (before it's rendered in the DOM) then the other aspects will work
  • If I remove either the binded [class] or [hidden] from each button within the 'Delivery To' amp-selector it'll work (see SS below)
  • AMP validates for me and other than an ampdoc issue for analytics (which I've tested disabling) I don't have any console errors with #development=1
    • @sebastianbenz did find a [CustomElement] Cannot resize element and overflow is not available error but I'm not getting that in my console

We have several AMP-only sites all with very similar code but none showing this issue. The example this is an issue on is www.panemirates.com/uae/en, but this site has some near identical fascia sites for different locales that do not have this issue. If you need to compare between them then you'll need to set your locale_prefix cookie to uae%2Fen for the site with the issue, or to ksa%2Fen for a site without the issue (which should take you to www.panemirates/ksa/en).

How do we reproduce the issue?

  1. Go to https://www.panemirates.com/uae/en/pan-beryl-garden-sign-wall-deco-multi-12x12cm-p15447 and add the product to your basket
  2. Go to the basket page at https://www.panemirates.com/uae/en/basket
  3. Try to open the 'Delivery Method' select or the 'Discount Code' toggle on the right side of the page
  4. If you then open the 'Deliver To' select and select a country everything will begin working correctly

What browsers are affected?

All.

Which AMP version is affected?

2103261048002

I'm unsure how long this issue has been present but I suspect it has occurred within the last two months.

rickbairstow avatar Apr 13 '21 08:04 rickbairstow

Could you please share the code snippet where you change the state? It's hard to dig on a production site.

alanorozco avatar Apr 13 '21 16:04 alanorozco

Here's the discount toggle button (minus the SVG code, and non-relevant code from the element it is trying to display), which is a bit of a smaller component and the easier for testing:

<button 
    on="tap: AMP.setState({ basketDiscountCode: !basketDiscountCode }), checkoutList.changeToLayoutContainer()" 
    class="flex items-center my-4 underline py-2 lg:py-0"
    type="button"
>
    <span [hidden]="!basketDiscountCode" hidden>//svg - angle-down</span>
    <span [hidden]="basketDiscountCode">//svg - angle-right</span>
    Got a discount code?
</button>
<div
    class="flex my-4"
    hidden
    [hidden]="!basketDiscountCode"
>
    // Discount content that should show when clicking the above button  
</div>

And here's a snippet of the code we use for the top amp-selector. The buttons here are where removing [class] or [hidden] allows at least some of the functionality to kick back in. The second select (delivery method) runs off the same code, however that one will only set courier state and not deliverTo, and the binds will be relative to that (so courier instead of deliverTo).

<amp-selector
    class="overflow-auto"
    style="max-height: 16rem"
    layout="container"
    keyboard-select-mode="focus"
    on="select: AMP.setState({
        deliverTo: {
            open: false,
            query: '',
            value: event.targetOption.split('|')[0],
            title: event.targetOption.split('|')[1],
            subtitle: event.targetOption.split('|')[2]
        },
        courier: {
            value: '',
            title: '',
            subtitle: ''
        }
    }), checkoutOptions.submit"
>
    {{ #delivery_options }}
        <button
            title="{{ title }}"
            type="button"
            class="text-left px-3 py-2 flex justify-between items-center border-b border-gray-2 w-full hover:bg-gray-1 text-sm truncate"
            [class]="deliverTo.value == '{{ value }}' ? 'bg-brand-1 :hover:bg-brand-1-interact text-brand-1-contrast hover:text-brand-1 text-left px-3 py-2 flex justify-between items-center border-b border-gray-2 w-full text-sm truncate' : 'text-left px-3 py-2 flex justify-between items-center border-b border-gray-2 w-full hover:bg-gray-1 text-sm truncate' "
            option="{{ value }}|{{ title }}|{{ subtitle }}"
            [hidden]='deliverTo.query.length > 0 && cleanString("{{ title }}").indexOf(cleanString(deliverTo.query)) == -1'
            tabindex="0"
        >
            {{ title }}
            {{ #subtitle }}
                <span class="font-bold ml-2">{{ subtitle }}</span>
            {{ /subtitle }}
        </button>
    {{ /delivery_options }}
</amp-selector>

rickbairstow avatar Apr 13 '21 16:04 rickbairstow

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 19 '25 04:07 stale[bot]