Skip to content

[NoQA] Fix import/no-cycle - part 17 - #103190

Open
LukasMod wants to merge 11 commits into
Expensify:mainfrom
callstack-internal:fix/no-cycle-part17-reportutils-anonymous-session
Open

LukasMod wants to merge 11 commits into
Expensify:mainfrom
callstack-internal:fix/no-cycle-part17-reportutils-anonymous-session

Conversation

@LukasMod

@LukasMod LukasMod commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

  • findLastAccessedReport, getMostRecentlyVisitedReport and canLeaveChat now take isAnonymousUser: boolean as a parameter instead of reading the anonymous-session flag from module state. This drops the ReportUtils to actions/Session import edge (no-cycle part 17).
  • Callers pass the flag in: React pages and hooks use a new useIsAnonymousUser hook (reads session.authTokenType); the non-React caller in actions/Link.ts passes isAnonymousUser() from actions/Session directly. Same value as before, just supplied by the caller.
  • navigateAfterOnboarding, navigateAfterOnboardingWithMicrotaskQueue and getReportIDAfterOnboarding thread the new parameter through to findLastAccessedReport.
  • On the Details page the anonymous flag is used in ReportDetailsMenuLeaveItem (the leave-room row, extracted into its own component on main): it feeds canLeaveChat and the post-leave findLastAccessedReport lookup.

This branch removes 14 import/no-cycle errors in src: 142 -> 128

Fixed Issues

$ #99650
PROPOSAL:

Tests

  • Verify that no errors appear in the JS console

Test 1: Signed-in user in the same room (smoke)

My test public room:

iOS: xcrun simctl openurl booted "new-expensify://r/6574590506765394"
Android: adb shell am start -W -a android.intent.action.VIEW -d "new-expensify://r/6574590506765394" com.expensify.chat.dev

  1. Sign in with an account that is a member of the public room (create a new one so you can be a member).
  2. Open the room from the LHN.
  3. Confirm the header menu shows "Leave"

Test 2: Anonymous visitor in a public room (smoke)

  1. Sign out, or open an incognito window.
  2. Open the public room link.
  3. Confirm the room loads and shows its messages instead of a not-found page.
  4. Open the room header menu.
  5. Confirm there is no "Leave" option.

Offline tests

QA Steps

  • 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 there are no new alerts related to the canBeMissing param for useOnyx
  • 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
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • 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
android.mov
Android: mWeb Chrome
android.web.mov
iOS: Native
ios.mov
iOS: mWeb Safari
ios.web.mov
MacOS: Chrome / Safari
web.mov

@LukasMod
LukasMod force-pushed the fix/no-cycle-part17-reportutils-anonymous-session branch from 04497b5 to 643c5a9 Compare October 7, 2026 06:49
@LukasMod

LukasMod commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Code review

Looks good to merge. I found no blocking issues. The refactor keeps behavior the same, adds no new import cycle, and every CI check passes except the expected Check independent approval.

What I checked

  • Same data source: the new CurrentUserStore.isAnonymousUser compares session.authTokenType to ANONYMOUS. That matches the no-arg path of Session.isAnonymousUser. All 3 call sites in ReportUtils used the no-arg form, so the switch is safe.
  • No new cycle: CurrentUserStore now imports CONST. Log already pulls in CONST through getPlatform, so Log and NetworkStore gain no new dependencies.
  • Tests: the new canLeaveChat pair covers both the anonymous and non-anonymous cases, so the test proves the anonymous check is what blocks leaving.

Nits (optional)

  1. The PR description says the old value came from Onyx.connectWithoutView. It actually came from Onyx.connect. Both read ONYXKEYS.SESSION, so behavior is unchanged. Only the wording is off.
  2. Both describe blocks in CurrentUserStoreTest.ts repeat the same beforeAll(Onyx.init) and beforeEach(Onyx.clear). You could move them to the top level.
  3. Two exported functions are now named isAnonymousUser, one in CurrentUserStore and one in actions/Session. You could make the no-arg path in Session delegate to CurrentUserStore, so only one copy of the session data stays in sync. That can wait for a follow-up.

I didn't run the manual test steps.


view run

@LukasMod
LukasMod force-pushed the fix/no-cycle-part17-reportutils-anonymous-session branch from e443b16 to 7ff2fae Compare October 7, 2026 11:41
@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/hooks/useAutoCreateTrackWorkspace.ts 87.17% <100.00%> (+0.33%) ⬆️
src/hooks/useFindLastAccessedReport.ts 100.00% <100.00%> (ø)
src/libs/ReportUtils.ts 88.54% <100.00%> (ø)
src/libs/navigateAfterOnboarding.ts 91.89% <100.00%> (+0.11%) ⬆️
...eportDetailsPage/ReportDetailsTaskDeleteAction.tsx 100.00% <100.00%> (ø)
...gPersonalDetails/BaseOnboardingPersonalDetails.tsx 89.47% <100.00%> (+0.09%) ⬆️
...rdingPrivateDomain/BaseOnboardingPrivateDomain.tsx 90.90% <100.00%> (+0.07%) ⬆️
.../pages/OnboardingPurpose/BaseOnboardingPurpose.tsx 90.72% <100.00%> (+0.09%) ⬆️
.../OnboardingWorkspaces/BaseOnboardingWorkspaces.tsx 92.94% <100.00%> (+0.04%) ⬆️
src/hooks/useCompleteOnboarding.ts 0.00% <0.00%> (ø)
... and 2 more
... and 12 files with indirect coverage changes

@LukasMod

LukasMod commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Code review (updated approach)

Looks good to merge. I found no blocking issues. The new version passes isAnonymousUser in from callers, which removes the ReportUtils → actions/Session import entirely. CI is green except the expected Check independent approval.

What I checked

  • Every caller is updated. I found all callers of canLeaveChat, findLastAccessedReport, getMostRecentlyVisitedReport and the 3 navigateAfterOnboarding* helpers in src/ and tests/. Each passes the new flag in the correct position.
  • Same value as before. React callers use the existing useIsAnonymousUser, which reads the same session.authTokenType. Link.ts:604 still calls Session.isAnonymousUser(), which it already imported.
  • Tests: the new getMostRecentlyVisitedReport test and the canLeaveChat pair cover both values of the flag.

Nits (optional)

  1. Two booleans in a row. canLeaveChat now takes isAnonymousUser followed by isReportArchived. findLastAccessedReport takes isAnonymousUser followed by openOnAdminRoom. A call written for the old signature, such as canLeaveChat(report, policy, id, isArchived), still type-checks but passes the archived flag as isAnonymousUser. No current caller does this. Watch for it in open PRs that merge after this one.
  2. The moved test "should return false if the chat is public room and the user is the guest" has no // Given / When / Then comments. The new "should return false for that public room when the user is anonymous" test covers the same case, so you could delete the older one.

My earlier review covered the CurrentUserStore version. Those nits no longer apply. I didn't run the manual test steps.


view run

@LukasMod

LukasMod commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Kept the old test and folded the new one into it: it now has Given/When/Then and a participant, so it fails if the anonymous check is removed

@LukasMod
LukasMod marked this pull request as ready for review October 7, 2026 12:09
@LukasMod
LukasMod requested review from a team as code owners October 7, 2026 12:09
@melvin-bot
melvin-bot Bot requested review from thelullabyy and trjExpensify and removed request for a team and trjExpensify October 7, 2026 12:09
@melvin-bot

melvin-bot Bot commented Oct 7, 2026

Copy link
Copy Markdown

@thelullabyy 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 the request for review from a team October 7, 2026 12:09
…ule session

Thread the anonymous-user flag through findLastAccessedReport,
getMostRecentlyVisitedReport, canLeaveChat and navigateAfterOnboarding from
their callers (via useIsAnonymousUser hook) instead of importing the
anonymous-session check from actions/Session. Removes the now-unused
isAnonymousUser helper from CurrentUserStore.
@LukasMod
LukasMod force-pushed the fix/no-cycle-part17-reportutils-anonymous-session branch from 6c84dea to 657b6bd Compare October 8, 2026 06:35
…eportutils-anonymous-session-v1

# Conflicts:
#	src/libs/ReportUtils.ts
…eportutils-anonymous-session-v1

# Conflicts:
#	src/libs/navigateAfterOnboarding.ts
#	src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx
#	src/pages/OnboardingPrivateDomain/BaseOnboardingPrivateDomain.tsx
#	src/pages/OnboardingWorkspaces/BaseOnboardingWorkspaces.tsx
#	tests/unit/navigateAfterOnboardingTest.ts
@LukasMod

Copy link
Copy Markdown
Contributor Author

@thelullabyy kind bump here

…eportutils-anonymous-session-v1

# Conflicts:
#	src/libs/navigateAfterOnboarding.ts
#	src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx

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.

2 participants