Repository navigation
Description
What happened?
Every time a video is opened, the toast "The server is back." appears, although the server was never away. Expected: the toast shows only at the moment the server actually comes back.
Steps to reproduce
- Open the web app and let one connection hiccup happen (laptop sleep, network switch, proxy dropping the event stream, or a server restart). After that,
resumesin the server-status store is greater than 0 for the rest of the page session. - Open any video.
- See "The server is back." at the bottom (page notice) and at the top of the player (player notice), for 3 s. Opening the next video shows it again.
Area
Frontend (web app)
Anything else?
Found by static code reading (Frontend main @ 7f42ebc); not run in a browser. The trigger condition in step 1 is inferred from the code, not observed.
Cause: useBackOnline() in apps/web/src/components/server-status-notice.tsx:18-28 turns the counter resumes into a transient event:
const resumes = useServerStatusStore((state) => state.resumes);
const [back, setBack] = useState(false);
useEffect(() => {
if (resumes === 0) return;
setBack(true);
...
}, [resumes]);An effect runs on mount as well as on change. Each ServerStatusNotice instance starts with back = false, but on mount resumes is already > 0 after any earlier recovery, so the effect immediately sets back = true and shows the toast. The component is mounted fresh each time a video opens: videojs-video-player.tsx:160 renders <ServerStatusNotice variant="player" /> inside the player, so every new player mount produces the toast, and the page-level instance (__root.tsx:288, ServerStatusHost) can show it alongside it on the watch page.
resumes itself is only incremented in serverGreeted / serverReached (lib/server-status.ts) on a real recovery; the bug is that a later mount cannot tell "a resume happened now" from "a resume happened earlier".
Suggested fix: show the toast only for a change of resumes after mount — keep the value seen on mount in a ref and compare (if (resumes === seen.current) return; seen.current = resumes;), or store a lastResumeAt timestamp in the store and show the toast only if it is younger than BACK_VISIBLE_MS. Also render the toast from one place only (the page instance); the player instance can keep the loss/restart phases but not the "back" message, so the two never appear together. Add a test that mounts the notice with resumes = 1 and expects no text.
AI disclosure: This issue was prepared with assistance from an AI system. The observations and proposed fix are based on static code reading and should be reviewed and validated by the maintainers.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog
Activity