Swiper + React SSR: watchOverflow Hydration Behavior
0 reputation · 02 Jun 2024, 01:30 UTC
Goal
Assess whether enabling Swiper's watchOverflow option in a React component rendered with server‑side rendering causes the overflow detection logic to execute twice during client‑side hydration, potentially producing inconsistent slide visibility.
Context
When a Swiper instance is created on the server and re‑hydrated on the client, the library’s internal watchOverflow flag may trigger its overflow check both during server render and after hydration, unless the instance is destroyed and recreated. The interaction with React’s lifecycle (e.g., useEffect cleanup) and Swiper’s module system is not fully documented, leaving uncertainty about the exact conditions that lead to duplicate checks.
- Does the overflow check run twice when
watchOverflowis enabled and the Swiper instance is not destroyed before hydration? - What is the minimal cleanup pattern (e.g., destroying the instance in
useEffect) that prevents duplicate overflow checks without breaking slide initialization? - Are there any documented Swiper or React‑Swiper guidelines that specify whether
watchOverflowshould be disabled in SSR environments?