You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the virtual module in Swiper React, as the user moves to a new slide, all the slides are updated, which creates a performance issue when somewhat complex slides are used. The reason is that the virtual module always assigns keys to the slide starting from 0.
For example, say initially slides A - C are rendered. Currently, Swiper will render something akin to this:
Then React will be able to detect that slides with keys 1 and 2 have the same content. If slide was a memo'ed component it would not be re-rendered.
The key used in virtual DOM is added in here, and based on the history it was added to fix an issue with loop and virtual slides. If we simply removed this line, it should fix the above problem but probably create a regression on the linked bug.
Thanks for looking at the issue.
Expected Behavior
When a slide moves around, it should not necessitate an update on it. The React key should be stable for the same virtual slide content. It may be seen by the counter each in slide shown in the reproduction link. The counter should not increase for all visible slides every time the user moves the slide.
Actual Behavior
All the slides are updated every time the set of visible slides changes. Namely, an instantiated slide (with a specific key) will change from one slide content to another. It may be seen by the counter each in slide shown in the reproduction link. The counter increases for all visible slides every time a new slide becomes visible.
Check that this is really a bug
Reproduction link
https://codesandbox.io/p/devbox/swiper-react-virtual-slides-86n5ny?file=%2Fsrc%2FApp.jsx%3A55%2C27
Bug description
When using the virtual module in Swiper React, as the user moves to a new slide, all the slides are updated, which creates a performance issue when somewhat complex slides are used. The reason is that the virtual module always assigns
key
s to the slide starting from 0.For example, say initially slides A - C are rendered. Currently, Swiper will render something akin to this:
Suppose the user swipes the slides and now slides B - D are rendered. Then Swiper will render:
Due to how React's virtual DOM works, it will re-render the all three slides with each one's new content. A more efficient way would be to render:
Then React will be able to detect that slides with keys 1 and 2 have the same content. If
slide
was a memo'ed component it would not be re-rendered.The
key
used in virtual DOM is added in here, and based on the history it was added to fix an issue with loop and virtual slides. If we simply removed this line, it should fix the above problem but probably create a regression on the linked bug.Thanks for looking at the issue.
Expected Behavior
When a slide moves around, it should not necessitate an update on it. The React
key
should be stable for the same virtual slide content. It may be seen by the counter each in slide shown in the reproduction link. The counter should not increase for all visible slides every time the user moves the slide.Actual Behavior
All the slides are updated every time the set of visible slides changes. Namely, an instantiated slide (with a specific
key
) will change from one slide content to another. It may be seen by the counter each in slide shown in the reproduction link. The counter increases for all visible slides every time a new slide becomes visible.Swiper version
11.0.6
Platform/Target and Browser Versions
macOS / Firefox 121.0.1
Validations
Would you like to open a PR for this bug?
The text was updated successfully, but these errors were encountered: