-
Notifications
You must be signed in to change notification settings - Fork 326
fix(app-router): keep refresh transitions pending #1269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { RefreshPendingClient } from "./refresh-pending-client"; | ||
|
|
||
| async function delay(ms: number) { | ||
| return new Promise((resolve) => setTimeout(resolve, ms)); | ||
| } | ||
|
|
||
| export default async function RouterRefreshPendingPage() { | ||
| // Keep the refresh RSC request in flight long enough for the browser test to | ||
| // observe the transition's pending state before the refreshed tree commits. | ||
| await delay(1_000); | ||
|
|
||
| return ( | ||
| <div> | ||
| <h1 id="router-refresh-pending-title">Router refresh pending</h1> | ||
| <RefreshPendingClient /> | ||
| <p id="refresh-server-stamp">server stamp: {Date.now()}</p> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| "use client"; | ||
|
|
||
| import { useRouter } from "next/navigation"; | ||
| import { useTransition } from "react"; | ||
|
|
||
| export function RefreshPendingClient() { | ||
| const router = useRouter(); | ||
| const [isPending, startTransition] = useTransition(); | ||
|
|
||
| return ( | ||
| <div> | ||
| <p id="refresh-pending-state">{isPending ? "pending" : "idle"}</p> | ||
| <button | ||
| id="refresh-current-route" | ||
| onClick={() => { | ||
| startTransition(() => { | ||
| router.refresh(); | ||
| }); | ||
| }} | ||
| > | ||
| Refresh current route | ||
| </button> | ||
| </div> | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The 1s server delay and the 1s Playwright assertion timeout for observing
"pending"are exactly matched. If the dev server is slow to start the RSC response (e.g. CI load spike), the delay might not provide enough headroom and the test could flake. The existing push-pending fixture also uses 1s, so this is consistent, but worth noting — if either ever flakes, bumping the delay to 1.5–2s (or increasing the assertion timeout to 2s) would add margin.