-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Weird behavior of Swiper.js in Next.js 13 & 14 #7577
Comments
Adding the cdn swiper files in document.tsx, helped me resolve this issue: <link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css"
/>
<script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script> |
Nuxt 3 same problem |
same problem |
The flicker appears to stem from Swiper setting each slide's width/height after hydration, but not before on the server. A solution to consider would be swiper offering some way to manually handle element height/width so we can seamlessly preserve the values from the server to the client. |
I use app router from nextjs 14, placed it like this, but it does not solve the problem...
|
I guess you need to use the hijacked script from Next Edit: this is for app router |
I tried, thanks, but it didn't help unfortunately... |
@isrezaei The issue arises because Swiper calculates and assigns each slide's width and margin only after the JavaScript loads. This can cause layout shifts, especially in server-side rendering (SSR) environments where initial styles are applied inconsistently. To prevent this, a workaround could involve pre-setting the slide widths and margins in CSS based on the expected layout, so the layout is more stable before Swiper's JavaScript adjusts the slides. Additionally, if the layout shifts are too significant, consider implementing a custom solution to handle these styles on the server side. |
Do you have any working solution for that? |
Check that this is really a bug
Reproduction link
Bug description
I don't know why I'm experiencing this behavior when I use Swiper in Next.js! Before the initial client-side rendering (SSR mode), I get an unstable Swiper style, as seen in these images. I don't know how to fix this on the first initial mount on every refresh.
Expected Behavior
"I don't want to see the flickering issue at the first refresh. It's not normal."
Actual Behavior
No response
Swiper version
11.1.4
Platform/Target and Browser Versions
chrome lasteat version
Validations
Would you like to open a PR for this bug?
The text was updated successfully, but these errors were encountered: