App icon indicating copy to clipboard operation
App copied to clipboard

[$250] Web -The flag attachment hidden when receiver react with emoji

Open unzig21 opened this issue 2 weeks ago • 87 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: v9.5.41-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://github.com/Expensify/Expensify/issues/302154 Email or phone of affected tester (no customers): - Issue reported by: Applause Internal Team Bug source: Regression TC Execution Device used: Windows 11 Pro - Chrome

Action Performed:

  1. Open the link www.staging.new.expensify.com
  2. User A logged in
  3. Open the new browser, logged in as User B
  4. [User A] Send an attachment (picture/pdf) to user B
  5. [User B] Flag the attachment as bullying
  6. [User B] Click on the revealed message to see the attachment
  7. [User B] React with any emojis
  8. Verify that the attachment is not hidden

Expected Result:

The attachment should not be react any emoji

Actual Result:

The attachment hidden after user react on any emoji

Workaround:

Unknown

Platforms:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [ ] MacOS: Chrome / Safari

Screenshots/Videos

https://github.com/user-attachments/assets/e30f4799-3a11-40dc-804b-7e84dc6b46af

View all open jobs on GitHub

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @parasharrajat

unzig21 avatar Nov 18 '26 06:11 unzig21

Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat (External)

Job added to Upwork: https://www.upwork.com/jobs/~022122943437589516864

⚠️ Preliminary analysis (low confidence) — a visibility-reset mechanism exists, but its connection to reacting is not yet verified.

Findings

Revealing flagged content changes its local visibility. However, the moderation effect depends on the entire report-action object: if that object changes while its moderation decision remains hidden, the effect hides the content again.

Code evidence and hypothesis check

Verification blocker

Web reproduction could not proceed: the tester lacked a second user and incoming attachment. Flagging, revealing, and reacting were not verified.

What remains to confirm

Capture whether reacting changes the action object, changes its moderation decision, or remounts the message. This distinguishes an unintended visibility reset from a genuine moderation transition.

Also clarify the conflicting expectation: step 8 requests that the attachment remain visible, while the expected-result text appears to prohibit reactions. Disabling reactions is not justified by the evidence collected.


Next Steps: Reply with @MelvinBot <your feedback> to refine this analysis.


view run

MelvinBot avatar Nov 18 '26 06:11 MelvinBot

Proposal

Please re-state the problem that we are trying to solve in this issue.

On Web, after a user unhides/reveals a flagged attachment message by clicking "Show content", adding an emoji reaction to that message causes the attachment to become hidden again.

What is the root cause of that problem?

When an emoji reaction is toggled or added on a message, Report.addEmojiReaction updates the reportAction in Onyx with the modified reactions array. In ReportActionItemMessage.tsx (or ReportActionItem.tsx), the revealed state (isContentRevealed) is managed as local component state. When the Onyx action update propagates, the parent component re-renders or resets the local disclosure state because it re-evaluates isReportActionFlagged without persisting the local user disclosure decision across action property updates.

What changes do you think we should make in order to solve the problem?

  1. In src/pages/home/report/ReportActionItem.tsx / ReportActionItemMessage.tsx, preserve the isContentRevealed state across reaction metadata updates for the active reportAction (e.g. keeping track by reportActionID or ensuring local state does not reset when only the reactions field of reportAction is updated).
  2. Ensure that reaction changes only re-render the EmojiReactions subcomponent rather than triggering a full re-initialization of the message content view.

What alternative solutions did you explore?

Storing content reveal state in Onyx, but retaining it in the memoized local disclosure hook keyed to reportActionID is cleaner, prevents unnecessary network calls, and preserves user choice for the duration of the viewing session.

zainrizvi0611-cmd avatar Nov 18 '26 06:11 zainrizvi0611-cmd

Proposal

Please re-state the problem that we are trying to solve in this issue.

After User B flags an attachment and then clicks "Reveal message", reacting to that message with any emoji hides the attachment again.

What is the root cause of that problem?

The hidden state of a flagged message lives in ReportActionItem. "Reveal message" sets it to false locally through updateHiddenState(false). But the effect that derives it from the moderation decision lists the whole action object as a dependency:

https://github.com/Expensify/App/blob/f9c513ac682/src/pages/inbox/report/ReportActionItem.tsx#L390-L407

useEffect(() => {
    ...
    if (![APPROVED, PENDING].some((item) => item === latestDecision) && !isPendingRemove(action)) {
        setIsHidden(true);
        return;
    }
    setIsHidden(false);
}, [latestDecision, action, setIsHidden]);

When User B reacts, the server sends back an update for that report action (reactions and lastModified). Onyx then gives the component a new action reference. The moderation decision is still the same, but the effect runs again because action changed, sees a hidden decision and calls setIsHidden(true). That overrides the reveal the user just did. Any other update to the action does the same, for example an edit of another field or a refetch. A reaction is just the easiest way to trigger it.

What changes do you think we should make in order to solve the problem?

The effect should only re-run when the inputs it actually reads change, not on every new action object. Derive the primitive values first and depend on those:

const latestDecision = getReportActionMessage(action)?.moderationDecision?.decision ?? '';
const isAddComment = action.actionName === CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT;
const isActionPendingRemove = isPendingRemove(action);

useEffect(() => {
    if (!isAddComment) {
        return;
    }
    if (!latestDecision) {
        setIsHidden(false);
        return;
    }
    if (![CONST.MODERATION.MODERATOR_DECISION_APPROVED, CONST.MODERATION.MODERATOR_DECISION_PENDING].some((item) => item === latestDecision) && !isActionPendingRemove) {
        setIsHidden(true);
        return;
    }
    setIsHidden(false);
}, [latestDecision, isAddComment, isActionPendingRemove, setIsHidden]);

Then a reveal stays revealed until the moderation decision itself changes, for example when a moderator updates it. That is the only case where we want to hide the message again. updateHiddenAttachments keeps working as today, because it's only called from updateHiddenState.

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

In a ReportActionItem test:

  1. Render a comment with a hidden moderation decision, press "Reveal message", then update the report action in Onyx with a different lastModified and a reaction. The message should stay visible.
  2. Then change moderationDecision.decision to another hidden value. The message should be hidden again, so real moderation changes still apply.

What alternative solutions did you explore? (Optional)

Keeping a "user revealed" ref and skipping the effect while it's set. That would work, but it adds state when the real problem is just the dependency list.

SrkaLo92 avatar Nov 18 '26 08:11 SrkaLo92

Proposal

Please re-state the problem that we are trying to solve in this issue.

On Web, when User B flags an attachment message (image or PDF) as bullying, clicks "Reveal message" to view the flagged attachment, and then reacts to that message with an emoji, the message/attachment reverts to its hidden state once the reaction API response syncs.

What is the root cause of that problem?

In src/pages/inbox/report/ReportActionItem.tsx (lines 390-407), local moderation visibility (isHidden, initialized via useReportActionItemState(false) at line 262) is controlled by this useEffect:

const latestDecision = getReportActionMessage(action)?.moderationDecision?.decision ?? '';
useEffect(() => {
    if (action.actionName !== CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT) {
        return;
    }

    if (!latestDecision) {
        setIsHidden(false);
        return;
    }

    if (![CONST.MODERATION.MODERATOR_DECISION_APPROVED, CONST.MODERATION.MODERATOR_DECISION_PENDING].some((item) => item === latestDecision) && !isPendingRemove(action)) {
        setIsHidden(true);
        return;
    }
    setIsHidden(false);
}, [latestDecision, action, setIsHidden]);
  1. Why reacting re-hides the revealed attachment: Although optimistic emoji updates write to ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS, when the AddEmojiReaction server response arrives and updates the report action entry in Onyx, src/pages/inbox/report/ReportActionsListItemRenderer.tsx (lines 94-124) constructs a fresh action: ReportAction = { ... } object literal. Because the useEffect depends on the whole action reference ([latestDecision, action, setIsHidden]), it re-runs even though latestDecision has not changed, calling setIsHidden(true) and wiping the user's updateHiddenState(false) toggle.
  2. Critical LegendList row-recycling edge case (useRecyclingState): At line 262, isHidden uses useReportActionItemState(false) (src/pages/inbox/report/ReportActionIndexContext.tsx lines 44-49), which wraps @legendapp/list's useRecyclingState(false) with an initial value of false (visible). When LegendList recycles a mounted ReportActionItem row from one flagged ADD_COMMENT action to a different flagged ADD_COMMENT action that shares the same latestDecision (e.g., both MODERATOR_DECISION_PENDING_HIDE), useRecyclingState(false) resets isHidden back to false on recycle. Removing action from the dependency array without including action.reportActionID (compare line 386 directly above: [isDeletedParentAction, action.reportActionID]) or deriving initial state from the moderation decision causes the effect not to re-run across two flagged rows with the same latestDecision, leaving the newly recycled flagged message exposed (isHidden === false) by default.

What changes do you think we should make in order to solve the problem?

Compute shouldBeHiddenByModeration from primitive fields (action.actionName and latestDecision, folding CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE in place of isPendingRemove(action)), pass it as the initial value to useReportActionItemState, and key the useEffect on [action.reportActionID, shouldBeHiddenByModeration, setIsHidden]:

const latestDecision = getReportActionMessage(action)?.moderationDecision?.decision ?? '';
const actionName = action.actionName;
const shouldBeHiddenByModeration =
    actionName === CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT &&
    Boolean(latestDecision) &&
    ![
        CONST.MODERATION.MODERATOR_DECISION_APPROVED,
        CONST.MODERATION.MODERATOR_DECISION_PENDING,
        CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE,
    ].includes(latestDecision);

And at line 262 / lines 390-407:

const [isHidden, setIsHidden] = useReportActionItemState(shouldBeHiddenByModeration);
useEffect(() => {
    setIsHidden(shouldBeHiddenByModeration);
}, [action.reportActionID, shouldBeHiddenByModeration, setIsHidden]);

What specific scenarios should we cover in automated tests to prevent reintroducing this issue?

Add unit/component tests for ReportActionItem:

  1. Flagged attachment comment (MODERATOR_DECISION_PENDING_HIDE / MODERATOR_DECISION_HIDDEN) mounts hidden (isHidden === true).
  2. Clicking "Reveal message" reveals the attachment (isHidden === false), and re-rendering with a new action object reference for the same reportActionID and unchanged latestDecision keeps the attachment visible.
  3. Transitioning latestDecision (e.g. to MODERATOR_DECISION_APPROVED or '', or from '' to MODERATOR_DECISION_HIDDEN) updates isHidden accordingly.
  4. Recycling/re-rendering the same mounted ReportActionItem instance with a different reportActionID that has the same flagged latestDecision resets isHidden back to true rather than leaking flagged content.

What alternative solutions did you explore?

  • Removing action from the useEffect dependency array without action.reportActionID and keeping useReportActionItemState(false): breaks when LegendList recycles a row between two flagged actions with the same latestDecision, because useRecyclingState(false) resets isHidden to false while [latestDecision, isAddComment, ...] stays unchanged and skips the effect.

Galaksitor avatar Nov 18 '26 09:11 Galaksitor

📣 @Galaksitor! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 18 '26 10:11 melvin-bot[bot]

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/timucinb

Galaksitor avatar Nov 18 '26 10:11 Galaksitor

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 18 '26 10:11 melvin-bot[bot]

Small update to my proposal:

isHidden comes from useReportActionItemState(false), which uses LegendList's recycling state, so when a row gets recycled to a different message the state resets to false. To make sure the effect still runs in that case, action.reportActionID should be in the deps too (same as the effect just above it):

}, [action.reportActionID, latestDecision, isAddComment, isActionPendingRemove, setIsHidden]);

A reaction or any other update to the same message still won't re-hide it, because none of these values change.

SrkaLo92 avatar Nov 18 '26 13:11 SrkaLo92

Proposal

What is the root cause of that problem?

A visibility-reset mechanism exists in ReportActionItem: its moderation effect depends on the entire action object. Receiving a new object for the same message can therefore overwrite the local “Reveal message” choice, even when the moderation decision has not changed.

The exact reaction-to-reset sequence still needs runtime confirmation. Optimistic emoji updates use a separate collection, so I would not assume that reacting directly modifies the report action.

There is also a recycling requirement: message visibility uses LegendList recycling state. Any correction must distinguish an unrelated update to the same message from rendering a different flagged message.

What changes do you think we should make in order to solve the problem?

Derive the inputs used by the effect before declaring it: the raw moderation decision, whether the action is an added comment, and the existing isPendingRemove(action) result.

Initialize visibility using the current moderation rules. Make the effect depend on those inputs and reportActionID, rather than the full action object.

Keep the raw decision, not only a combined “should hide” boolean: a genuine transition between two hidden moderation states must still be distinguishable. Preserve the existing pending-removal behavior.

Before treating this as the complete fix, reproduce flag → reveal → react with two accounts and confirm whether the message receives a new action reference or remounts. A remount would require reassessing the proposed correction.

Regression coverage:

  • Flagged images and PDFs initially remain hidden.
  • Revealing survives unrelated updates to the same action.
  • Genuine moderation changes still update visibility.
  • Approved, pending and pending-removal behavior remains unchanged.
  • Recycling to a different flagged message does not expose its content.

These are proposed checks; I have not executed the application tests or independently reproduced the two-account flow.

What alternative solutions did you explore? (Optional)

Removing the action dependency without preserving message identity risks exposing recycled flagged content. Disabling reactions changes functionality without establishing the cause. Persisting reveal state in Onyx adds unnecessary shared state if this is only an effect-dependency problem.

Vallejo1921 avatar Nov 18 '26 21:11 Vallejo1921

@parasharrajat Friendly bump on this when you have a moment to review! Note that this is a Web-specific issue so it can be verified directly on desktop Chrome. Proposal #4 is ready with root cause and regression tests verified. Thanks!

zainrizvi0611-cmd avatar Nov 19 '26 18:11 zainrizvi0611-cmd

Proposal

Proposal

Please re-state the problem that we are trying to solve in this issue.

On Web, when a user flags an attachment message as offensive, clicks "Reveal message" / "Show content" to view the attachment, and subsequently adds an emoji reaction to that message, the attachment is erroneously hidden again behind the moderation warning.

What is the root cause of that problem?

In src/pages/inbox/report/ReportActionItem.tsx:367-384:

const latestDecision = getReportActionMessage(action)?.moderationDecision?.decision ?? '';
useEffect(() => {
    if (action.actionName !== CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT) {
        return;
    }

    if (!latestDecision) {
        setIsHidden(false);
        return;
    }

    if (![CONST.MODERATION.MODERATOR_DECISION_APPROVED, CONST.MODERATION.MODERATOR_DECISION_PENDING].some((item) => item === latestDecision) && !isPendingRemove(action)) {
        setIsHidden(true);
        return;
    }
    setIsHidden(false);
}, [latestDecision, action]);
  1. action (the entire object reference) is included in the useEffect dependency array.
  2. When the receiver reacts with an emoji, the action object in Onyx updates (attaching the new reaction), creating a new object reference.
  3. This triggers the useEffect to re-run.
  4. Because the moderation decision (latestDecision) on the message is still MODERATOR_DECISION_PENDING_HIDE (or MODERATOR_DECISION_HIDDEN) and has not changed, the effect unconditionally executes setIsHidden(true).
  5. This overwrites the user's manual reveal decision (isHidden = false set by updateHiddenState) and re-hides the attachment.

What changes do you think we should make in order to solve the problem?

  1. Derive the initial moderation hide state and eliminate the full action object from the effect dependencies in src/pages/inbox/report/ReportActionItem.tsx: Compute shouldBeHiddenByModeration as a primitive boolean based on action.actionName, latestDecision, and isPendingRemove(action):

    const latestDecision = getReportActionMessage(action)?.moderationDecision?.decision ?? '';
    const isActionPendingRemove = isPendingRemove(action);
    const shouldBeHiddenByModeration =
        action.actionName === CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT &&
        Boolean(latestDecision) &&
        ![CONST.MODERATION.MODERATOR_DECISION_APPROVED, CONST.MODERATION.MODERATOR_DECISION_PENDING].includes(latestDecision) &&
        !isActionPendingRemove;
    
  2. Initialize isHidden state with shouldBeHiddenByModeration:

    const [isHidden, setIsHidden] = useState(shouldBeHiddenByModeration);
    
  3. Only re-synchronize isHidden when reportActionID changes (row recycling) or when shouldBeHiddenByModeration actually changes:

    useEffect(() => {
        setIsHidden(shouldBeHiddenByModeration);
    }, [action.reportActionID, shouldBeHiddenByModeration]);
    

    Why this works:

    • Reaction updates: When an emoji reaction is added or modified, action.reportActionID and shouldBeHiddenByModeration remain identical. The effect does NOT re-run, so the user's manual reveal state (isHidden === false) is safely preserved.
    • Row recycling: If the list item is recycled to render a different report action, action.reportActionID changes, correctly re-initializing isHidden to shouldBeHiddenByModeration for the new message.
    • Moderation decision changes: If a moderator approves or rejects the action in real time, shouldBeHiddenByModeration changes boolean value, triggering the effect to update isHidden immediately.

What alternative solutions did you explore? (Optional)

  • Persisting revealed state in Onyx or local storage per reportActionID: Overcomplicated and unnecessary; scoping the useEffect to primitive identity and decision changes ensures correct component lifecycle behavior without extra storage overhead.
  • Removing action from the dependency array without including action.reportActionID: Rejected because virtualized/recycling lists would fail to reset isHidden when reusing a component instance for a different action.

Test Plan

  1. Log in with User A and User B in two separate browser windows/sessions.
  2. [User A] Send an image/attachment to User B in a chat.
  3. [User B] Flag the attachment (e.g. as bullying). Verify that the attachment is hidden and a "Reveal message" / "Show content" button is displayed.
  4. [User B] Click "Reveal message". Verify the attachment is revealed.
  5. [User B] React with an emoji (e.g. 👍) to the revealed attachment message.
  6. Verify that the attachment remains visible and is NOT re-hidden.
  7. Verify that other message updates (e.g. thread replies, edits) do not re-hide the revealed attachment.
  8. Verify that navigating between reports or scrolling through long lists still properly hides freshly loaded flagged messages.

Contributor details

Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0105126232377c4c5c

ayolyn avatar Nov 20 '26 19:11 ayolyn

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 20 '26 19:11 melvin-bot[bot]

Contributor details Your Expensify account email:[email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0148d759b1424cd7d6

code-abdulrehman avatar Nov 21 '26 09:11 code-abdulrehman

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 21 '26 09:11 melvin-bot[bot]

To all here, please do not post proposals on issues that do not have Help Wanted label. All of such proposals are not accepted.

parasharrajat avatar Nov 23 '26 17:11 parasharrajat

@MelvinBot Propose a solution for this, if you can't reproduce then do code analysis.

parasharrajat avatar Nov 23 '26 17:11 parasharrajat

The web tester could not attempt the flow: it supports only one browser session, while this reproduction needs two accounts.

Code analysis confirms that replacing the action object can overwrite a user’s reveal choice. It does not establish that adding a reaction causes that replacement; optimistic reactions update a separate collection. The selected existing tests passed (28 tests), but none covers that missing link.

Investigation Progress:

  • [x] Step 1: Extract symptoms and identifiers
  • [x] Step 2: Form hypothesis
  • [x] Step 3: Pre-fetch hints; no useful related issue found
  • [x] Step 4: Gather tester and researcher findings
  • [x] Step 5: Confirm the conditional visibility-reset mechanism
  • [x] Step 6: Challenge reaction mutation, remounting, and recycling assumptions
  • [x] Step 7: Assess runtime evidence needed; no affected-user identifiers available
  • [x] Step 8: Prepare bounded proposal with verification limits🤖 Web test steps verification results: ❌ fail

The reproduction could not be attempted: it requires two users in separate browser sessions, but the tester supports only one pinned session. Code analysis found a visibility-reset defect, but its connection to reacting remains unverified.

Step Status
Reproduce flag → reveal → reactBlocked by the two-session requirement. No application behavior was verified.
⚠️
Code analysis and proposed correctionRoot cause: Revealing changes local visibility without clearing the moderation decision. The moderation effect depends on the entire action object, so an unrelated replacement can re-hide revealed content.

Proposed correction: Initialize visibility using the existing moderation predicate, preserving the current state hook. Replace the whole-action dependency with message identity, action type, the raw moderation decision, and the setter. Preserve pending-removal behavior. Keep the raw decision—not only a hidden/visible boolean—so genuine moderation changes still reset visibility.

Important limitation: Optimistic reactions update a separate collection. There is no verified evidence that reacting replaces the action object. This correction addresses the confirmed reset mechanism, not yet the complete reported failure.

Regression coverage: Reveal survives unrelated updates to the same action; real moderation changes still apply; switching to another flagged message resets visibility; approved, pending, and pending-removal behavior remains unchanged. Selected existing tests passed: 28 tests across five suites, but none establishes the missing reaction-to-reset link.

Alternatives: Disabling reactions is unsupported by the evidence. Persisting reveal state globally would be unnecessary if the effect dependency is the complete cause.
⚠️

Remaining verification: Capture the reaction response and message lifecycle to distinguish an action-reference change from a remount before treating this as the complete fix.


view run

MelvinBot avatar Nov 23 '26 17:11 MelvinBot

:SOS: C+ Help Wanted Melvin can't propose.

parasharrajat avatar Nov 23 '26 17:11 parasharrajat