Skip to content
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

Cannot read properties of undefined (reading 'classList') #6335

Closed
5 of 6 tasks
muuvmuuv opened this issue Feb 3, 2023 · 3 comments
Closed
5 of 6 tasks

Cannot read properties of undefined (reading 'classList') #6335

muuvmuuv opened this issue Feb 3, 2023 · 3 comments

Comments

@muuvmuuv
Copy link

muuvmuuv commented Feb 3, 2023

Check that this is really a bug

  • I confirm

Reproduction link

https://codesandbox.io/s/musing-chaum-tx84zk?file=/src/app/app.component.html

Bug description

I can't reproduce it actually. The code is the same. Just the application arround it is bigger.

The error is that it says above error when using thumbs. I debugged it and can see that it gets the correct Swiper instance but the slides array does not update or update too late.

Expected Behavior

Perhaps a check if the thumbs instance is fully initialized before using instance props

Actual Behavior

thumbs.js:98 Uncaught TypeError: Cannot read properties of undefined (reading 'classList')
    at update (thumbs.js:98:51)
    at Swiper.<anonymous> (thumbs.js:172:5)
    at events-emitter.js:92:24
    at Array.forEach (<anonymous>)
    at events-emitter.js:91:37
    at Array.forEach (<anonymous>)
    at Swiper.emit (events-emitter.js:84:17)
    at resizeHandler (resize.js:13:5)
    at resize.js:35:11

https://github.com/nolimits4web/swiper/blob/master/src/modules/thumbs/thumbs.js#L115

Swiper version

9.x

Platform/Target and Browser Versions

latest macOS

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
  • Make sure this is a Swiper issue and not a framework-specific issue

Would you like to open a PR for this bug?

  • I'm willing to open a PR
@ser-shant
Copy link

ser-shant commented May 17, 2023

keep getting this error in 9.3.2 !!!

thumbs.js:68 Uncaught TypeError: Cannot read properties of undefined (reading 'classList')
at init (thumbs.js:68:1)
at Swiper. (thumbs.js:167:1)
at events-emitter.js:92:1
at Array.forEach ()
at events-emitter.js:91:1
at Array.forEach ()
at Swiper.emit (events-emitter.js:84:1)
at Swiper.init (core.js:459:1)
at mountSwiper (mount-swiper.js:24:1)
at swiper.js:118:1

swiper.thumbs.swiper.el.classList.add(swiper.params.thumbs.thumbsContainerClass);

@Frallen
Copy link

Frallen commented May 24, 2023

Small solution for vue/nuxt developers

Use ref insted useState

I pass the value of swiper directly to ref

<Swiper  @swiper="e=>slider=e" :thumbs="{ swiper: thumbsSwiper }"></Swiper>

//thumbs
<Swiper @swiper="e=>thumbsSwiper=e"></Swiper>

const slider = ref<null>();
let thumbsSwiper = ref<null>();

I didn't need ClientOnly

@ser-shant , @muuvmuuv

@Love-Becca
Copy link

Repository owner deleted a comment from IvanAdmaers Mar 4, 2024
Repository owner locked and limited conversation to collaborators Mar 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants