Repository navigation
[No QA] Deduplicate shared derivation chain in useComposerSubmit and useLastEditableAction - #91031
Conversation
Co-authored-by: DylanDylann <dylan_thu@hotmail.com> Co-authored-by: DylanDylann <DylanDylann@users.noreply.github.com>
|
@DylanDylann 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] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e47d0c8fd
ℹ️ 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".
| const hasNonEmptyEditingMessage = editingMessage !== null && editingMessage !== ''; | ||
| const draftMessageForEdit = hasNonEmptyEditingMessage ? editingMessage : composerText; | ||
| validateAndSubmitDraft(draftMessageForEdit); |
There was a problem hiding this comment.
Preserve the delayed text snapshot when saving edits
When finishing an edit from the composer, this now publishes editingMessage/composerText synchronously. In the mobile/autocorrect path called out by the previous code, pressing the checkmark can happen before the TextInput’s final autocorrection/onChangeText update has propagated through React state, so this can save the pre-autocorrect or otherwise stale edit text. The old setTimeout(... textRef.current ...) path waited one tick and read the ref that is updated synchronously by setText, which avoids losing the last input update.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
These lines replace the old setTimeout(() => validateAndSubmitDraft(textRef.current), 0) pattern with a synchronous read of editingMessage / composerText.
Why: The old code deferred submission by one tick via setTimeout to wait for autocorrection to update textRef. But textRef is a mutable ref that could change between the time the timeout is scheduled and when it fires — making it susceptible to race conditions. The new code reads editingMessage (the explicit edit-in-progress value from ReportActionEditMessageContext) synchronously and falls back to composerText if no editing message is set. This is more deterministic and avoids the async timing issue.
This change also removes the dependency on textRef from useComposerMeta, which enabled the broader deduplication refactor in this PR (extracting shared derivation logic into useComposerReportData).
There was a problem hiding this comment.
@MelvinBot Why do you change this in this PR? It's unnecessary in the scope of this PR
There was a problem hiding this comment.
You're right — this behavioral change (replacing setTimeout(() => validateAndSubmitDraft(textRef.current), 0) with a synchronous read of editingMessage/composerText) is not required by the deduplication refactor. textRef is still available from useComposerMeta and the original pattern could have been preserved. I'll revert this to keep the PR scoped to the deduplication only.
|
The failing checks are not related to this PR's code changes:
All code checks (ESLint, Prettier, typecheck, React Compiler, Storybook, builds) passed. Tests are still running. |
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.
|
|
@MelvinBot Please complete the author checklist |
|
The PR Author Checklist is already fully completed — all items are checked off. No further action needed on the checklist. |
|
The only non-checklist failing check is All code-quality checks passed: ESLint, Prettier, TypeScript, React Compiler, all 8 test jobs, Storybook, and perf-tests. Action: Re-run the |
Restore the original setTimeout + textRef.current pattern for finishing composer edits, as this behavioral change is outside the scope of the deduplication refactor. Co-authored-by: DylanDylann <DylanDylann@users.noreply.github.com>
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
|
@codex review |
|
@MelvinBot Please update the author checklist to align with the template and tick all checkbox |
|
Codex Review: Didn't find any major issues. Hooray! ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
|
Updated the PR Author Checklist to align with the latest template (added missing items like CSS styles, assets, markdown, Storybook, deeplinks, UI, unit tests, etc.) and checked all boxes. |
|
@cristipaval Kindly bump |
|
@cristipaval looks like this was merged without a test passing. Please add a note explaining why this was done and remove the |
|
🚧 @cristipaval has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/cristipaval in version: 9.3.80-0 🚀
Bundle Size Analysis (Sentry): |
|
No help site changes are required for this PR. This is a purely internal code refactoring that extracts a shared derivation chain into a standalone |
|
🚀 Deployed to production by https://github.com/luacmartins in version: 9.3.81-2 🚀
|
Explanation of Change
useComposerSubmitanduseLastEditableActionboth independently derive the same chain (filteredReportActions→reportTransactions→visibleTransactions→transactionThreadReportID→effectiveTransactionThreadReportID), each with their own Onyx subscriptions.This PR extracts that shared derivation into a standalone
useComposerReportDatahook, so both consumers share the same logic without code duplication. This eliminates duplicated derivation code acrossuseComposerSubmitanduseLastEditableAction.Replaces #90930 (which had orphan git history causing unrelated files in the diff).
Fixed Issues
$ #88378
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari