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

[Bug]: beforeUnmount destroys too soon during Vue transitions #869

Open
4 of 14 tasks
sambedingfield opened this issue May 12, 2024 · 10 comments
Open
4 of 14 tasks

[Bug]: beforeUnmount destroys too soon during Vue transitions #869

sambedingfield opened this issue May 12, 2024 · 10 comments
Assignees
Labels
bug Something isn't working vue Issue is related to Vue

Comments

@sambedingfield
Copy link

Which variants of Embla Carousel are you using?

  • embla-carousel (Core)
  • embla-carousel-react
  • embla-carousel-vue
  • embla-carousel-svelte
  • embla-carousel-autoplay
  • embla-carousel-auto-scroll
  • embla-carousel-solid
  • embla-carousel-auto-height
  • embla-carousel-class-names
  • embla-carousel-docs (Documentation)
  • embla-carousel-docs (Generator)

Steps to reproduce

The bug occurs when I transition away a Vue component containing an Embla carousel, causing it to be destroyed too early. This causes a flicker of an unstyled carousel during the transition.

For a common example, imagine a transition on an app route and clicking a link from within a carousel slide.
The user sees the destroyed state of the carousel before the page transitions away.

Expected Behavior

That either the clean up can be prevented or delayed during beforeUnmount.

Additional Context

To clarify, this is a known Vue thing, and not unique to Embla. It happens with a lot of libraries that clean up using Vue's beforeUnmount hook.

A solution could be using a mutation observer or providing a timeout prop to delay the destroying.
Here's how it got discussed for Splide.

This could require a similar solution to the React issue here #540, where "freezing" styles could work.

I tried the following workaround, but it doesn't consider slides that are translated during loops :

beforeUnmount(){
  const x = this.embla.internalEngine().location.get();
  const $cont = this.embla.containerNode();
  $cont.style.transform = 'translateX('+x+'px)';
}

What browsers are you seeing the problem on?

All browsers

Version

v8.0.4

CodeSandbox

https://codesandbox.io/p/devbox/reverent-almeida-nh8pkr

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
  • I agree to follow this project's Contributing Guidelines for bug reports
@sambedingfield sambedingfield added the bug Something isn't working label May 12, 2024
@sambedingfield sambedingfield changed the title [Bug]: beforeUnmount called before too soon with [Bug]: beforeUnmount destroys too soon during Vue transitions May 12, 2024
@davidjerleke
Copy link
Owner

davidjerleke commented May 13, 2024

@sambedingfield thanks for your bug report. Is this expected behaviour for onBeforeUnmount:

Or is it a bug? It seems like some of the comments suggest it's by design? This was the PR where the onUnmounted was replaced with onBeforeUnmount:

I'm not a seasoned Vue dev by any means but would re-introducing onUnmounted fix the problem? @meirroth and/or @sadeghbarati, any thoughts on this?

@davidjerleke davidjerleke added the vue Issue is related to Vue label May 13, 2024
@sambedingfield
Copy link
Author

sambedingfield commented May 13, 2024

It doesn't look like it's going to change, so... by design ¯\_(ツ)_/¯
Without any kind of destroy delay or style freeze via Embla there's no other workaround (that I know of) to prevent this.
So feel free to flag this as a feature request instead!

To clarify, both onUnmounted and onBeforeUnmount trigger beforehand, irrelevant to parent Vue transitions.

@sadeghbarati
Copy link
Contributor

Will create Vue SFC playground to see differences between Vue versions

IIRC they refactored Transition component alot lately

@meirroth
Copy link
Contributor

@davidjerleke I'd be concerned about making such a change without extensive testing, especially given any potential errors or performance changes #672 (comment).

@sambedingfield Is it possible for you to share a minimal reproduction of the problem you're experiencing so that we can visualize it, debug it, and possibly find a solution? One option I can think of is to use the embla-carousel core without the wrapper and manually destroy it whenever you want. It's actually quite simple, as demonstrated by the Vue 2 example I provided earlier.

@sadeghbarati
Copy link
Contributor

sadeghbarati commented May 13, 2024

@meirroth

Here the Vue SFC playground

It appears that there are issues with Transition and onBeforeUnmount

@sambedingfield
Copy link
Author

@meirroth My CodeSandbox is in the original report, here: https://codesandbox.io/p/devbox/reverent-almeida-nh8pkr
And you're correct, a workaround could be to not use the Vue version.

@meirroth
Copy link
Contributor

@sambedingfield Sorry I missed it 🤦‍♂️ Thanks for sharing.

It seems to me that the issue persists after replacing onBeforeUnmount with onUnmounted as you can see in this Vue SFC playground using embla-carousel core.

@meirroth
Copy link
Contributor

@davidjerleke
Copy link
Owner

davidjerleke commented May 13, 2024

@meirroth it can, but not every user would want that. I'm not sure how to solve this in an optimal way. Maybe we can add a parameter to destroy() that's a boolean:

function destroy(keepStyles: boolean): void {
  // ...
}

On the other hand, that wouldn't solve this request which is related to this to some extent:

@sadeghbarati
Copy link
Contributor

sadeghbarati commented May 13, 2024

  • React is working fine with framer-motion

https://stackblitz.com/edit/basic-embla-carousel-dthb3k


  • Svelte is also fine with transition

https://svelte.dev/repl/0e18b50b771c496dbf11a7d330a46164?version=3.31.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working vue Issue is related to Vue
Projects
None yet
Development

No branches or pull requests

4 participants