fix: message deep links (`?msg=`) reload loop when jumping to an old message

Merged
RI
2mo ago
+199-39

Proposed changes (including videos or screenshots)

Opening a message deep link (?msg=<id>) to a message far from recent history flashes the target, then keeps loading until it hits the server rate limit (429) and the room reloads.

On a ?msg= open, two loads compete over the same message store: RoomProvider prefetches recent history, and the jump loads the surrounding window. The surrounding load calls clear() (which resets loaded), so RoomProvider re-fires recent and clobbers the window — which re-triggers the surrounding load → 429.

Fix (2 files):

  • RoomProvider — skip the recent-history prefetch while ?msg= is set, so the surrounding-window load owns the initial load (removes the competing load / the race).
  • RoomHistoryManager — re-assert isLoading right after clear() in loadSurroundingMessages, so the surrounding load isn't re-fired into the brief empty-store gap clear() opens before the messages are upserted.

Result: a ?msg= open does a single surrounding-window load and opens positioned on the message. Normal opens (no ?msg=) are unchanged.

Issue(s)

Steps to test or reproduce

  1. Pick a message far from the bottom of a busy channel, copy its link (?msg=<id>).
  2. Open it in an incognito window (empty cache is required — a warm cache hides the bug).
  • Before: target flashes in, then loads keep firing → 429 / reload.
  • After: opens positioned on the target and stays.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed message links that could trigger repeated reloads when opening older messages.
    • Rooms now remain focused on the selected message without hitting rate limits.
    • Improved navigation to messages within threads, including loading surrounding context when needed.
    • Corrected loading indicators while message history is being fetched.