- Add unreadInfoRef in RoomTimeline; remove unreadInfo from useLiveEventArrive
callback deps and LocalEchoUpdated effect deps to stop per-message listener churn
- Fix CallEmbed .bind(this) leak: bind handlers once in start(), push cleanup to
disposables so dispose() correctly removes all listeners
- Add stable refs in useCallSignaling for mutedRoomId/ring callbacks; tighten
effect deps to [mx, mDirects, setMutedRoomId] to prevent SessionEnded listener
accumulation during sync retry cycles
useLiveEventArrive, useRelationUpdate, useLiveTimelineRefresh, and
useThreadUpdate each passed their callback argument into the useEffect
dependency array. This caused the listener to be removed and re-added
every time the callback identity changed (e.g. when unreadInfo toggled
or when any other parent-scope value included in the useCallback deps
changed).
Under normal conditions React's synchronous effect cleanup guarantees
one listener at a time. But during sliding-sync error/retry cycles the
client emits MaxListenersExceededWarning (11 session_ended, 51
RoomState.events) confirming that listeners accumulate. When the
callbacks change fast enough — or React defers cleanup in concurrent
mode — multiple handleTimelineEvent instances are live simultaneously.
Each one independently calls setTimeline({ range: start+1, end+1 }) for
the same arriving event, producing the spurious scroll jumps reported.
Fix: use the stable callback ref pattern in all four hooks.
- Add a ref (onArriveRef / onRelationRef / onRefreshRef / onUpdateRef)
- Assign ref.current = callback on every render (always up-to-date)
- Remove the callback from the useEffect dep array (effect runs only
when `room` changes)
- Inside handlers, delegate via ref.current() instead of the captured
closure value
The event listener identity is now stable for the entire lifetime of
each room mount. Listener counts stay at 1 regardless of how many
re-renders occur or how many sync error/retry cycles fire.
When a sliding-sync limited response fires RoomEvent.TimelineReset (or
the app fires RoomEvent.TimelineRefresh) the useLiveTimelineRefresh
callback was unconditionally calling setAtBottom(true) and incrementing
scrollToBottomRef, scrolling the user to the bottom even if they had
scrolled up to read history.
Three coordinated changes:
1. Add RoomEvent.TimelineReset handler to useLiveTimelineRefresh.
The SDK emits TimelineReset on the EventTimelineSet (not the Room)
when a limited sync response replaces the live EventTimeline. Without
this listener the stored linkedTimelines reference the old detached
chain; back-pagination silently no-ops, freezing the room.
2. Gate the viewport scroll on atBottomRef.current (prior position).
Capture wasAtBottom before calling setTimeline(getInitialTimeline).
Only call setAtBottom(true) and increment scrollToBottomRef when the
user was already at the bottom. When scrolled up we still reinit the
timeline (the old chain is gone) but avoid the forced scroll.
3. Add timelineJustResetRef to allow the self-heal effect to run when
atBottom=false after a reset. The SDK fires TimelineReset before
populating the fresh timeline, so getInitialTimeline sees range.end=0.
Without the atBottom guard bypass the range stays at {0,0} as events
arrive, leaving the virtual paginator rendering nothing. The ref is
cleared on first successful heal, after which normal atBottom-gated
behaviour resumes.
- Use "globalThis" instead of "window", "self", or "global" (typescript:S7764)
- Unicode-aware string methods should be used for proper character handling (typescript:S7758)
- Strings should use "replaceAll()" instead of "replace()" with global regex (typescript:S7781)
- Existence checks should use ".includes()" instead of ".indexOf()" or ".lastIndexOf()" (typescript:S7765)
- Use "globalThis" instead of "window", "self", or "global" (typescript:S7764)
- Built-in constructors should be called consistently with or without "new" (typescript:S7723)
- Negated conditions should be avoided when an else clause is present (typescript:S7735)
- Strings should use "replaceAll()" instead of "replace()" with global regex (typescript:S7781)
- Use ".some()" instead of ".filter().length" checks or ".find()" for existence testing (typescript:S7754)
- React props should be read-only (typescript:S6759)
- Number static methods and properties should be preferred over global equivalents (typescript:S7773)
- The return value of "useState" should be destructured and named symmetrically (typescript:S6754)
- Optional chaining should be preferred (typescript:S6582)
- Arrays used only for existence checks should be Sets (typescript:S7776)
- Unicode-aware string methods should be used for proper character handling (typescript:S7758)
- Number static methods and properties should be preferred over global equivalents (typescript:S7773)
- Function references should not be passed directly to iterator methods (typescript:S7727)
- Strings should use "replaceAll()" instead of "replace()" with global regex (typescript:S7781)
- "RegExp.exec()" should be preferred over "String.match()" (typescript:S6594)
- React props should be read-only (typescript:S6759)
- Prefer `Math.min()` to simplify ternary expressions (typescript:S7766)
- Optional property declarations should not use both '?' and 'undefined' syntax (typescript:S4782)
- Built-in constructors should be called consistently with or without "new" (typescript:S7723)