fix(react): support SwiperSlider components wrapped in higher order components and fix nested fragments bug #4144
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Support
SwiperSlide
components wrapped in higher order components and fix a nested fragments bugThis change does several things:
SwiperSlide
componentsSwiperSlide
components when they're wrapped by a HOC by middlewareFor example, this slider only has 2 slides:
This slider might not work at all:
The reason for this is that I'm trying to help someone who is trying to build a an editor UI for Swiper in a CMS, but the recommended workaround given here is impossible.
I traced the introduction of the code in question to the addition of virtual slides in v6 alpha 4 but could not find any reason for the requirement other than that without it the code could not detect the slide. It appears to be a technical limitation. This PR corrects that by introducing proper recursion while preserving the requirement that the slide be used.
While investigating I also uncovered the Fragment bug. The checking of the component name also means that components that just return
SwiperSlide
components perhaps for organisational purposes no longer work.This also prevents libraries such as slot fills from working with Swiper. For example a React application may provide a Slot inside a Swiper library, then use a Fill elsewhere to insert an additional
SwiperSlide
component.