Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

JS error "swiper.a11y is undefined" when destroying swiper after click in slide #6223

Closed
6 tasks done
digitas-git opened this issue Nov 17, 2022 · 1 comment · Fixed by #6226
Closed
6 tasks done

Comments

@digitas-git
Copy link

Check that this is really a bug

  • I confirm

Reproduction link

no reproduction link

Bug description

I hope this description will show the problem I'm having difficulties to create a codesandbox.

In my vue project including the swiper (core, not vue) I have the problem getting an error message since v8.4.3 when clicking on a linked element in a slide:
Uncaught TypeError: swiper.a11y is undefined in a11y.js:195

I have to use the method beforeDestroy() to call swiper.destroy(deleteInstance, cleanStyles) with cleanStyles=false. But if the swiper is destroyed, swiper.a11y.clicked can't be set to false, because it is undefined after destruction.

As a workaround I am setting swiper.a11y = {} after calling swiper.destroy(deleteInstance, cleanStyles).

I suggest adding a check if swiper.destroyed is not true in src/modules/a11y/a11y.js:

const handlePointerUp = () => {
  requestAnimationFrame(() => {
    requestAnimationFrame(() => {
      if (!swiper.destroyed)
      swiper.a11y.clicked = false;
    });
  });
};

Expected Behavior

No javascript error when swiper is destroyed after clicking a link within a slide.

Actual Behavior

Receiving error message in console after clicking a link within a slide and destroying the swiper:
Uncaught TypeError: swiper.a11y is undefined in a11y.js:195

Swiper version

8.4.3

Platform/Target and Browser Versions

Windows Chrome 107

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
@ScorpAL
Copy link
Contributor

ScorpAL commented Nov 17, 2022

Same happened for react version

React 18
Swiper 8.4.4
Chrome Version 107

Receiving error message in console after clicking a link within a slide and destroying the swiper:

Uncaught TypeError: Cannot set properties of undefined (setting 'clicked')
at a11y.js:195:21

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants