Skip to content

fix: keep public room in LHN for anonymous users#93054

Open
yusufdeveloper2903 wants to merge 6 commits into
Expensify:mainfrom
yusufdeveloper2903:fix/92672-public-room-anon-visibility
Open

fix: keep public room in LHN for anonymous users#93054
yusufdeveloper2903 wants to merge 6 commits into
Expensify:mainfrom
yusufdeveloper2903:fix/92672-public-room-anon-visibility

Conversation

@yusufdeveloper2903

Copy link
Copy Markdown
Contributor

Explanation of Change

An anonymous session can only ever access public rooms, and such a room's notification preference defaults to hidden. In the LHN filter (shouldDisplayReportInLHN in SidebarUtils), a hidden report only survives when one of the shouldOverrideHidden conditions is true — and for an anonymous user the only one that ever applied was isFocused. So the public room stayed in the Inbox only while it was the focused report. The moment the anon user opened a thread inside the room, the thread became the focused report, the public room was no longer focused, isHidden && !shouldOverrideHidden became true, and the room was dropped from the Inbox — collapsing it to the "Woohoo! All caught up" empty state and leaving the anon user unable to return to the room.

This PR adds a new shouldOverrideHidden condition so a public room is never hidden from an anonymous user's LHN just because it isn't the focused report:

(isPublicRoom(report) && isAnonymousUser())

This pairs isPublicRoom with isAnonymousUser() exactly the way ReportUtils already gates anon-only public-room behaviour elsewhere (e.g. canLeaveChat). It is a display-only predicate — it does not mutate any report/Onyx data or notification preference — so there are no side effects on unread/GBR or leave-room logic. After sign-in isAnonymousUser() becomes false, the override no longer applies, and the existing flow (#91931) re-fetches the room with a real notification preference, so there is no regression and no double-handling.

Fixed Issues

$ #92672
PROPOSAL: #92672 (comment)

Tests

  1. Log out of the app so you are an anonymous user.
  2. Open a public room as the anonymous user (e.g. open the public room deep link / URL …/r/<publicRoomID>).
  3. Verify the public room appears in the Inbox/LHN.
  4. Inside the public room, open a thread (tap a message that has replies, e.g. "1 Reply").
  5. Verify the public room remains in the Inbox/LHN and the Inbox does not collapse to the "Woohoo! All caught up" empty state.
  6. Tap the public room in the LHN and verify you can navigate back to it.
  7. Sign in and verify the Inbox/LHN still behaves normally (no duplicate or stuck public room).
  • Verify that no errors appear in the JS console

Offline tests

This change is a purely client-side display predicate, so it behaves identically offline.

  1. As an anonymous user, open a public room and confirm it shows in the Inbox/LHN.
  2. Turn off your network connection.
  3. Open a thread inside the public room.
  4. Verify the public room is still present in the Inbox/LHN while offline.

QA Steps

  1. On staging, log out so you are an anonymous user.
  2. Open this public room link as the anonymous user: https://staging.new.expensify.com/r/1540486774487195
  3. Verify the public room appears in the Inbox.
  4. Open a thread inside the public room (tap a message with replies).
  5. Verify the public room remains in the Inbox and you do not see the "Woohoo! All caught up" empty state.
  6. Verify you can still navigate back to the public room from the Inbox.
  • 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 followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • 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 a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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

Before fix:

Before-fix-android.mp4

After fix:

After-fix-android.mp4
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

Before fix:

Before-fix.Chrome-mac.mp4

After fix:

After-fix.Chrome-mac.mp4

@melvin-bot

melvin-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

@brunovjk 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 removed request for a team June 9, 2026 11:47
@yusufdeveloper2903 yusufdeveloper2903 force-pushed the fix/92672-public-room-anon-visibility branch 2 times, most recently from 47d8ddf to 375edfe Compare June 9, 2026 15:51

@joekaufmanexpensify joekaufmanexpensify left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good for product

@brunovjk

Copy link
Copy Markdown
Contributor

I can still reproduce the original bug:

Screen.Recording.2026-06-11.at.11.57.48.mov

@yusufdeveloper2903, did everything work out in your tests? Thank you.

@yusufdeveloper2903

Copy link
Copy Markdown
Contributor Author

Hi @brunovjk, thanks again for catching this and for your patience! You were right that the bug was still reproducible — but only in a specific scenario that the original fix didn't cover. I dug deep into it and pushed additional commits. Here's the full picture:

What the original fix covered (and what it missed)

The first commit (isPublicRoom && isAnonymousUser in SidebarUtils) is the display half — it keeps a public room visible in an anonymous user's LHN even when it isn't the focused report. This correctly fixes the web and warm app flows (room already loaded → open a thread → room stays).

But it didn't fix the cold native flow (fresh app / cleared data → tap the public room link), which is exactly what QA reported. The reason: in that flow the public room never reaches Onyx at all, so there's nothing for the LHN filter to display.

Root cause of the cold-native flow (verified with logs + Onyx inspection)

Tracing it on a device, the sequence is:

  1. The deep link fires OpenReport for the public room → succeeds (200), room is written to Onyx, anonymous session is created. ✅
  2. Creating the anonymous session triggers OpenApp, which loads the anonymous account's default reports and drops the public room from Onyx. ❌
  3. Navigation waits for the (now-missing) report, so the room never appears → empty "Woohoo! All caught up." Inbox.

I confirmed the room was genuinely absent from Onyx at that point (not just hidden), which is why no display-only change could fix it. There was also a secondary The action 'NAVIGATE' ... was not handled by any navigator console error in this flow.

What the new commits do

  1. DeepLinkHandler — re-fetch the public room after OpenApp (the data half): once the anonymous OpenApp settles, if the deep-linked public room went missing, we re-openReport it so it lands back in Onyx. Combined with the original LHN fix, it then shows in the Inbox.
  2. subscribe.ts — guard against the premature navigation: for an unauthenticated session we no longer dispatch the report deep link to react-navigation (the Report screen isn't mounted under PublicScreens); openReportFromDeepLink already handles anonymous navigation. This removes the NAVIGATE ... was not handled console error.

So the three pieces are complementary: load the room (refetch) → keep it visible (LHN override) → no console error (nav guard).

Verification

I tested the exact cold-native repro from the issue (cleared app data → tapped the public room link as an anonymous user). The public room now appears in the Inbox and the console error is gone. Video below:

REC-20260612161320.mp4

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/libs/SidebarUtils.ts 80.38% <100.00%> (+0.02%) ⬆️
src/DeepLinkHandler.tsx 86.53% <93.75%> (+3.20%) ⬆️
src/libs/Navigation/linkingConfig/subscribe.ts 20.00% <0.00%> (-3.08%) ⬇️
... and 13 files with indirect coverage changes

@brunovjk

brunovjk commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • 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 a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
93054_android_native.mov
Android: mWeb Chrome
93054_android_native.mov
iOS: HybridApp
93054_ios_native.mov
iOS: mWeb Safari
93054_ios_web.mov
MacOS: Chrome / Safari
93054_web_chrome.mov

@brunovjk

Copy link
Copy Markdown
Contributor

Thanks for the update @yusufdeveloper2903, everything seems fine now, do you think we managed to increase the cover test here? Another thing, we have a warning related to DeepLinkHandler, were we able to fix it? Thank you

@yusufdeveloper2903 yusufdeveloper2903 force-pushed the fix/92672-public-room-anon-visibility branch from 0a220fc to 139874b Compare June 13, 2026 09:29
@yusufdeveloper2903

Copy link
Copy Markdown
Contributor Author

Thanks @brunovjk!

Coverage: Good call - I've added unit tests to cover the new logic:

  • tests/unit/SidebarUtilsTest.ts covers the new shouldDisplayReportInLHN predicate: a hidden public room stays in the LHN for an anonymous user even when it isn't the focused report, is still dropped for an authenticated user, and the override doesn't leak to non-public rooms.
  • tests/unit/DeepLinkHandlerTest.tsx covers the cold-start refetch effect: an anonymous user deep-linking into a public room that's missing from Onyx triggers a refetch once OpenApp settles, while it's a no-op when the room is already present or the user is authenticated.

Warning: The only console warning I see is The result of getSnapshot should be cached to avoid an infinite loop. This isn't introduced by this PR - it comes from the existing useOnyx(COLLECTION.REPORT) / NVP_ONBOARDING selector subscriptions that already exist on main (this PR only added an IS_LOADING_APP boolean read plus an effect, neither of which triggers it). It's the known useOnyx / useSyncExternalStore warning.

The error that was part of this flow - The action 'NAVIGATE' ... was not handled by any navigator - is now gone thanks to the subscribe.ts guard (verified on the cold native repro).

Happy to report the getSnapshot warning in Slack per the checklist rather than widen this PR's scope - let me know if you'd prefer I tackle it here.

@brunovjk

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 7cb05ebac7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@melvin-bot melvin-bot Bot requested a review from MonilBhavsar June 15, 2026 15:13
@yusufdeveloper2903

Copy link
Copy Markdown
Contributor Author

Hi @brunovjk 👋

Besides the main bug, I also fixed a separate issue in this PR: on web, after opening a public room, going back to Home, reloading, and returning to the Inbox — the public room would disappear from the LHN. This PR fixes that too.

Commit: bebb427

Should we keep it here or split it into its own PR?

Before fix:

605054097-ff9c7219-b877-4979-815f-86f3b8cd6663.mp4

After fix:

After-fix.Chrome-mac.mp4

Comment thread src/DeepLinkHandler.tsx
Comment thread src/DeepLinkHandler.tsx Outdated
@yusufdeveloper2903

yusufdeveloper2903 commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

Hi @MonilBhavsar! 👋 Both points are in 9200c00 now. I pulled the duplicated tracking code out into a shared trackPendingPublicRoomFromDeepLink helper, and the ref is reset as soon as the room shows up in Onyx — so the effect no longer keeps firing on every report update. No change to the actual fix flow, and the existing tests are still green. Let me know if you'd like anything else! 🙏

@MonilBhavsar

Copy link
Copy Markdown
Contributor

@brunovjk mind taking a look at this comment #93054 (comment)

@brunovjk

Copy link
Copy Markdown
Contributor

Sure, I'll check it ASAP; I'm a bit busy with other PRs. Thanks.

@brunovjk

brunovjk commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Sorry for the delay. I checked it, and this web fix is closely related to the same LHN/public-room issue, so I think we should keep it in this PR.

cc: @yusufdeveloper2903 @MonilBhavsar

@MonilBhavsar

Copy link
Copy Markdown
Contributor

There are conflicts to resolve @yusufdeveloper2903

yusufdeveloper2903 and others added 5 commits July 3, 2026 15:39
An anonymous session can only access public rooms, whose notification
preference defaults to `hidden`. Previously a public room only survived
the LHN filter while it was the focused report, so opening a thread inside
the room (which steals focus) dropped the room from the Inbox, leaving the
anon user unable to return to it.

Add an override in `shouldDisplayReportInLHN` so a public room stays in the
LHN for anonymous users regardless of focus, mirroring how ReportUtils
already gates anon-only public-room behaviour (e.g. canLeaveChat).

Fixes Expensify#92672

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@yusufdeveloper2903 yusufdeveloper2903 force-pushed the fix/92672-public-room-anon-visibility branch from 9200c00 to aba48a9 Compare July 3, 2026 10:59
@yusufdeveloper2903

Copy link
Copy Markdown
Contributor Author

@MonilBhavsar rebased onto latest main and fixed the conflicts (imports only, no logic changes). All checks pass and it's mergeable now — ready for re-review

@MonilBhavsar

Copy link
Copy Markdown
Contributor

Oxfmt check / Oxfmt check (pull_request) seems to be failing

@yusufdeveloper2903

Copy link
Copy Markdown
Contributor Author

@MonilBhavsar the failing test job 7 is an unrelated flaky test (SubscriptionUtils isUserOnFreeTrial, date-based) — not touched by this PR. A re-run should clear it

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.

4 participants