Skip to content

Conversation

@WofWca
Copy link
Member

@WofWca WofWca commented Nov 3, 2025

Don't ask if nothing is actually going to get lost.

TODO:

  • Adjust tests for the new behavior

WofWca added 11 commits November 3, 2025 15:36
This should greatly simplify the code,
and allow for further simplifications.

This is not production-ready yet, because this removes
the throttle / debounce.
See the new TODO comments.

However, even without the debounce, the performance
doesn't seem too bad.
Even if it is, the React compiler should be able
to negate the effects of this commit.

This also fixes a minor bug with `showSendButton`.
This is a follow-up to the previous commit,
the one that lifted the draft text state
from `ComposerMessageInput` to `useDraft`.
And also save the draft when switching chats, or minimizing the app.

This the third and final commit in a series dedicated to
refactoring and fixing up `useDraft`.
The commit that removed `throttle` is actually not this one
but the first one in the series,
"refactor: lift composer text state up".

The performance, based on Chromium profiling and looking at how long
`keypress` event handler takes, seems to be pretty much unaffected
compared to when we relied on `throttle` in `ComposerMessageInputProps`.
It's still ~4ms.
And otherwise it's possible that it will actually improve,
because we send the draft to the backend much more rarely now.
An indirect thing it's that the chat list has to re-render
and to be refetched much less often, because `ChatlistItemChanged`
fires when the draft gets saved.

Closes #5252.

This should also improve the situation with
#3586
(but I'm not completely sure that things
aren't going to get worse at first).

This is also the "proper" resolution of
#3733,
which has previously been resolved by
d1fbc7a
(#4144).
So this commit also somewhat reverts that one.
Namely, when doing
- 'Share Profile'
- `webxdc.sendToChat()`
- bot command click
- `mailto:...?body=...` click

The issue was described in
#5643.
The problem was that, since we save the draft the the backend
on debounce and not immediately, it is not enough
to utilize `BackendRemote.rpc.getDraft()` to check whether
a draft is present.

So let's instead treat the source of truth for the draft state
as being inside of `useDraft`, and overall move more draft logic
to inside of `useDraft`.

The problem with this, however, is that `useDraft` is not always
rendered with the `accountId` and `chatId` that we need,
so we have to store the "set draft request"
until the correct chat has been selected and loaded.
Don't ask if nothing is actually going to get lost.
@WofWca WofWca force-pushed the wofwca/useDraft-stuff-10-3-fixed branch 11 times, most recently from 7772cf0 to 4c4ab32 Compare November 8, 2025 09:04
Base automatically changed from wofwca/useDraft-stuff-10-3-fixed to main November 8, 2025 09:04
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.

2 participants