AgentSkillsCN

loading-and-error-states

避免布局偏移、提升清晰度的加载与错误处理 UX 模式。关键词:加载、错误、Suspense、骨架屏、错误边界、CLS。

SKILL.md
--- frontmatter
name: loading-and-error-states
description: "Loading and error UX patterns that avoid layout shift and improve clarity. Keywords: loading, error, suspense, skeleton, error boundary, CLS."

Loading and Error States

This skill provides patterns for consistent loading and error UX.


1. Avoid layout shift (CLS)

  • Reserve space for content during loading (skeletons, placeholders).
  • Avoid patterns that drastically change layout between loading and loaded states.

2. Choose a consistent strategy

Two common approaches:

  • Suspense-based: use Suspense boundaries + error boundaries.
  • Explicit state-based: isLoading / isError flags with consistent layout.

Pick one approach per application (or per major area) and apply consistently.


3. Error boundaries (recommended)

For unexpected errors, prefer an error boundary that:

  • renders a safe fallback UI
  • logs/captures the error to monitoring
  • offers a retry action if appropriate