@vctqs1/nav-progress-bar-react 0.0.2-5 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -11
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -2,16 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
React wrapper for [`@vctqs1/nav-progress-bar`](https://www.npmjs.com/package/@vctqs1/nav-progress-bar) — a zero-dependency, CSP-safe top-of-page progress bar built as a native Web Component.
|
|
4
4
|
|
|
5
|
+
> Live demo: https://nav-progress-p0gw9z3lf-vctqs1s-projects.vercel.app/
|
|
6
|
+
|
|
7
|
+
> Demo video:
|
|
8
|
+
|
|
9
|
+
<video src="https://github.com/user-attachments/assets/4144ed95-8c25-4aa9-b804-905ac24805b4" controls width="100%"></video>
|
|
10
|
+
|
|
5
11
|
This package provides a thin React component that renders the `<vctqs1-nav-progress-bar>` custom element with proper TypeScript JSX types and SSR support via Declarative Shadow DOM.
|
|
6
12
|
|
|
13
|
+
> Originally built to solve the [Next.js App Router `loading.js` dead gap](https://github.com/vercel/next.js/issues/43548), but the underlying mechanism (the browser [Navigation API](https://developer.mozilla.org/en-US/docs/Web/API/Navigation_API)) works anywhere.
|
|
14
|
+
|
|
15
|
+
> If you use Next.js App Router, this is the missing feedback layer before `loading.js` renders.
|
|
16
|
+
|
|
7
17
|
## Table of Contents
|
|
8
18
|
|
|
9
19
|
- [Installation](#installation)
|
|
10
|
-
- [
|
|
20
|
+
- [Packages](#packages)
|
|
11
21
|
- [Quick Start](#quick-start)
|
|
12
22
|
- [Next.js App Router](#nextjs-app-router-recommended-setup)
|
|
13
23
|
- [Custom color](#custom-color)
|
|
14
24
|
- [React SPA (Vite, CRA, etc.)](#react-spa-vite-cra-etc)
|
|
25
|
+
- [Why](#why)
|
|
15
26
|
- [Props](#props)
|
|
16
27
|
- [How SSR Works](#how-ssr-works)
|
|
17
28
|
- [Why a Separate Package?](#why-a-separate-package)
|
|
@@ -26,17 +37,21 @@ npm install @vctqs1/nav-progress-bar @vctqs1/nav-progress-bar-react
|
|
|
26
37
|
pnpm add @vctqs1/nav-progress-bar @vctqs1/nav-progress-bar-react
|
|
27
38
|
```
|
|
28
39
|
|
|
29
|
-
##
|
|
40
|
+
## Packages
|
|
41
|
+
|
|
42
|
+
| Package | Description |
|
|
43
|
+
|---------|-------------|
|
|
44
|
+
| [`@vctqs1/nav-progress-bar`](https://www.npmjs.com/package/@vctqs1/nav-progress-bar) | Core Web Component — zero dependencies, framework-agnostic |
|
|
45
|
+
| [`@vctqs1/nav-progress-bar-react`](https://www.npmjs.com/package/@vctqs1/nav-progress-bar-react) | React wrapper with SSR support and JSX types |
|
|
46
|
+
|
|
30
47
|
|
|
31
|
-
| Package | Version |
|
|
32
|
-
|---------|---------|
|
|
33
|
-
| `react` | `>=18.0.0` |
|
|
34
|
-
| `@vctqs1/nav-progress-bar` | `>=1.0.0` |
|
|
35
48
|
|
|
36
49
|
## Quick Start
|
|
37
50
|
|
|
38
51
|
### Next.js App Router (recommended setup)
|
|
39
52
|
|
|
53
|
+
This is the main reason to use this package: immediate route feedback before App Router finishes loading the next screen.
|
|
54
|
+
|
|
40
55
|
**1. Add to root layout** (`app/layout.tsx`):
|
|
41
56
|
|
|
42
57
|
```tsx
|
|
@@ -69,11 +84,7 @@ export function onRouterTransitionStart(
|
|
|
69
84
|
}
|
|
70
85
|
```
|
|
71
86
|
|
|
72
|
-
That's it.
|
|
73
|
-
|
|
74
|
-
> 🎬 **Demo** — watch the bar in action with Next.js App Router:
|
|
75
|
-
|
|
76
|
-
https://github.com/user-attachments/assets/d7537ef6-81a5-4c55-8884-900c9af06161
|
|
87
|
+
That's it. In Next.js App Router, the bar starts from `onRouterTransitionStart()` on every route departure and finishes automatically when the new page commits.
|
|
77
88
|
|
|
78
89
|
---
|
|
79
90
|
|
|
@@ -115,6 +126,42 @@ export default function App() {
|
|
|
115
126
|
|
|
116
127
|
In a plain SPA the bar auto-starts and auto-finishes via the browser Navigation API — no extra wiring needed.
|
|
117
128
|
|
|
129
|
+
## Why
|
|
130
|
+
|
|
131
|
+

|
|
132
|
+
|
|
133
|
+
In Next.js App Router, `loading.js` is a React Suspense boundary — it only renders **after** the RSC payload arrives. On slow connections this creates a dead period of 100ms–2s+ where the page looks frozen after a user clicks a link.
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
User clicks Link
|
|
137
|
+
→ nothing visible happens ← dead gap: page looks frozen
|
|
138
|
+
→ RSC payload arrives
|
|
139
|
+
→ React renders Suspense shell
|
|
140
|
+
→ loading.js displays ← feedback finally appears
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
This is a known App Router limitation:
|
|
144
|
+
- [Next.js issue #43548 — loading.js not shown immediately on navigate](https://github.com/vercel/next.js/issues/43548)
|
|
145
|
+
- [Reddit thread — loading state does not show when navigating](https://www.reddit.com/r/nextjs/comments/1c3ngkh/the_loading_state_does_not_show_when_i_navigate/)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
`@vctqs1/nav-progress-bar` fills that gap by starting from Next.js `onRouterTransitionStart()` — synchronously on route departure, before the next screen is ready:
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
User clicks <Link> / router.push()
|
|
153
|
+
→ Next.js dispatches ACTION_NAVIGATE (React startTransition) [app-router-instance.ts#L457-L474]
|
|
154
|
+
→ Next.js calls history.pushState() to update the URL [app-router.tsx#L52-L54]
|
|
155
|
+
→ browser fires "navigate" → bar starts
|
|
156
|
+
→ Next.js fetches RSC payload
|
|
157
|
+
→ React patches the tree
|
|
158
|
+
→ Next.js finalises with history.pushState() [app-router.tsx#L52-L54]
|
|
159
|
+
→ browser fires "navigatesuccess" → bar finishes
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Next.js App Router does **not** call `navigation.navigate()` directly. It manages routing internally via its own action queue ([`dispatchAppRouterAction`](https://github.com/vercel/next.js/blob/v16.2.6/packages/next/src/client/components/app-router-instance.ts#L457-L474)) using React `startTransition`, then calls `history.pushState()` to update the URL. The browser Navigation API fires `navigate` and `navigatesuccess` as a side effect of those `history` mutations.
|
|
163
|
+
|
|
164
|
+
|
|
118
165
|
## Props
|
|
119
166
|
|
|
120
167
|
| Prop | Type | Default | Description |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vctqs1/nav-progress-bar-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"repository": "https://github.com/vctqs1/nav-progress-bar",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"keywords": [
|
|
24
|
+
"toploader",
|
|
24
25
|
"progress-bar",
|
|
25
26
|
"navigation",
|
|
26
27
|
"react",
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
"access": "public"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@vctqs1/nav-progress-bar": "0.
|
|
40
|
+
"@vctqs1/nav-progress-bar": "0.1.1"
|
|
40
41
|
},
|
|
41
42
|
"nx": {
|
|
42
43
|
"name": "@vctqs1/nav-progress-bar-react",
|