DEV Community

Cover image for How to handle Async Rendering in Vue with Suspense?
Jakub Andrzejewski
Jakub Andrzejewski

Posted on

How to handle Async Rendering in Vue with Suspense?

When working with data fetching, async components, or delayed UI loading, Vue developers often run into flickering interfaces, hydration issues, or mismatched loading states. Vue Suspense solves this by giving you full control over asynchronous rendering with built-in placeholders, fallbacks, transitions, and error boundaries.

In this article, you’ll learn:

• What Vue Suspense is and why it exists
• How fallback slots work for loading placeholders
• How to use Suspense with <Transition>
• How it interacts with <KeepAlive>
• How to catch and handle errors inside Suspense
• When Suspense is especially useful in Vue and Nuxt

Enjoy!

🤔 What Is Vue Suspense?

Vue Suspense is a built-in Vue 3 feature that lets components “wait” for async operations during the setup() phase before rendering. While waiting, it shows a fallback UI of your choice.

Vue automatically handles:

• pausing rendering
• waiting for async setup calls
• switching from fallback to resolved UI
• handling transitions
• capturing async errors

Suspense is especially useful when:

• components fetch data during setup
• you load heavy async components
• you want predictable placeholder behavior
• you care about SSR hydration stability

Suspense provides a structured and predictable way to manage async UI.

🟢 Vue Suspense examples

There are multiple ways how you can use Suspense in Vue - let's take a look at some examples where it shines!

Using the Fallback Slot for Placeholders

The #fallback slot shows temporary UI until the async content is ready.

Example:

<Suspense>
  <template #default>
    <UserDashboard />
  </template>

  <template #fallback>
    <DashboardSkeleton />
  </template>
</Suspense>
Enter fullscreen mode Exit fullscreen mode

This improves the loading UX and prevents UI flicker, especially when:

• the component fetches data
• the component imports heavy modules
• you want skeleton screens or loaders

The fallback disappears once the component resolves its async dependencies.

Combining Suspense with <Transition>

One of the most overlooked features is that Suspense works beautifully with transitions.

Example:

<Transition name="fade">
  <Suspense>
    <template #default>
      <AsyncGallery />
    </template>

    <template #fallback>
      <GallerySkeleton />
    </template>
  </Suspense>
</Transition>
Enter fullscreen mode Exit fullscreen mode

This gives you:

• fading in of content after async completion
• smoother perceived loading
• cleaner visual flow

It is ideal for media-heavy components, dashboards, or galleries.

Using Suspense Together with <KeepAlive>

Suspense can also be combined with <KeepAlive> to prevent re-running expensive async operations:

<KeepAlive>
  <Suspense>
    <template #default>
      <ChatWindow />
    </template>

    <template #fallback>
      <ChatLoading />
    </template>
  </Suspense>
</KeepAlive>
Enter fullscreen mode Exit fullscreen mode

Great for:

• chat apps
• multi-page dashboards
• data-intensive components
• 3D scenes or visualization tools

KeepAlive ensures the component stays in memory, avoiding re-fetching or reinitializing.

Error Handling Inside Suspense

Suspense provides a dedicated #error slot to catch async errors:

<Suspense>
  <template #default>
    <AnalyticsReport />
  </template>

  <template #fallback>
    <ReportLoading />
  </template>

  <template #error="{ error }">
    <div class="error-box">
      Failed to load report: {{ error.message }}
    </div>
  </template>
</Suspense>
Enter fullscreen mode Exit fullscreen mode

This protects your app from:

• network failures
• API errors
• rejected promises
• missing permission scopes

You get a clean, declarative error boundary.

Vue + Nuxt: When Suspense Is Especially Useful

Suspense becomes a superpower in Nuxt, where:

• async setup happens both server- and client-side
• hydration mismatches are common with async content
• fallback placeholders prevent flicker
• it helps control when components load during SSR
• transitions between states feel smoother

Any async-heavy Nuxt project benefits directly from Suspense.

📖 Learn more

If you would like to learn more about Vue, Nuxt, JavaScript or other useful technologies, checkout VueSchool by clicking this link or by clicking the image below:

Vue School Link

It covers the most important concepts of modern Vue and Nuxt development and will help you grow as a developer.

🧪 Advance skills

A certification boosts your skills, builds credibility, and opens doors to new opportunities. Whether you're advancing your career or switching paths, it's a smart step toward success.

Check out Certificates.dev by clicking this link or the image below:

Certificates.dev Link

Invest in yourself—get certified in Vue.js, JavaScript, Nuxt, Angular, React, and more!

✅ Summary

Suspense helps you create smoother, more predictable async UIs while avoiding hydration issues and loading flickers.

Take care!
And happy coding as always 🖥️

Top comments (0)