Replies: 3 comments 1 reply
-
Work that is going to help make this RFC possible is already live at vuejs/core#9206 (comment) and vuejs/core#9651 |
Beta Was this translation helpful? Give feedback.
-
Digging more into this, it looks like this is a common source of trouble that framework authors have been dealing, since besides the Vuetify threads linked in the main post, Radix Vue also had the same issue. They workaround this using their @zernonia Do you think all the use cases of Radix will be covered by this proposal? Any edge case you think that might be missed by pausing effects while transitions are running? Given you develop a component library and have some experience with Presence, any API suggestion to have this feature upstream? Thank you very much in advance, |
Beta Was this translation helpful? Give feedback.
-
IMHO This has a big potential for edge cases and unforeseen consequences. A few random comments, but I'm sure more will be uncovered if people experiment with this:
|
Beta Was this translation helpful? Give feedback.
-
Hello. I'm opening this with the aim to gather some feedback on whether there's interest in having this in Vue's core. In my opinion, my proposal fits into the "small enough" area to not go into the RFC process yet (besides, I don't have a PR yet), and that's why I'm opening it under the "General" topic (but feel free to let me know or to move this discussion there) .
Motivation/Summary
When a component is transitioning, state mutations can trigger DOM changes. These can sometimes break the appearance of animations, like in this snippet:
Vuetify Playground
Fire the snackbar and wait a few seconds for it to close. Check how the color of the snackbar changes to white while the transition is taking place. More backrgound here: vuetifyjs/vuetify#17180
Here's another example where this problem might be annoying. In this example, we will deal with a large list (10000 items) and we want to toggle the visibility using
v-show
, but also kill all the DOM nodes when they're hidden to free up resources:In the first case, we simply have a transition that fires after a
v-show
change. In DevTools, you can see how all the nodes are still present in the tree: Vue PlaygroundIf we want to kill all the DOM nodes, we need an
v-if
too! However, that breaks transitions as the DOM is patched: Vue PlaygroundThis is not a problem of the Vue's scheduler patching the DOM before the Transition component takes the change, since this is also reproducible if we add another property that tracks the animation's state: Vue Playground
3 is also reproducible if we set an interval that takes less than the transition itself: Vue Playground
The current solution everybody is doing to solve this problem is very similar to what has been done in 3) and 4): have 2 variables, one that tracks the model state and another that tracks the rendering itself. With the
after-leave
hook, we have an effective workaround: Vue PlaygroundProposed solution
There are two things that could be done into the
leave
andafter-leave
hooks ofTransition
to solve this:Stop dependency/effect tracking of the child component recursively.
This one probably introduces a lot of edge cases and will be really difficult to implement, besides being more prone to breaking watchers, computed properties, etc... And probably will make the implementation much more difficult, since the
Transition
component itself relies in the the state of the component to know when it needs to fire the transition*Stop Vue's patch process.
Inside Vue, only
Transition
should be manipulating the DOM nodes in the "paused" state of the patcher to add the CSS styles and event handler needed for the correct functionality of the component:· Entering component:
sync
flush timing:Transition
)after-leave
:· Leaving component:
pre
flush timing:after-leave
:Adoption strategy
This new behaviour should be the default for
Transition
, since I think it's what most people expect. Apatchable
|modifiable
boolean prop (with proper documentation) could be added to the component to keep the current behaviour.Drawbacks
None that I'm aware of
Alternatives
Approach 5) in the Motivation/Summary section.
Additional context
Teleport
source code and, although I consider myself proficient enough in "userland" Vue, I'm just starting to become more and more interested in Vue's internals and there are probably a lot of things that I'm missing. Please, forgive any lack of precision. Any detailed explanation or further precision of the fine details to get this proposal to a good point is more than welcome!Beta Was this translation helpful? Give feedback.
All reactions