Handle offline mode in the agentic UI#4232
Conversation
📊 Performance Test ResultsComparing 00f8ed8 vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
There was a problem hiding this comment.
In the exploration design, although we don't have the behavior for offline, we do for logged-out experience, and we could apply a similar UI.
| Light | Dark |
|---|---|
![]() |
![]() |
My suggestion for this PR is to:
- Create the new Overview tab - just the tab title and the offline banner, we can add the rest of the content in follow-up PR
- Adjust the banner layout and text to match the logged-out one, keeping your suggestion of a "warning-like" style
- Keep the redirect behavior, it matches exactly what it is done in the exploration design
Behavior wise, I am still able to push, pull and update preview while offline, if those were already connected before going offline.
e9d1319 to
ce9ddb0
Compare
|
@bcotrim I have made some more changes - feel free to review and modify whatever you think is necessary. Initially, I thought about using the separate tab but I did not find that it worked nice so I ended up adding the banner to the site settings tab. I will be AFK next week but feel free to take over and make further changes |
…gentic-ui # Conflicts: # apps/ui/src/components/site-dropdown/main-view.tsx # apps/ui/src/ui-classic/router/route-new-session/index.tsx # apps/ui/src/ui-classic/router/route-session-detail/index.tsx
|
@sejas @nightnei I picked up this PR from @katinthehatsite and made some adjustments. |
…t view when back online
| import { useEffect, useState } from 'react'; | ||
|
|
||
| export function useOffline(): boolean { | ||
| const [ isOffline, setIsOffline ] = useState( ! navigator.onLine ); | ||
|
|
||
| useEffect( () => { | ||
| const update = () => setIsOffline( ! navigator.onLine ); | ||
| window.addEventListener( 'online', update ); | ||
| window.addEventListener( 'offline', update ); | ||
| return () => { | ||
| window.removeEventListener( 'online', update ); | ||
| window.removeEventListener( 'offline', update ); | ||
| }; | ||
| }, [] ); | ||
|
|
||
| return isOffline; | ||
| } |
There was a problem hiding this comment.
Nit. We could use useSyncExternalStore, and avoid using useState.
| import { useEffect, useState } from 'react'; | |
| export function useOffline(): boolean { | |
| const [ isOffline, setIsOffline ] = useState( ! navigator.onLine ); | |
| useEffect( () => { | |
| const update = () => setIsOffline( ! navigator.onLine ); | |
| window.addEventListener( 'online', update ); | |
| window.addEventListener( 'offline', update ); | |
| return () => { | |
| window.removeEventListener( 'online', update ); | |
| window.removeEventListener( 'offline', update ); | |
| }; | |
| }, [] ); | |
| return isOffline; | |
| } | |
| import { useSyncExternalStore } from 'react'; | |
| function subscribe( callback: () => void ) { | |
| window.addEventListener( 'online', callback ); | |
| window.addEventListener( 'offline', callback ); | |
| return () => { | |
| window.removeEventListener( 'online', callback ); | |
| window.removeEventListener( 'offline', callback ); | |
| }; | |
| } | |
| export function useOffline(): boolean { | |
| return useSyncExternalStore( subscribe, () => ! navigator.onLine ); | |
| } |




Related issues
Fixes STU-2060
How AI was used in this PR
It helped to identify and implement relevant changes.
Proposed Changes
This PR handles offline mode in the agentic UI:
Testing Instructions
Pre-merge Checklist