---
title: "Lazy Load Without Killing Your UX | Super Kenil"
description: "Clicking a button shouldn't feel like a chore. Discover how to eliminate 'ghost delays' in your React apps by decoupling dialog state from content loading for a buttery-smooth, high-performance interface."
url: "https://sknl.dev/blog/lazy-load-without-killing-ux"
published: "2026-04-05"
updated: "2026-11-26"
tags:
  - "react"
  - "nextjs"
  - "webperf"
  - "frontend"
  - "ux-design"
  - "zustand"
  - "javascript"
  - "architecture"
content_signal: "ai-train=yes, search=yes, ai-input=yes"
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://sknl.dev/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Lazy Load Without Killing Your UX

Clicking a button shouldn't feel like a chore. Discover how to eliminate 'ghost delays' in your React apps by decoupling dialog state from content loading for a buttery-smooth, high-performance interface.

- Author: Kenil Sudani (Super Kenil)
- Published: 2026-04-05 | Updated: 2026-11-26
- Tags: react, nextjs, webperf, frontend, ux-design, zustand, javascript, architecture

**To lazy load React dialogs without UX lag**, decouple the dialog shell from its lazily imported body: keep a lightweight store (`dialogName`) that opens the dialog frame instantly on click, and wrap the dynamic modal content inside a React `<Suspense>` boundary so the chunk downloads while the open animation plays.

The problem with naive lazy-loaded dialogs is simple: code splitting delays feedback. You click a button, nothing happens for 200ms while JavaScript fetches the chunk, and then the modal pops in. Preloading every dialog defeats code splitting—so the solution is opening the shell first and streaming the content inside.

## The Pattern

Keep a **stateless dialog layer** powered by a lightweight state store (Zustand, Redux, Jotai, or Context). Clicking a button updates only `dialogName`, opening the dialog frame immediately while React loads the specific inner component inside `<Suspense>`.

```typescript
// src/stores/use-dialogs.ts
import { create } from 'zustand'
import { startTransition } from 'react'

type DialogStoreType = {
  dialogName: string | null
  open: (name: string) => void
  close: () => void
}

export const useDialogs = create<DialogStoreType>((set) => ({
  dialogName: null,
  open: (name) => {
    startTransition(() => {
      set({ dialogName: name })
    })
  },
  close: () => {
    startTransition(() => {
      set({ dialogName: null })
    })
  }
}))
```

That's the entire store—just the active dialog identifier.

Now wire the root container with `next/dynamic` (or `React.lazy`) inside `Suspense`:

```typescript
// components/dialogs-root.tsx
'use client'
import dynamic from 'next/dynamic'
import { Suspense } from 'react'
import { useDialogs } from '@/stores/use-dialogs'
import { Dialog, DialogContent } from '@/ui/dialog'

const FirstDialog = dynamic(() => import('./first-dialog'))
const SecondDialog = dynamic(() => import('./second-dialog'))

export function DialogsRoot() {
  const { dialogName, close } = useDialogs()

  return (
    <Dialog open={!!dialogName} onOpenChange={close}>
      <Suspense fallback={<DialogContent>Loading...</DialogContent>}>
        {dialogName === 'first' && <FirstDialog />}
        {dialogName === 'second' && <SecondDialog />}
      </Suspense>
    </Dialog>
  )
}
```

## Triggering a Dialog From Any Component

```typescript
const openDialog = useDialogs((store) => store.open)

return (
  <button onClick={() => openDialog('first')}>
    Open Dialog
  </button>
)
```

Click happens → store updates → dialog shell animates open immediately → inner chunk loads inside `Suspense`.

## Why This Pattern Works

1. **Instant UI feedback:** The dialog container opens on the click frame so users know their action registered.
2. **Animation masks network latency:** During a 200–300ms entrance animation, the dynamic chunk often finishes downloading before the transition completes.
3. **True on-demand splitting:** Unopened modals (settings, delete confirmations, invite flows) never ship in the initial page bundle.
4. **Graceful slow-network fallback:** If the network is slow, the `Suspense` fallback inside `<DialogContent>` gives clear loading feedback.

## Minimal Fallback Pattern

```tsx
<Suspense fallback={
  <DialogContent>
    <div className='flex items-center justify-center min-h-80'>
      <Spinner />
    </div>
  </DialogContent>
}>
  {/* dialogs here */}
</Suspense>
```

## Scaling to Pages With 10+ Dialogs

On complex dashboards with many modals, forms, and confirmation dialogs, deferring individual dialog bodies avoids shipping tens of kilobytes of unused form/validation code upfront while keeping interactions responsive. Any dialog-specific form state stays isolated inside that dialog component itself.

## Frequently Asked Questions

### How do you lazy load a React modal or dialog without delaying its open animation?

Store only the active dialog identifier in lightweight global state (such as Zustand or React Context) inside startTransition so the dialog shell opens immediately, while lazy-loading the inner dialog body inside a React Suspense boundary.

### Why does lazy loading a whole dialog wrapper hurt UX?

If the trigger button directly wraps a dynamically imported dialog component, clicking the button blocks on the network chunk download before the modal opens, causing a noticeable 150-300ms unresponsive delay.
