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

fix: ensure loadLottie is called after the component mounted #527

Merged

Conversation

Mini-ghost
Copy link
Contributor

Resolved #502

Currently, loadLottie is invoked during the component's creation phase. However, this does not guarantee that the component will be mounted right away.

App.vue

<script setup lang="ts">
import { defineAsyncComponent } from 'vue';
const LazyDynamicComponent = defineAsyncComponent(() => import('./components/DynamicComponent.vue'));
</script>

<template>
    <Suspense>
      <LazyDynamicComponent />
    </Suspense>
</template>

components/DynamicComponent.vue

<template>
  <div>
    <Vue3Lottie :animationData="dog" :width="300" :height="300" />
  </div>
</template>

<script setup lang="ts">
import dog from '../assets/dog.json';

await new Promise(resolve => {
  setTimeout(() => {
    resolve(true);
  }, 3000);
});
</script>

Especially when we use async setup() with <Suspense>, the component will be created first but not mounted until the promise is resolved.

Therefore, it's essential to verify if the component has been mounted before calling loadLottie. We can do this by monitoring the lottieAnimationContainer value.

@Mini-ghost Mini-ghost requested a review from megasanjay as a code owner March 5, 2024 10:07
Copy link

vercel bot commented Mar 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vue3-lottie ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 5, 2024 10:24am

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have skipped reviewing this pull request. All of the files appear to be ones we're not sure how to review. We're working on it!

@megasanjay megasanjay changed the base branch from main to v3.3 March 17, 2024 00:26
@megasanjay megasanjay merged commit 171d54f into megasanjay:v3.3 Mar 17, 2024
6 checks passed
megasanjay added a commit that referenced this pull request Mar 17, 2024
* fix: ensure `loadLottie` is called after the component mounted (#527)

* fix: ensure `loadLottie` invoke after `lottieAnimationContainer` is mounted

* refactor: remove unnecessary `nextTick`

* perf: educe the unnecessary use of `ref` (#526)

Co-authored-by: Sanjay Soundarajan <sanjay.16@live.com>

* refactor: switch to smaller dependencies to reduce bundle size (#525)

* 🐛  fix: performance improvements and suspense bug fixes

* 🔖 chore: prep for releasing v3.3

* 🔖 chore: prep for releasing v3.3 beta

---------

Co-authored-by: Alex Liu <dsa1314@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lottie won't render in Suspense!
2 participants