amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

setState not working on slideChange of carousel inside amp-render

Open gskaushal92 opened this issue 5 years ago • 10 comments

Description

I am trying to setstate on slide change inside amp-render. But it is not reflecting.

Reproduction Steps

  1. I am loading data inside amp-carousel using amp-render.
  2. I am binding setState on carousel slide change
  3. It is not working.

is this is a known issue. or is there any workaround.

Relevant Logs

No response

Browser(s) Affected

No response

OS(s) Affected

No response

Device(s) Affected

No response

AMP Version Affected

No response

gskaushal92 avatar Jul 31 '21 13:07 gskaushal92

Anybody has any update on this?

gskaushal92 avatar Aug 02 '21 06:08 gskaushal92

any update on this issue?

gskaushal92 avatar Aug 03 '21 05:08 gskaushal92

@caroqliu setState is not working inside amp-render. Is this known issue?

gskaushal92 avatar Aug 04 '21 05:08 gskaushal92

@dmanek Can you take a look at this? I've created a minimal sample in the playground here of what I understand of the issue.

Here is what I'm observing:

  • amp-render renders the amp-carousel from the data. There is an on action to setState given the onSlideChange event.
  • Advance on the carousel. You'll notice that nothing changes on the document. This is because the console displays the following error:
    Uncaught (in promise) Error: AMP-BIND is not installed.​​​
      at eb (VM229 v0.js:2)
      at Db.g.assert (VM229 v0.js:2)
      at K (VM229 v0.js:2)
      at VM229 v0.js:5
    
  • installing amp-bind on the document causes the amp-carousel not to render (?)

caroqliu avatar Aug 04 '21 15:08 caroqliu

If I move the binding inside template then amp-carousel will render. But again on slide Change setState will not be set. <amp-render id="my-component" src="https://amp.dev/static/inline-examples/data/amp-list-data.json" height="300"> <template type="amp-mustache"> <p> Carousel state: <span [text]="currentSlide">null</span> </p> <amp-carousel type="slides" height="300" on="slideChange:AMP.setState({currentSlide: event.index})"> {{#items}} <amp-img src="{{imageUrl}}" layout="flex-item"></amp-img> {{/items}} </amp-carousel> </template> </amp-render>

gskaushal92 avatar Aug 05 '21 04:08 gskaushal92

@caroqliu So I hope this is a known issue and will be taken care by your team?

gskaushal92 avatar Aug 05 '21 04:08 gskaushal92

@gskaushal92 thanks for reporting this issue. Will investigate and update when I have more.

dmanek avatar Aug 05 '21 04:08 dmanek

@dmanek any idea when can we get the fix for this issue?

gskaushal92 avatar Aug 10 '21 06:08 gskaushal92

@gskaushal92 I have the PR out for review. Once it's merged, it should be on rolled out in ~2 weeks.

dmanek avatar Aug 10 '21 16:08 dmanek

Closing this issue since it's been fixed by PR #35449.

This issue is caused due to amp-img within amp-carousel having display: flex causing it not to display since the container div's height is 0. In PR #35449 we preserve the wrapper element which allows amp-img to have height > 0.

dmanek avatar Aug 13 '21 18:08 dmanek