feat(frontend): auto-reconnect offline page on network restore - #417
Merged
Merged
Conversation
- Convert app/offline/page.tsx to a Client Component so it can
register a window 'online' event listener.
- On mount, if already online redirect immediately to /.
- On network restore, show 'Reconnecting...' spinner (Spinner component)
then redirect to / via router.replace('/').
- Extract metadata (title: 'You're offline') into a sibling layout.tsx
so the page can be a pure client component without losing SEO title.
- Add e2e/offline.spec.ts with three Playwright tests:
- redirect fires when network is restored (context.setOffline toggle)
- Reconnecting spinner has accessible aria-label 'Reconnecting...'
- Retry link is always present as a fallback while offline
Closes arflexx#278
|
@Onesimus-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(frontend): auto-reconnect offline page on network restore
Closes #278
closes #275
closes #268
closes #269
Problem
The offline fallback page (app/offline/page.tsx) was a static Server
Component with no awareness of network state changes. When a user's
connection was restored, they had to manually reload the page to get
back to the app — a poor UX for a PWA where seamless recovery is
expected.
Solution
app/offline/page.tsx
Converted from a static Server Component to a "use client" Client
Component so it can register browser event listeners.
Key behaviours:
the browser served a cached copy after reconnecting), redirects
immediately to / via router.replace('/') without waiting for the event.
"Reconnecting…" message), then calls router.replace('/') to send the
user home automatically — no manual reload needed.
function to prevent memory leaks and stale closures.
Retry link) is preserved as a fallback while the network is still down.
app/offline/layout.tsx (new)
The Next.js App Router does not allow a metadata export in a Client
Component. A minimal sibling layout.tsx is added to own the route-level
metadata (title: "You're offline") so the page title is still set
correctly without making the page a Server Component.
e2e/offline.spec.ts (new)
Three Playwright tests using context.setOffline(true/false) to toggle
the browser context network state. This fires the real window 'online'
and 'offline' events — the same mechanism the page listens to — making
the test faithful to production behaviour without any mocking.
Tests:
redirects to / automatically when network is restored
router navigates to / without a manual reload.
shows Reconnecting spinner with accessible label
restore, and carries aria-label="Reconnecting…" for screen readers.
Retry link is present while offline
fallback for users who restore connectivity before the event fires
or who have JS disabled.
Files changed
M frontend/app/offline/page.tsx
A frontend/app/offline/layout.tsx
A frontend/e2e/offline.spec.ts