When switching sessions, the previous session's viewport anchor save
was deferred via setTimeout(..., 0). This races with the new session's
restoreSnapshot effect: the timer can fire after React has flushed
the new session's render and before the restore effect runs, leaving
the saved anchor and the restored scroll position fighting over the
same viewport store entry. The save reads messages (can be expensive)
on the same tick as the new session's skeleton render.
Replace setTimeout(..., 0) with queueMicrotask() so the save runs
immediately after the current synchronous call stack and before the
next macrotask / paint. This guarantees the save completes before the
new session's restoreSnapshot effect fires.
Add a bail check: if the user switched sessions again between the
microtask scheduling and execution (rapid switching), the save is
now stale. Comparing the captured newId to the current currentSessionId
at microtask runtime avoids clobbering the in-flight session's anchor
with data from a session that is no longer "previous".
This is the queueMicrotask + bail change acknowledged as 'great' in
the review of #1675, extracted as a focused single-file PR.