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

Already on GitHub? Sign in to your account

Using Swiper in Nuxt3 causes flickering issues. #7693

Open
6 tasks done
luoriwusheng-xia opened this issue Aug 21, 2024 · 8 comments
Open
6 tasks done

Using Swiper in Nuxt3 causes flickering issues. #7693

luoriwusheng-xia opened this issue Aug 21, 2024 · 8 comments
Labels

Comments

@luoriwusheng-xia
Copy link

Check that this is really a bug

  • I confirm

Reproduction link

https://codesandbox.io/p/devbox/nuxt3-swiper-flicker-bug-rxlzms

Bug description

All dependencies and packages are the latest versions. I hope to use Swiper in Nuxt3 with SSR capability, but currently, the images flicker at the moment of loading.

Expected Behavior

When first entering the page, the images flicker, likely because Swiper has not accounted for the remaining space allocated by the parent container.

Actual Behavior

Images do not flicker, and the Swiper container displays normally.

Swiper version

11.1.9

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
@luoriwusheng-xia
Copy link
Author

luoriwusheng-xia commented Aug 21, 2024

[en] : Using client-only in Nuxt3 loses the ability for SSR rendering, which is not SEO-friendly.

[zh-cn]: 在Nuxt3中 使用 client-only 会失去SEO的能力。

@luoriwusheng-xia
Copy link
Author

[en]: I tried loading swiper.min.css separately, but the flickering still occurs. Initially, I thought importing the CSS file via ESM might cause the CSS file to be dynamically inserted into the page through JavaScript, leading to the flickering. However, I found that even when loading the full CSS file separately, the flickering still persists.

[zh-cn]: 我尝试单独加载 swiper.min.css 但是还是会闪烁,我一开始以为是 通过 ESM引入 css文件会导致css文件是通过js动态执行插入到页面,导致的闪烁, 发现单独加载完整的css文件,仍旧闪烁

@luoriwusheng-xia
Copy link
Author

Undesirable effect, The image placeholders are very large.

image


Desired result

image

@vishal-dev-hash
Copy link

The same issue is occurring in Remix as well.
I can create a CodeSandbox demo if needed.

@dijkermans
Copy link

I think you are referring to the content shift that occurs. I solve this issue in the following ways:

Use CSS to define the size of each slide, corresponding to the Swiper breakpoints.

Or:

Use CSS to make the images visible once the slider is initialized.

@Nuzzlet
Copy link

Nuzzlet commented Sep 5, 2024

I think this is a duplicate of: #7577

@dijkermans
Copy link

dijkermans commented Sep 5, 2024

I think you are referring to the content shift that occurs. I solve this issue in the following ways:

Use CSS to define the size of each slide, corresponding to the Swiper breakpoints.

Or:

Use CSS to make the images visible once the slider is initialized.

Example:

breakpoints: {	
	900: {
		slidesPerView: 2.3,
	},	
},
@media only screen and (min-width: 900px) {

	.swiper-slide {

	    width: calc(100% / 2.3);

	}

}

@Nuzzlet
Copy link

Nuzzlet commented Sep 6, 2024

I think you are referring to the content shift that occurs. I solve this issue in the following ways:
Use CSS to define the size of each slide, corresponding to the Swiper breakpoints.
Or:
Use CSS to make the images visible once the slider is initialized.

Example:

breakpoints: {	
	900: {
		slidesPerView: 2.3,
	},	
},
@media only screen and (min-width: 900px) {

 .swiper-slide {

     width: calc(100% / 2.3);

 }

}

Absolutely did not think to try this. I needed a workaround with CSS Var to handle my page margin and handle spaceBetween, but got everything working!

It would be awesome perhaps if I could also just disable or replace the Javascript resizing mechanism of swiper… it seems silly to use both when the CSS performs better anyway. Anyone know of a way to disable it?

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

No branches or pull requests

4 participants