8000 Fix undeclared allReportsViolations in hasVisibleReportFieldViolations by MelvinBot · Pull Request #84952 · Expensify/App · GitHub
[go: up one dir, main page]

Skip to content

Fix undeclared allReportsViolations in hasVisibleReportFieldViolations#84952

Merged
tgolen merged 3 commits intomainfrom
claude-fixUndeclaredAllReportsViolations
Mar 11, 2026
Merged

Fix undeclared allReportsViolations in hasVisibleReportFieldViolations#84952
tgolen merged 3 commits intomainfrom
claude-fixUndeclaredAllReportsViolations

Conversation

@MelvinBot
Copy link
Contributor
@MelvinBot MelvinBot commented Mar 11, 2026

Explanation of Change

PR #83424 introduced hasVisibleReportFieldViolations in ReportUtils.ts, which references an undeclared variable allReportsViolations. This caused typecheck, ESLint, and test failures on main (issues #84928, #84929, #84930).

This fix adds reportViolations as an explicit parameter to hasVisibleReportFieldViolations instead of relying on a nonexistent module-level variable. The caller in reportAttributes.ts now includes ONYXKEYS.COLLECTION.REPORT_VIOLATIONS as an Onyx dependency and passes the specific report's violations to the function.

Fixed Issues

$ #84930
$ #84929
$ #84928

Tests

  1. Verify typecheck passes (npx tsc --noEmit)
  2. Verify ESLint passes on modified files
  3. Verify unit tests pass
  • Verify that no errors appear in the JS console

Offline tests

Same as QA

QA Steps

Precondition:

Create a text type report field in workspace settings > Reports.

  1. Go to workspace chat.
  2. Create an expense, and confirm expense preview appears instantly after creating expense.
  3. Navigate to another chat, then go back to workspace chat.
  4. Open the expense report, and confirm it is not empty
  5. Navigate to another chat, then go back to workspace chat.
  6. Open the expense report and ensure expense report is now loaded.
  • 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
      • 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 ex 8000 isting 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

N/A — build/compilation fix only, no UI changes.

…Violations

Add reportViolations as a parameter to hasVisibleReportFieldViolations and
pipe the data through from the Onyx derived config in reportAttributes.ts.
The function was referencing an undeclared module-level variable
allReportsViolations, causing typecheck, ESLint, and test failures.

Co-authored-by: Daniel Gale-Rosen <dangrous@users.noreply.github.com>
The reportAttributes config now has 12 dependencies after adding
REPORT_VIOLATIONS, but the test was still passing arrays with only
11 elements, causing a typecheck failure.

Co-authored-by: Daniel Gale-Rosen <dangrous@users.noreply.github.com>
@dangrous dangrous marked this pull request as ready for review March 11, 2026 19:36
@dangrous dangrous requested a review from a team as a code owner March 11, 2026 19:36
8000 @MelvinBot
Copy link
Contributor Author

Fixed the failing typecheck: The reportAttributes config has 12 dependencies after adding ONYXKEYS.COLLECTION.REPORT_VIOLATIONS, but the test in OnyxDerivedTest.tsx was still passing arrays with only 11 elements to compute(). Added the missing 12th element (undefined) to both array literals on lines 126 and 128.

@melvin-bot melvin-bot bot requested review from ShridharGoel and heyjennahay and removed request for a team and heyjennahay March 11, 2026 19:36
@melvin-bot
Copy link
melvin-bot bot commented Mar 11, 2026

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

@ShridharGoel
Copy link
Contributor
ShridharGoel commented Mar 11, 2026

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 there are no new alerts related to the canBeMissing param for useOnyx
  • 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 8000 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
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

Copy link
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 909176f748

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

ONYXKEYS.SESSION,
ONYXKEYS.COLLECTION.POLICY,
ONYXKEYS.COLLECTION.POLICY_TAGS,
ONYXKEYS.COLLECTION.REPORT_VIOLATIONS,

Choose a reason for hiding this comment

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

P1 Badge Recompute report attributes on REPORT_VIOLATIONS updates

Adding ONYXKEYS.COLLECTION.REPORT_VIOLATIONS as a dependency here causes compute to run when report-field violations change, but the incremental path still only treats report/report-metadata/report-actions/report-name-value-pairs/transaction updates as actionable; when isFullyComputed is true and only report-violation keys change, it returns early via the "No updates to process" path, so hasVisibleReportFieldViolations(...) is not re-evaluated and sidebar brick-road state can stay stale until an unrelated update arrives.

Useful? React with 👍 / 👎.

Copy link
Contributor

Choose a reason for hiding this comment

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

@MelvinBot can you double check this one? Also please attempt to figure out why this passed tests on #83424 but then failed them on the workflow. I'm guessing it is because of recent changes to main, but that might give us a clue as to a better solution here, too.

Copy link
Contributor Author
@MelvinBot MelvinBot Mar 11, 2026

Choose a reason for hiding this comment

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

The concern flagged here is valid. Adding ONYXKEYS.COLLECTION.REPORT_VIOLATIONS as a dependency means compute will fire when report-field violations change, but the incremental update path (after isFullyComputed is true) doesn't track reportViol 8000 ationsUpdates — so it hits the "No updates to process" early-return and hasVisibleReportFieldViolations is never re-evaluated for the affected report.

Whether this is a regression vs. pre-existing: Before PR #83424, hasVisibleReportFieldViolations didn't exist at all, so there was no brick-road indicator for report field violations in the first place. The original code in #83424 used a module-level allReportsViolations via Onyx.connect, which would have had its own reactivity path. This PR correctly fixes the broken reference, but doesn't fully replicate the reactivity that the original approach intended.

Practical impact: If report-field violations can change independently of report/transaction updates (e.g., pushed via Pusher after a server-side policy check), the sidebar brick-road indicator would go stale until some other Onyx update triggers a full recompute. If they only change alongside report updates (which are already tracked), the gap is latent.

Recommendation: Since this PR is an urgent fix for a build breakage on main, the current approach is fine to merge as-is — it restores the build and is no worse than having no report-field violation indicator at all (which was the state before #83424). The incremental update handling should be added as a follow-up to fully complete the feature.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think we should merge this, and the above P1 should be handled as a follow up of #83424

Copy link
Contributor

Choose a reason for hiding this comment

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

@dangrous What do you think?

@tgolen
Copy link
Contributor
tgolen commented Mar 11, 2026

@dangrous This is pretty bad and should be CPed to staging at least.

@dangrous
Copy link
Contributor
dangrous commented Mar 11, 2026

@tgolen It's not on staging yet, just main, as far as I know! Came from this PR - #83424

UPDATE: That went to staging 10 mins ago, I can CP this for sure

@MelvinBot
Copy link
Contributor Author

🔍 PR Review & Investigation

Why PR #83424 passed CI but broke main

This is a classic merge skew (semantic merge conflict). Here's the timeline:

Timestamp (UTC) Event
2026-03-07 00:12 Last main commit that PR #83424 synced with
2026-03-09 04:45 PR #83424 last merges from main ("resolve conflict")
2026-03-09 ~04:47 PR #83424 CI passes — allReportsViolations still exists on main
2026-03-09 19:32 PR #80104 merges to main — removes allReportsViolations entirely
2026-03-11 18:57 PR #83424 merges to mainbreakage (references now-deleted variable)
2026-03-11 19:27 PR #84952 created to fix the breakage

PR #80104 ("[No QA] Removing ONYXKEYS.COLLECTION.REPORT_VIOLATIONS in ReportUtils") removed the module-level allReportsViolations variable and its Onyx.connect block from ReportUtils.ts. This happened ~15 hours after PR #83424's last CI run but ~2 days before it was merged. Since #83424 was never re-synced with main after #80104 landed, its green CI was stale.

GitHub's branch protection checks CI on the PR branch's head commit but not against the current state of main at merge time, which is how this slipped through.

Review of PR #84952 fix

The core approach is correct. Passing reportViolations as an explicit parameter to hasVisibleReportFieldViolations is the right pattern — it's consistent with how hasReportViolations and getFieldViolation already work in ReportUtils.ts, and the codebase has moved away from module-level Onyx subscriptions for violations.

However, there is one gap: missing incremental update handling for REPORT_VIOLATIONS.

In reportAttributes.ts, every other collection dependency has explicit incremental update detection (lines 105-110):

  • REPORTreportUpdates
  • REPORT_METADATAreportMetadataUpdates
  • REPORT_ACTIONSreportActionsUpdates
  • REPORT_NAME_VALUE_PAIRSreportNameValuePairsUpdates
  • TRANSACTIONtransactionsUpdates
  • TRANSACTION_VIOLATIONStransactionViolationsUpdates

REPORT_VIOLATIONS is completely absent from this incremental logic. After isFullyComputed becomes true, if only report violations change (without concurrent report/transaction changes), the compute function will hit the early-return and return stale currentValue. The fix should add something like:

const reportViolationsUpdates = sourceValues?.[ONYXKEYS.COLLECTION.REPORT_VIOLATIONS];

...and include it in the incremental update conditional, plus logic to determine which reports need re-computation when report violations change (similar to how transactionViolationsUpdates is handled, but simpler since reportViolations_ keys map directly to report IDs).

Whether this matters in practice depends on whether report violations can change independently of report/transaction updates. If they only change alongside report changes (which are already tracked), this gap may be latent. But if violations can be pushed independently from the server (e.g., via Pusher), stale brick-road indicators would result.

Summary


Next Steps: Reply with @MelvinBot implement this to have me add the missing incremental update handling, or @MelvinBot <your feedback> to discuss further.

@dangrous
Copy link
Contributor

@MelvinBot implement this ^

…utes

When report violations change independently after the initial full compute,
the reportAttributes derived value now correctly detects the change and
recomputes the affected reports. Without this, report field violation
changes could result in stale brick-road indicators.

Co-authored-by: Daniel Gale-Rosen <dangrous@users.noreply.github.com>
@MelvinBot MelvinBot requested a review from a team as a code owner March 11, 2026 20:47
@melvin-bot melvin-bot bot requested review from dangrous and removed request for a team March 11, 2026 20:47
@melvin-bot
Copy link
melvin-bot bot commented Mar 11, 2026

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

@MelvinBot
Copy link
Contributor Author

Added incremental update handling for REPORT_VIOLATIONS in reportAttributes.ts. The change follows the exact same pattern as the existing collection dependencies (REPORT_METADATA, REPORT_ACTIONS, REPORT_NAME_VALUE_PAIRS):

  1. Added REPORT_VIOLATIONS to prepareReportKeys so violation keys are mapped to report keys
  2. Extracts reportViolationsUpdates from sourceValues
  3. Includes report violation keys in the updates array

This ensures that when report violations change independently (after the initial full compute), the affected reports are re-evaluated and brick-road indicators stay accurate.

All 35 OnyxDerived tests pass. Full typecheck couldn't run in this environment due to memory limits, but ESLint passes clean and the changes are structurally identical to the existing patterns.

@dangrous
Copy link
Contributor

@ShridharGoel I think this is ready for a final look, the update wasn't too tricky it seems. I'll get internal eyes on it to review/merge once tests pass

@dangrous dangrous added the CP Staging marks PRs that have been CP'd to staging label Mar 11, 2026
reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], {});
const reportAttributesComputedValue = reportAttributes.compute(
[reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined],
[reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined],
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be really nice to have a test where this new value IS used. NAB because it's not necessary to fix the blocker, but if there are any follow-up issues, please add a test covering this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that makes sense, I'll ping on the initial issue

@tgolen
Copy link
Contributor
tgolen commented Mar 11, 2026

I discussed on Slack with @dangrous about adding some actual QA tests for this to ensure it's working (especially the report violations). I can merge it as-is and the tests can be updated aftewards.

@tgolen tgolen merged commit 52fb308 into main Mar 11, 2026
44 of 45 checks passed
@tgolen tgolen deleted the claude-fixUndeclaredAllReportsViolations branch March 11, 2026 21:23
@melvin-bot
Copy link
melvin-bot bot commented Mar 11, 2026

@tgolen looks like this was merged without a test passing. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@melvin-bot melvin-bot bot added the Emergency label Mar 11, 2026
@github-actions
Copy link
Contributor

🚧 @tgolen has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@mountiny
Copy link
Contributor

Since the original PR is linked to couple blockers, I have gone ahead and reverted this and the original PR so @daledah can fix and test it thoroughly. I hope that works

@OSBotify
Copy link
Contributor

🚀 Cherry-picked to staging by https://github.com/tgolen in version: 9.3.37-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

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

Labels

CP Staging marks PRs that have been CP'd to staging Emergency

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

0