Repository navigation
Commit e48bf75
authored
social: the peer-thinking row stops polling while the tab is hidden and reads once when it returns (#3333)
Fixes #3332
Bot: FlyBot Dev-3
Owner: Dev-3
Written-by: Dev-3
Reviewer: Birfy
## What the row did
`PeerThinking` polls `social/typing` every 2 s to draw the "…is
thinking" row in an open face-to-face room. It did that on a bare
interval, whatever the tab was doing:
- `plugins/social/client.js:2489` at the base: `const timer =
setInterval(load, 2000)`, created unconditionally on mount.
- The visibility check lived *inside* `load` (`:2484`, `if (typeof
document !== 'undefined' && document.hidden) return`), so a hidden tab
kept a timer firing every 2 s that returned before reading anything —
one wake-up per 2 s for nothing, until unmount.
- The effect registered no `visibilitychange` listener at all, so a tab
that came back did not read at once: its first read waited out the rest
of the current period (0–2 s).
Every other poll in this client already goes through `pollWhileVisible`
(`client.js:3059`, #3315, #3327): no timer while hidden, one read as the
tab comes back, the cadence restarted from that read, the listener
removed on unmount. This row was the next item on `#3327`'s follow-up
list.
## What changes
- `plugins/social/client.js` — the effect drops `setInterval` and the
`document.hidden` early return inside `load` (the helper never calls it
while hidden) and keeps `const stop = pollWhileVisible(load, 2000)`;
unmount does `live = false; stop?.()` (`+2/−6`).
- `plugins/social/test/poll-visibility.test.js` — one case on the
shipped component through the file's existing `scene()` / `mount()`
harness (`+27`): a hidden mount makes no `social/typing` read and keeps
no poll timer, `visibilitychange` back to visible reads exactly once and
the 2 s cadence restarts from that read, one period later reads once
more, going hidden again stops it, unmount drops the timer. It counts
observed calls over time rather than compare a golden.
- `docs/subsystems/social.md` — one sentence beside the #3315/#3327
polling rule.
- `changelog.d/3332.fixed.md`.
Visible cadence is unchanged: the helper's `start()` calls `fn()` once
and then `setInterval(fn, 2000)`, which is the same "read at mount, then
every 2 s" shape the old `load(); setInterval(load, 2000)` had. No new
string, so no dictionary rebuild and no client-bundle re-emit.
Not touched: `plugins/social/src/**`, `core/**`,
`core/src/client/i18n.js`, `patches/**`.
## No UI face
The row's text, when it appears and its layout do not change, only when
the reads happen while hidden. Nothing is drawn differently — no text,
row, or layout moves — so there is nothing for a before/after screenshot
to show, and this section says so for the verdict.
## Red first
The new case with the base `plugins/social/client.js` (test file from
this branch), the same command twice on the same tree at base
`1a276c57874e3c45680d4bec10ae1bd6080777fd`:
```
$ cd plugins/social && node --import ./test/resolve.mjs --test test/poll-visibility.test.js
# tests 7 | # pass 6 | # fail 1 (run 1)
# tests 7 | # pass 6 | # fail 1 (run 2)
not ok 7 - the peer-thinking row stops while hidden and reads once when the tab returns
error: 'a hidden row holds no poll timer'
actual: [ 2000 ] expected: []
at plugins/social/test/poll-visibility.test.js:275
```
Both runs are the same shape and fail on the same assertion (`:275`): a
hidden mount already keeps a 2 s poll timer, which is the defect and the
line the case reads first. The six #3315/#3327 cases above it stay green
throughout.
The second half of the defect — a tab that comes back does not read at
once — was probed on the same base during the READY with a one-off copy
of the case that dropped the timer assertion: `# pass 0 | # fail 1`,
`coming back made 0 read(s), not one` (`poll-visibility.test.js:278`),
i.e. the old effect had no `visibilitychange` listener to read on. The
committed case asserts both halves; the first one to fire is the timer.
## Verification at tip `af344f6c06199430eda1fac5a97323837fef2b0c`
- tip `af344f6c06199430eda1fac5a97323837fef2b0c`, tree
`816a934971ae8b3665adc920aef30285c2b0ff08`, base
`1a276c57874e3c45680d4bec10ae1bd6080777fd`
- `git diff --name-only
1a276c5..af344f6`
→ exactly the four files above (`client.js` +2/−6, test +27, docs +1,
changelog +1)
- `cd plugins/social && node --import ./test/resolve.mjs --test
test/poll-visibility.test.js` → 7/7, `# fail 0`, rc 0
- `npm --prefix plugins/social test` → 768/768, 0 fail, rc 0 (unchanged
base is 767/767; only this one case is added)
- `node scripts/lint-plugins.mjs social` → `Found 42 warnings and 0
errors.`, rc 0
- `node .github/scripts/changelog.mjs check` → `changelog: 9 fragment(s)
in changelog.d/ are well formed`
- `ARCH_DOCS_BASE=1a276c57874e3c45680d4bec10ae1bd6080777fd node
core/scripts/check-arch-docs.mjs` → `arch-docs: OK (4 changed file(s))`
## Checkpoint
<!-- flybot:checkpoint -->
```json
{
"pr": 3333,
"claim": "Dev-3",
"issue": 3332,
"summary": "The peer-thinking row kept a bare 2 s `setInterval` and checked `document.hidden` inside the read, so a hidden tab held a timer ticking for nothing and a tab that came back waited out the rest of the period instead of reading once. It now uses the existing `pollWhileVisible`, so a hidden tab holds no timer, coming back reads once at once and restarts the 2 s cadence from that read, and unmount removes the listener. The visible cadence is unchanged and nothing on screen changes; only when the reads happen while hidden.",
"files": [
"plugins/social/client.js",
"plugins/social/test/poll-visibility.test.js",
"docs/subsystems/social.md",
"changelog.d/3332.fixed.md"
],
"checks": {
"ran": "npm --prefix plugins/social test",
"result": "green",
"at": "af344f6c06199430eda1fac5a97323837fef2b0c"
},
"next": "none — ready for review"
}
```
<!-- /flybot:checkpoint -->1 parent 1a276c5 commit e48bf75
4 files changed
Lines changed: 31 additions & 6 deletions
File tree
- changelog.d
- docs/subsystems
- plugins/social
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2481 | 2481 | | |
2482 | 2482 | | |
2483 | 2483 | | |
2484 | | - | |
2485 | 2484 | | |
2486 | 2485 | | |
2487 | | - | |
2488 | | - | |
2489 | | - | |
2490 | | - | |
2491 | | - | |
| 2486 | + | |
| 2487 | + | |
2492 | 2488 | | |
2493 | 2489 | | |
2494 | 2490 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
0 commit comments