Skip to content

fix: preserve cached chat scroll position on reconnect - #106687

Open
chrispader wants to merge 4 commits into
Expensify:mainfrom
margelo:@chrispader/fix/reconnect-scroll-preservation
Open

chrispader wants to merge 4 commits into
Expensify:mainfrom
margelo:@chrispader/fix/reconnect-scroll-preservation

Conversation

@chrispader

@chrispader chrispader commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

When a cached chat opens offline, reconnecting can replace its messages with a loading skeleton and reset its scroll position. I keep the displayed list mounted while app and report refreshes finish. This fix works with the existing FlashList and is independent of the LegendList migration.

Explanation of Change

Once cached messages have been shown, I keep their list mounted while app and report refreshes finish. Initial online loads still wait for the data they need.

Fixed Issues

$ #98994

PROPOSAL: N/A

Tests

Use a chat with enough history to scroll.

  1. Open the chat while online. Its messages should appear after initial loading.
  2. Scroll to an older message.
  3. Open another chat.
  4. Return to the first chat. Its messages should appear without a loading flash.
  • Verify that no errors appear in the JS console

Offline tests

  1. Open a chat with cached history.
  2. Enable Force offline in Troubleshoot.
  3. Return to the chat.
  4. Scroll to an older message.
  5. Disable Force offline in Troubleshoot.
  6. Return to the chat. The same messages should remain visible while loading finishes, without a skeleton or a scroll reset.
  7. Disconnect again while the refresh is pending. Cached messages should remain readable.
  8. Reconnect. The refresh should finish without moving the message being read.

QA Steps

Repeat Tests and Offline tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

Return online while reading older cached messages.

Before:

Screen.Recording.2026-11-13.at.12.44.07.mov

After:

Screen.Recording.2026-11-13.at.12.29.45.mov

🤖 Generated with Codex

Keep displayed offline actions ready while queued app and report loads finish. This prevents loading skeletons and the first successful response from recreating the list and resetting its viewport.

Co-authored-by: Codex <noreply@openai.com>
@chrispader
chrispader marked this pull request as ready for review November 12, 2026 12:41
@chrispader
chrispader requested review from a team as code owners November 12, 2026 12:41
@melvin-bot
melvin-bot Bot requested review from dmkt9 and removed request for a team November 12, 2026 12:41
@melvin-bot

melvin-bot Bot commented Nov 12, 2026

Copy link
Copy Markdown

@dmkt9 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot requested review from flaviadefaria and removed request for a team November 12, 2026 12:41
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T13:00:43.920871Z dc9fcd5 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc9fcd5490

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Before the first successful load, a missing loading-state entry means ReportFetchHandler has not
// enqueued OpenReport yet. Once a terminal failure writes false, the stored state releases the gate.
const shouldKeepInitialReportLoadGated = isReportLoadPending || (!hasOnceLoadedReportActions && isLoadingInitialReportActions !== false);
const shouldKeepInitialReportLoadGated = !hasOnceLoadedReportActions && (isReportLoadPending || isLoadingInitialReportActions !== false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the pending gate on a fresh online report mount

When an unread report is reopened online after an earlier successful visit in the same session, hasOnceLoadedReportActions is already true even though this is a new list mount. If only the newest action is cached—for example, after report-action cache eviction—this change skips the pending OpenReport gate and initializes the list before the older unread messages arrive. useReportActionsListScroll also omits the unread anchor from listID while this flag is true, so the response cannot remount the list to apply its first-unread scroll position; the viewport remains at the newest cached message instead. Suppress the pending gate only when the current list has actually been displayed, rather than using the session-wide successful-load flag as that indication.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chris's AI understudy stepping in. 🤖

Good catch, fixed in 1460697. The guard now tracks whether it has already displayed the list since it mounted, and only that skips the pending OpenReport gate and the app-load skeleton. A new mount of an unread report waits for OpenReport again, like on main, even if the report loaded earlier in the session. A list that is already on screen still stays mounted when queued loads resume after reconnecting.

chrispader and others added 3 commits November 13, 2026 11:44
Reconnecting removed the skeleton that holds the space of unloaded history before the older actions arrived. The list shrank, the browser clamped the scroll position, and the messages being read jumped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reconnect fix skipped the OpenReport and app-load gates whenever the report had loaded earlier in the session. A new mount of an unread report with only its newest action cached then opened at that action instead of the first unread one. Only a list this guard has already displayed now skips those gates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant