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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 [amp-carousel 0.1] Fix race for setting slideWidth_ #32866

Merged
merged 4 commits into from Feb 25, 2021

Conversation

micajuine-ho
Copy link
Contributor

@micajuine-ho micajuine-ho commented Feb 24, 2021

Closes #32920

There's a race between setting the slidesWidth_ via attachedCallback and using the slidesWidth_ in layoutCallback (expected to be non-zero, initially, in getScrollLeftForIndex_()).

Let's set a flag to see if it's been set and manually set if it hasn't been yet.

@@ -721,7 +721,8 @@ export class AmpSlideScroll extends BaseSlides {
);
return false;
}
showIndexArr.forEach((showIndex, loopIndex) => {

showIndexArr.sort().forEach((showIndex, loopIndex) => {
Copy link
Member

Choose a reason for hiding this comment

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

super nit: I prefer .sort() on its own line instead of chained with forEach. that is because it actually modified the showIndexArr in addition to returning it.

i.e.

showIndexArry.sort();
showIndexArr.forEach(...)

@@ -907,6 +907,19 @@ describes.realWin(
expect(ampSlideScroll.hasAttribute('loop')).to.be.false;
});

it.only('sets the correct scrollLeft for looping carousel', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

rm .only :P

@micajuine-ho micajuine-ho changed the title 馃悰 [amp-carousel 0.1] Fix style.order for looping slides 馃悰 [amp-carousel 0.1] Fix race for setting slideWidth_ Feb 25, 2021
extensions/amp-carousel/0.1/slidescroll.js Outdated Show resolved Hide resolved
Co-authored-by: Caroline Liu <10456171+caroqliu@users.noreply.github.com>
@micajuine-ho micajuine-ho merged commit 25bb462 into ampproject:master Feb 25, 2021
ampprojectbot pushed a commit that referenced this pull request Mar 3, 2021
* init

* fix race

* Update extensions/amp-carousel/0.1/slidescroll.js

Co-authored-by: Caroline Liu <10456171+caroqliu@users.noreply.github.com>

Co-authored-by: Caroline Liu <10456171+caroqliu@users.noreply.github.com>
(cherry picked from commit 25bb462)
ampprojectbot pushed a commit that referenced this pull request Mar 3, 2021
* init

* fix race

* Update extensions/amp-carousel/0.1/slidescroll.js

Co-authored-by: Caroline Liu <10456171+caroqliu@users.noreply.github.com>

Co-authored-by: Caroline Liu <10456171+caroqliu@users.noreply.github.com>
(cherry picked from commit 25bb462)
@D-Kalashnikov
Copy link

Hello. This issue persists in amp-carousel 0.2.
Appears when the page is first loaded on IOS devices.
https://youtu.be/HO30PpYRuyk

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

Successfully merging this pull request may close these issues.

[amp-carousel 0.1] Looping carousel starts on last slide
6 participants