nolimits4web / swiper

Most modern mobile touch slider with hardware accelerated transitions
https://swiperjs.com
MIT License
39.66k stars 9.75k forks source link

Swiper 9.0.2 + React 18.2.0 in StrictMode - Cannot read properties of undefined (reading 'slideClass') #6342

Closed ScorpAL closed 1 year ago

ScorpAL commented 1 year ago

Check that this is really a bug

Reproduction link

https://codesandbox.io/s/swiper-9-react-strict-issue-c83d98

Bug description

Swiper 9.0.2 + React 18.2.0 in StrictMode

If you set loading='lazy' to image element inside SwiperSlide and set React.StrictMode you will see error message

Uncaught TypeError: Cannot read properties of undefined (reading 'slideClass')
    at slideSelector (process-lazy-preloader.js:2:1)
    at processLazyPreloader (process-lazy-preloader.js:3:1)
    at HTMLImageElement.<anonymous> (core.js:484:1)

https://github.com/nolimits4web/swiper/blob/9fe9a9605e41af36e4c34b8877accf0530830975/src/shared/process-lazy-preloader.js#L2

I know that lazy loading reimplemented in Swiper 9.

Is it possible to avoid execution of processLazyPreloader if developer don't want to use preloader spinners?

Expected Behavior

Native lazy loading working without issues in console in React.StrictMode

Actual Behavior

Errors in console:

Uncaught TypeError: Cannot read properties of undefined (reading 'slideClass')
    at slideSelector (process-lazy-preloader.js:2:1)
    at processLazyPreloader (process-lazy-preloader.js:3:1)
    at HTMLImageElement.<anonymous> (core.js:484:1)

Swiper version

9.0.2

Platform/Target and Browser Versions

Win/Mac, Chrome

Validations

Would you like to open a PR for this bug?

nolimits4web commented 1 year ago

fixed in https://github.com/nolimits4web/swiper/commit/4ea0102cfda0be6de5757381b6c0e2aa2649a4e8