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

repeating destroy and init calls triggering the error Uncaught (in promise) TypeError: Cannot convert undefined or null to object #2004

Open
studentIvan opened this issue Dec 19, 2022 · 1 comment
Labels

Comments

@studentIvan
Copy link

studentIvan commented Dec 19, 2022

Source code:

import PhotoSwipeLightbox from 'https://unpkg.com/photoswipe/dist/photoswipe-lightbox.esm.js';

const lightbox = new PhotoSwipeLightbox({
  gallery: '#my-gallery',
  children: 'a',
  pswpModule: () => import('https://unpkg.com/photoswipe'),
});

lightbox.init();
lightbox.destroy();
lightbox.init();
lightbox.destroy();
lightbox.init();
lightbox.destroy();
lightbox.init();

(Object.keys(this._listeners)).forEach((name) => {

this._listeners is null in this case.

Playground what reproduces the bug:
https://codepen.io/tranquility/pen/ExpxEGB

Try to open any image and check the developer console
image

p.s.: Who faced with this problem on some dynamic data - use dataSource attribute instead of gallery and children combination. Use pswpLightbox.loadAndOpen(index) for opening the image.

@dimsemenov dimsemenov added the Bug label Dec 30, 2022
@dimsemenov
Copy link
Owner

The script isn't designed to be used after it's destroyed, but I can see how it can be an issue. Will try to improve docs/errors.

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

No branches or pull requests

2 participants