Skip to content

Commit 33ffe5b

Browse files
committed
social: the approval dock and the friends panel hold no poll timer in a hidden tab (#3354)
1 parent 64cf2a6 commit 33ffe5b

3 files changed

Lines changed: 9 additions & 23 deletions

File tree

‎changelog.d/3354.fixed.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The chat approval dock and the friends settings panel no longer keep a poll timer in a hidden tab: both polls go through `pollWhileVisible`, so a hidden tab makes no read and holds no timer, a tab that comes back reads once at once and restarts the cadence from that read, and the panel — which had no visibility listener — now catches up on return instead of waiting out the rest of its period. The visible cadence and everything on screen are unchanged.

‎docs/subsystems/social.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Creating a group opens its Session with zero turns, and the host draws no sessio
128128
- The paused-chat card's 5 s `social/paused` read and the connecting page's 2 s `social/server` read are the same rule (#3327): both go through `pollWhileVisible`, so a hidden tab makes no call, coming back reads once at once and restarts the cadence from that read, and unmount removes the listener. Nothing on screen changes; only when the reads happen while hidden.
129129
- The peer-thinking row's 2 s `social/typing` read follows the same rule: `pollWhileVisible`, so a hidden tab makes no call, 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.
130130
- The face-rooms page's 5 s `social/face-rooms` read is the same rule once more: `pollWhileVisible`, so a hidden tab makes no call (not even the mount read), coming back reads once at once and restarts the 5 s cadence from that read, and unmount removes the listener. The visible cadence is unchanged, and nothing on screen changes.
131+
- The chat approval dock's 5 s `social/status` + `approvals` poll and the friends settings panel's 15 s `social/status` poll are the same rule (#3354): both go through `pollWhileVisible`, so a hidden tab makes no call (not even the mount read) and holds no timer, coming back reads once at once and restarts the cadence from that read, and unmount removes the listener. The panel gains the catch-up read it did not have; the visible cadence and everything on screen are unchanged.
131132
- A plain human line in an open face-to-face room is logged and fanned out once, and starts a single pass of every local Bot (admin first, capped at 6, no @ needed; #287, #295; core `openingSpeakers`, see [core-host](core-host.md)). Since #299 the Bots pick the responder from a plain line (they may `[PASS]`; the first Bot that answers ends the round unless the line is to everyone; the first Bot answers if all pass on the owner's own line), and a line to everyone or `@all` is unchanged. A friend's attested plain line (or `@all`) starts the same pass on this home, routed and single like the owner's own line (#462) (the plugin passes `attested: true` to `postHuman` only for a stamped line); an attested line that names Bots starts only the Bot(s) it names by the label the picker shows (`Friend's Chief`) or by handle; `plugins/social/test` has the two-home case. **Explicit mention list (#293):** the sender's host resolves the picker's labels against the room (`faceMentions().handles`; core `onFaceLine(fn)` passes `{ mentions }` for the owner's typed line) and `faceApi.send` puts the handles in `mentions` next to `typed_by_owner` only when `GET /v1/platform` `features` lists `mentions` (the one feature probe, `serverMentions()`); never on the legacy envelope, Bot lines or an older server. The receiver reads `mentions` (`cleanMentions`, at most 8 handles) only from a line the server attests `typed_by_owner` (`renderFaceEvent`), and `postHuman` resolves the handles against the room first (`mentionedByHandle`): only my own Bots in the list answer; a list naming nobody the room knows, or no list, falls back to the label/name reading above. The composer's `@` picker inserts the label text, so the handles are derived from it at send, not tracked in the composer.
132133
- The encoded human line is bounded at 18 000 **code points**, not UTF-16 units (#2641): `encodeFaceHuman` cuts with the file's own `cutCodePoints`, the same 18 000-code-point budget `coSeatEnvelope` applies to an outgoing room-share line, so a person's line whose bound falls inside an emoji ends on a code-point boundary instead of storing a lone surrogate that the next UTF-8 write turns into `U+FFFD`.
133134
- A peer string that arrives from the far side of Bot Social is capped on **code points** too (#2693): `cleanText` (60, so a friend's Bot or owner display name), `safeName` (120, an attached file's name), `draftText` (800), the person label `grantPersonView` builds in `mcp-client.js` (60), and the error and invite lines the host caps. All of them cut with one `cutCodePoints` in `src/code-points.js`, which `social.js` still re-exports (#2581), so a value whose bound falls inside an emoji keeps the emoji whole instead of ending on a lone high surrogate that a stored setting, a remote session name or a cross-home payload would show as `U+FFFD`; a value already stored that way is left unchanged rather than migrated.

‎plugins/social/client.js‎

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,18 +2592,10 @@ window.__ModuleLoader__.load({
25922592
setListLoaded(true)
25932593
}, () => {})
25942594
}
2595-
useEffect(() => {
2596-
load()
2597-
if (typeof setInterval !== 'function') return undefined
2598-
const timer = setInterval(load, 5000)
2599-
timer?.unref?.()
2600-
// #3080: a tab that sat in the background catches up the moment it is shown, not one beat later
2601-
// (the same shape `everySecond` uses above).
2602-
const onShow = () => { if (typeof document === 'undefined' || !document.hidden) load() }
2603-
const doc = typeof document !== 'undefined' && typeof document.addEventListener === 'function' ? document : null
2604-
doc?.addEventListener('visibilitychange', onShow)
2605-
return () => { clearInterval(timer); doc?.removeEventListener('visibilitychange', onShow) }
2606-
}, [])
2595+
// #3080: a tab that sat in the background catches up the moment it is shown, and a tab nobody is
2596+
// reading keeps no timer: the poll goes through `pollWhileVisible` (the same shape `#3315` gave
2597+
// the other lists here).
2598+
useEffect(() => pollWhileVisible(load, 5000), [])
26072599
const session = { sessionId, roster, room, bot, handle: bot?.remote?.handle }
26082600
// The person who gets it (#418, #498), not the friend's Bot: a local hold already names the person.
26092601
const named = list => list.map((item) => {
@@ -3308,17 +3300,9 @@ window.__ModuleLoader__.load({
33083300
const dismissShareRequest = item => call('social/share-request-dismiss', { id: item.id }).then(applyStatus, e => setError(errorText(e)))
33093301
const dismissAccept = item => call('social/accept-notice-dismiss', { id: item.id }).then(applyStatus, e => setError(errorText(e)))
33103302
const askShareBack = item => call('social/ask-share-back', { botId: item.botId, to: item.from, noticeId: item.id }).then(applyStatus, e => setError(errorText(e)))
3311-
useEffect(() => {
3312-
loadApprovals()
3313-
if (typeof setInterval !== 'function') return undefined
3314-
const tick = () => {
3315-
if (typeof document !== 'undefined' && document.hidden) return
3316-
loadApprovals()
3317-
}
3318-
const timer = setInterval(tick, 15_000)
3319-
timer?.unref?.()
3320-
return () => clearInterval(timer)
3321-
}, [])
3303+
// A hidden tab is not looking at these requests either, so the 15 s poll runs only while the page
3304+
// is on screen and a tab that comes back reads once at once (`pollWhileVisible`).
3305+
useEffect(() => pollWhileVisible(loadApprovals, 15_000), [])
33223306
useEffect(() => facePanel.bind(mode => { setFaceMode(mode === 'start' ? 'start' : 'join'); setFaceOpen(true) }), [])
33233307
useEffect(() => addFriendPanel.bind(() => setAdding(true)), [])
33243308
const unavailable = String(error).startsWith('Social is not running:')

0 commit comments

Comments
 (0)