Skip to content

Having init="false" leads to layout shifts #7983

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
6 tasks done
krzksz opened this issue May 8, 2025 · 0 comments
Open
6 tasks done

Having init="false" leads to layout shifts #7983

krzksz opened this issue May 8, 2025 · 0 comments

Comments

@krzksz
Copy link

krzksz commented May 8, 2025

Check that this is really a bug

  • I confirm

Reproduction link

https://colorful-grizzled-oboe.glitch.me/

Bug description

I'm working on a website that uses Swiper Element. There are multiple components that wrap it to provide custom options so the init="false" is used in that cases. Because there can be multiple carousels inserted into the HTML at once, I wanted to split their initialisation into separate tasks to not block the main thread for too long.

The issue is that any delay in calling the .initialize() leads to a layout shift. This is caused by the fact that both <swiper-container> and <swiper-slide> call this.attachShadow() in their constructors. It makes the browser hide all of their content until initialize() moves all elements into slots.

Expected Behavior

I would expect the carousel to retain its appearance until the .initialize() function is called, especially when init="false" option is provided.

Actual Behavior

If the <swiper-container> and <swiper-slide> elements are already registered, they will hide their whole content until the .initialize() function is called.

Swiper version

v11.2.6

Platform/Target and Browser Versions

macOS, Chrome

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
  • Make sure this is a Swiper issue and not a framework-specific issue

Would you like to open a PR for this bug?

  • I'm willing to open a PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant