mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #701] Add experimental.useOffline — offline detection, retry, and useOffline() hook #150
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#150
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @github-actions[bot] on GitHub (Mar 28, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/701
Upstream
904501127c9ed2e0a7ffd51bd192537b7c398fb3)useOffline()hook (7bce97d6485599cab2964ef58fde8a55d19904d3)Summary
Next.js added a new
experimental.useOfflineflag that provides two capabilities:1. Offline retry for navigations, server actions, and prefetches
When a
fetch()rejects due to a network error (not abort/timeout), the request blocks until connectivity is restored and then retries automatically, instead of falling back to MPA navigation or surfacing an error.packages/next/src/client/components/offline.tsmodule owns all offline state: detection, polling with exponential backoff (500ms → 1s → 2s → 3s cap), and connectivity checks via HEAD requests.fetchServerResponse(navigation) catches network errors, callscheckOfflineError()→waitForConnection()→ retries.fetchServerAction(server actions) does the same — safe to replay because the rejection means the request never reached the server.offline/onlineevents feed into the polling loop. Successful fetches from any code path short-circuit vianotifyOnline().process.env.__NEXT_USE_OFFLINEwith lazyrequire()calls.2.
useOffline()hook vianext/offlinenext/offlineexport path (offline.js,offline.d.ts).useOffline()hook returnstruewhen offline, powered byOfflineProviderrendered inside the app router.useState+useOptimisticso value updates even during blocked transitions.dispatchOfflineChange()bridges from the offline detection module into React state viastartTransition.Impact on vinext
next/offline→ exportuseOffline()hook. Needs to be added to the shim map inindex.ts.experimental.useOfflineneeds to be recognized if vinext processes next.config.OfflineProviderin app router tree: The provider wraps the router content — relevant if vinext constructs the app router React tree.notifyOnline()callspingPrefetchScheduler()to resume prefetches after reconnection.Suggested approach
Start with the shim for
next/offlinethat exports a no-opuseOffline()returningfalse. The full offline retry behavior is complex client-side router logic that can be deferred until the feature stabilizes (it's behindexperimental).