Skip to content

[No QA] Add a new lint rule that blocks onyx loading status check - #104729

Open
VickyStash wants to merge 9 commits into
Expensify:mainfrom
callstack-internal:VickyStash/refactor/104583-onyx-loading-lint-rule
Open

VickyStash wants to merge 9 commits into
Expensify:mainfrom
callstack-internal:VickyStash/refactor/104583-onyx-loading-lint-rule

Conversation

@VickyStash

@VickyStash VickyStash commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

This PR adds a lint rule that prevents new code from depending on the per-key loading status of useOnyx while we remove existing usages in batches.

The rule flags:

  • imports of isLoadingOnyxValue
  • reads of status from a useOnyx result

LocaleContextProvider and HybridAppHandler are exempt, because they mount before Onyx finishes loading and still need the startup status. Tests are exempt too. They get cleaned up together with the code they cover.

Existing usages are added to the seatbelt baseline, so current code keeps passing lint.

Fixed Issues

$ #104583
PROPOSAL: N/A

Tests

  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • 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 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 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)
  • 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)
  • 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 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.

@VickyStash

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Review

The rule works for the main patterns. CI lint passes, and the new seatbelt entries line up with the existing usages I spot-checked. I found one gap that's worth fixing before merge, and two smaller ones.

1. Aliased useOnyx imports are not checked. The rule only matches a callee named exactly useOnyx (no-onyx-loading-status.js:92). About 10 files import {useOnyx as useOnyxWithoutSnapshots} from 'react-native-onyx', for example useCreateReport.tsx:19. This code passes lint today:

const [policies, policiesMetadata] = useOnyxWithoutSnapshots(ONYXKEYS.COLLECTION.POLICY);
if (policiesMetadata.status === 'loading') {...}

Fix: in ImportDeclaration, record the local name of any useOnyx specifier (from react-native-onyx or @hooks/useOnyx). Then match the callee against that set. Add an invalid test case for the alias.

Smaller gaps (optional)
  • Wrapper hooks that return ResultMetadata. useCardFeeds, useCardsList, useCardsLists, and useCompanyCards pass useOnyx metadata through. Today every caller reads it through isLoadingOnyxValue, so the import check catches it. A direct allFeedsResult.status read would not be flagged. You could note this in the rule docs, or change these hooks' return types as part of the cleanup batches.
  • Default value in a destructuring pattern. const [x, {status} = {}] = useOnyx(key) is not caught, because findStatusProperty only handles ObjectPattern, not AssignmentPattern. This is rare, so it's fine to skip.

Everything else looks good. The exemption block comes after the main rules block, so the override applies, and the Promise.allSettled and fetch cases are correctly treated as valid.


view run

@VickyStash

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Re-review

The alias fix in Check aliased useOnyx imports works. The rule now tracks the local name of any named useOnyx import and any default import from hooks/useOnyx. Both new invalid tests cover it. All CI checks pass except Check independent approval, so the seatbelt baseline still matches. I have no blocking issues left.

Nits (optional)
  • Removed test comments. The commit removed the comments that explained why the Promise.allSettled, fetch, and type-only import cases are valid (NoOnyxLoadingStatusRuleTest.ts:47-50). They told the reader why these cases must not be flagged. Consider restoring them.
  • Relative default import with an alias. import useOnyxFoo from './useOnyx' inside src/hooks/ isn't tracked, because ./useOnyx doesn't end with hooks/useOnyx. No current file does this, since the hooks that import it relatively keep the name useOnyx. It's safe to skip.

view run

@VickyStash
VickyStash marked this pull request as ready for review October 23, 2026 10:42
@VickyStash
VickyStash requested a review from a team as a code owner October 23, 2026 10:42
@melvin-bot
melvin-bot Bot requested review from nkdengineer and removed request for a team October 23, 2026 10:42
@melvin-bot

melvin-bot Bot commented Oct 23, 2026

Copy link
Copy Markdown

@nkdengineer 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]

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T10:55:29.003218Z d2741d1 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: d2741d1807

ℹ️ 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".


describe('no-onyx-loading-status', () => {
tsRuleTester.run(ruleModule.name, ruleModule, {
valid: [

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add Given/When/Then rationale to every rule case

Each string under valid/invalid becomes an individual RuleTester test, but these new cases omit the mandatory // Given, // When, and // Then rationale (and the lone line 93 comment is not those sections). CLAUDE.md:81, which the root instructions designate as the repository testing guidance, requires all three for every test case, so annotate each case rather than leaving the table undocumented.

AGENTS.md reference: AGENTS.md:L3-L3

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.

Other lint tests have the same structure.

},

VariableDeclarator(node) {
if (node.id.type !== 'ArrayPattern' || node.init?.type !== 'CallExpression') {

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 Catch status reads from retained useOnyx tuples

When a caller keeps the tuple instead of destructuring it—for example, const result = useOnyx(key); if (result[1].status === 'loading') ...—node.id is an Identifier, so this guard returns without a report. That valid hook usage introduces the exact per-key status dependency this rule is intended to stop, allowing new migration debt and a later failure when status is removed; recognize assigned tuple/index reads rather than only ArrayPattern declarators.

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.

I haven't found any usage like this in the codebase:
result[1].status === 'loading'

So Im not sure it's really valid for us

Comment on lines +88 to +93
for (const specifier of node.specifiers) {
const isNamedUseOnyx = specifier.type === 'ImportSpecifier' && specifier.imported.type === 'Identifier' && specifier.imported.name === USE_ONYX_IDENTIFIER;
const isDefaultUseOnyxHook = specifier.type === 'ImportDefaultSpecifier' && source.endsWith(USE_ONYX_HOOK_PATH_SUFFIX);
if (isNamedUseOnyx || isDefaultUseOnyxHook) {
useOnyxNames.add(specifier.local.name);
}

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.

Hooks that wrap useOnyx aren't checked. For example, WorkspaceCompanyCardsTable uses useAllPersonalDetails. We should treat the known wrappers as useOnyx

const [personalDetails, personalDetailsMetadata] = useAllPersonalDetails();

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.

True, but in practice, most of these wrappers are already covered.
For example in WorkspaceCompanyCardsTable, personalDetailsMetadata you mention is only used through isLoadingOnyxValue

const isLoadingOnyxPersonalDetails = isLoadingOnyxValue(personalDetailsMetadata);

and the rule counts every isLoadingOnyxValue call.

There is only one place where this is actually missing: here.


We should treat the known wrappers as useOnyx

To do that, we will need to track all of the wrappers in the rule, right? I guess it can be problematic, cause new wrappers can be added/updated. Or we can consider all hooks as wrappers, which can end up with some false positives in some case.
Since the cleanup will remove the metadata from these wrappers anyway, maybe we can skip it.
What do you think?

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.

Makes sense as it's a rare case.

@nkdengineer

Copy link
Copy Markdown
Contributor

@VickyStash We have the conflicts.

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.

4 participants