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

Webp custom content loads JPG on remove() #2037

Open
pierreleripoll opened this issue May 7, 2023 · 2 comments
Open

Webp custom content loads JPG on remove() #2037

pierreleripoll opened this issue May 7, 2023 · 2 comments
Labels

Comments

@pierreleripoll
Copy link

When using webp picture solution as presented here : https://photoswipe.com/custom-content/#using-webp-image-format
You can observe closing photoswipe triggers the loading of jpg image, eg : open the first mountain image, then watch network in dev tools while closing photoswipe, you will see that the jpg version of the image is requested on closing

I managed to resolve the problem my modifying remove() functions in both photoswipe-lightbox.esm.js and photoswipe.esm.js adding this :
if (this.element && this.element.parentNode && !this.pictureElement) { this.element.remove(); } if (this.pictureElement && this.pictureElement.parentNode) { this.pictureElement.remove(); }
in both functions
But this is not the cleanest way to do it I suppose, I know the "real" picture feature is being developed, but until then if some people want to use my dirty fix here it is

@dimsemenov dimsemenov added the Bug label May 7, 2023
@michaelkhabarov
Copy link

Another dirty fix without modifying source files:

    photoswipe.on("destroy", function () {
      this.mainScroll.itemHolders.forEach((itemHolder) => {
        const content = itemHolder.slide?.content
        if (content?.pictureElement) content.element = content.pictureElement
      })
    })

Not sure if this have any side effects

@Dominic-Marcelino
Copy link

Dominic-Marcelino commented Aug 21, 2023

Saving the pictureElement in the contentElement as mentioned by @michaelkhabarov doesn't solves the problem in our project. The destroy/remove action still loads the jpeg version.

Is there any known solution?

UPDATE
Turns out I need to update the contentElement both on destroy and on contentRemove.

lightbox.on('destroy', (e) => {
    lightbox.pswp.mainScroll.itemHolders.forEach((itemHolder) => {
      const content = itemHolder.slide?.content;
      if (content?.pictureElement) {
        content.element = content.pictureElement;
      }
    });
  });
  lightbox.on('contentRemove', (that) => {
    const pictureElement = that.content?.pictureElement;
    if (pictureElement) {
      that.content.element = pictureElement;
    } 
  });

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

4 participants