02-how-it-works

All docs

How It Works

AutoSkeleton generates loading skeletons automatically by inspecting your rendered DOM. No manual skeleton components needed.

The Pipeline

                  Render   ->  Measure  ->   Infer    ->  Blueprint  ->   Render   (hidden)       (DOM)       (roles)        (tree)       (skeleton)                

Step 1: Hidden Render

When loading={true}, your children are rendered in a hidden measurement container (opacity: 0, position: absolute). This allows the browser to compute layout without showing content.

Step 2: DOM Measurement

Using requestAnimationFrame to ensure paint is complete, the library traverses the DOM tree:

Step 3: Role Inference

Each leaf element is classified using a score-based heuristic system:

RoleKey Signals
textHas text content, text-range height, typical text tags
image<img> tag, role="img", background-image
icon<svg> tag, small and square
button<button> tag, role="button", cursor: pointer
input<input>, <textarea>, <select>, contenteditable

The highest-scoring role wins. Minimum threshold is 30 points.

Step 4: Blueprint Generation

A tree of SkeletonNode objects is built:

Step 5: Skeleton Rendering

The skeleton is rendered as an absolute-positioned overlay on top of the hidden content:

 Wrapper (position: rel)         Content (hidden)       <- visibility: hidden during loading           Skeleton (overlay)     <- position: absolute, z-index on top           Measure (hidden)       <- opacity: 0, for DOM measurement    

Transitions

When loading changes from true to false:

  1. Content becomes visible
  2. Skeleton fades out over 300ms (opacity: 1 -> 0)
  3. After fade completes, skeleton is unmounted

This produces a smooth crossfade between skeleton and real content.

Key Design Decisions

Next Steps