Introduction
import { Router } from '@solidjs/router'
import { Suspense } from 'solid-js'
import { RouteProgress } from 'solid-route-progress/router'
import 'solid-route-progress/style.css'
<Router
root={(props) => (
<>
<RouteProgress />
<Suspense>{props.children}</Suspense>
</>
)}
/>Entry points
| Entry | Exports |
|---|---|
solid-route-progress | createProgress, <Progress>, <ProgressProvider>, <Bar>, useProgress(), createCrossDocumentProgress(), IGNORE_ATTRIBUTE |
solid-route-progress/router | <RouteProgress>, createRouteProgress() |
solid-route-progress/navigation | <NavigationProgress>, createNavigationProgress() |
solid-route-progress/style.css | the stylesheet |
What JavaScript writes
| Written | On | Value |
|---|---|---|
--sp-value | the bar | 0 to 1, the target of the CSS transition |
--sp-speed | the bar | the speed option |
data-state | the bar | idle | trickle | active | done |
data-error | the bar | during the done phase of a failed load |
data-sp-busy | <html> | while any bar is visible |
Everything else is CSS.
How it works
start()waitsdelay(200 ms), then flipsdata-statetotrickleand sets--sp-valuetotrickleTo(0.95). The stylesheet'stricklerule has a 10 s transition ontranslatewhose curve races out and then crawls. It is one transition, and no timer steps it.set(n)switches toactive, which leaves the bar on its short--sp-speedtransition for the hop, then hands back totrickle. CSS transitions interrupt from the current animated value, so there is nothing to sync.- Once the last hold is released (or on
done()), the bar hops to 100% in thedonestate (withdata-errorif a hold was released as an'error'; a'cancel'skips this step and fades straight out), thenidlefades the whole bar out withopacity+ a delayedvisibility: hidden. The bar itself is parked back at--sp-startonly after the fade has finished. Both steps takespeed, which the bar also writes to--sp-speed, so the CSS and the timers never disagree. A load that starts during this phase waits for the fade and fordelay, whichever is longer. - If the load ends while
delayis still pending, or before the browser painted the bar (tracked with a singlerequestAnimationFrame), the bar is dropped silently.
Size
What each setup adds to your bundle, in bytes, after tree-shaking:
| Import | min | gzip | brotli |
|---|---|---|---|
<RouteProgress />, solid-route-progress/router | 4838 | 2363 | 2135 |
<NavigationProgress />, solid-route-progress/navigation | 4300 | 2099 | 1905 |
createProgress alone | 1721 | 908 | 841 |
solid-route-progress/style.css | 1089 | 510 | 418 |
Zero dependencies. The bar only moves opacity and translate, so its animations run on the compositor thread and stay smooth while the next route keeps the main thread busy.