setState not working on slideChange of carousel inside amp-render
Description
I am trying to setstate on slide change inside amp-render. But it is not reflecting.
Reproduction Steps
- I am loading data inside amp-carousel using amp-render.
- I am binding setState on carousel slide change
- 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
Anybody has any update on this?
any update on this issue?
@caroqliu setState is not working inside amp-render. Is this known issue?
@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-renderrenders theamp-carouselfrom the data. There is anonaction tosetStategiven theonSlideChangeevent.- 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-bindon the document causes theamp-carouselnot to render (?)
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>
@caroqliu So I hope this is a known issue and will be taken care by your team?
@gskaushal92 thanks for reporting this issue. Will investigate and update when I have more.
@dmanek any idea when can we get the fix for this issue?
@gskaushal92 I have the PR out for review. Once it's merged, it should be on rolled out in ~2 weeks.
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.