Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,8 @@
"Kolkata",
"lintrk",
"Fbclid",
"Gclid"
"Gclid",
"autocorrection"
],
"ignorePaths": [
".gitignore",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type ComposerMeta = {
actionButtonRef: RefObject<View | HTMLDivElement | null>;
isNextModalWillOpenRef: RefObject<boolean>;
attachmentFileRef: RefObject<FileObject | FileObject[] | null>;
textRef: RefObject<string>;
};

const noop = () => {};
Expand Down
12 changes: 10 additions & 2 deletions src/pages/inbox/report/ReportActionCompose/ComposerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ function ComposerProvider({children, reportID}: ComposerProviderProps) {

const [isFullComposerAvailable, setIsFullComposerAvailable] = useState(isComposerFullSize);
const [isMenuVisible, setMenuVisibility] = useState(false);
const [text, setText] = useState(() => {
const getInitialText = () => {
return draftComment ?? '';
});
};
const textRef = useRef<string>(getInitialText());
const [text, setTextState] = useState(getInitialText);

const setText = (v: string) => {
setTextState(v);
textRef.current = v;
};

const containerRef = useRef<View>(null);
const suggestionsRef = useRef<SuggestionsRef>(null);
Expand Down Expand Up @@ -161,6 +168,7 @@ function ComposerProvider({children, reportID}: ComposerProviderProps) {
actionButtonRef,
isNextModalWillOpenRef,
attachmentFileRef,
textRef,
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {setIsComposerFullSize} from '@userActions/Report';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';
import {useComposerActions, useComposerEditActions, useComposerEditState, useComposerMeta, useComposerSendState, useComposerText} from './ComposerContext';
import {useComposerActions, useComposerEditActions, useComposerEditState, useComposerMeta, useComposerSendState} from './ComposerContext';
import useSidePanelContext from './useSidePanelContext';

function useComposerSubmit(reportID: string) {
Expand All @@ -39,11 +39,10 @@ function useComposerSubmit(reportID: string) {
const [isComposerFullSize = false] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportID}`);
const delegateAccountID = useDelegateAccountID();

const {composerRef, attachmentFileRef} = useComposerMeta();
const composerText = useComposerText();
const {composerRef, attachmentFileRef, textRef} = useComposerMeta();
const {clearComposer} = useComposerActions();
const {isSendDisabled, debouncedCommentMaxLengthValidation} = useComposerSendState();
const {isEditingInComposer, editingMessage, effectiveDraft, didResetComposerHeightWhileEditing, editingState} = useComposerEditState();
const {isEditingInComposer, effectiveDraft, didResetComposerHeightWhileEditing, editingState} = useComposerEditState();
const {publishDraft, setDidResetComposerHeightWhileEditing} = useComposerEditActions();
const {scrollOffsetRef} = useContext(ActionListContext);

Expand Down Expand Up @@ -186,9 +185,12 @@ function useComposerSubmit(reportID: string) {
editingState === CONST.REPORT_ACTION_EDIT_MESSAGE_STATE.EDITING && (isEditingInComposer || didResetComposerHeightWhileEditing) && !attachmentFileRef.current;

if (isFinishingComposerEdit) {
const hasNonEmptyEditingMessage = editingMessage !== null && editingMessage !== '';
const draftMessageForEdit = hasNonEmptyEditingMessage ? editingMessage : composerText;
validateAndSubmitDraft(draftMessageForEdit);
// We need to schedule the submission on the next tick to wait for
// potential autocorrection to update the text
setTimeout(() => {
validateAndSubmitDraft(textRef.current ?? '');
}, 0);
Comment on lines +190 to +192

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 Use edit draft fallback when delayed submit runs

Submitting edits now always reads textRef.current after a setTimeout, but that ref is updated by setText in composer effects (useEditComposerToggle) rather than from the edit context itself. When edit mode just switched actions (or just entered edit mode), editingMessage can already hold the correct draft while textRef.current still points to the previous composer text for one render; pressing Save during that window will publish the wrong message. The previous logic avoided this by preferring non-empty editingMessage before falling back to composer text.

Useful? React with 👍 / 👎.

ghost May 18, 2026

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.

This is exactly what we want. When autocorrection happens, it updates the actual value of the TextInput directly, and we have no way of hooking into that before we submit the edit. Therefore, we need to schedule the validateAndSubmitDraft as a later macro-task by calling setTimeout(() => validateAndSubmitDraft(textRef.current ?? ''), 0) with a timeout of 0. This does not add any "magic number" delay.


return;
}

Expand Down
Loading