Repository navigation
Commit 290d2db
authored
fix(Message): throw when a message handler is missing a parameter (#3362)
Ticket: https://linear.app/stream/issue/REACT-1264
> **Stacked on #3360.** The base is `fix/pin-failure-notification-v15`,
so the diff shows only this change. Retarget to `master` once #3360 is
merged.
### 🎯 Goal
Follow-up from the review on #3360 and the comments on REACT-1264.
The message action handlers returned early without sending a request
when a required parameter was missing, and some only logged a
`console.warn`. The default `MessageActions` treat a resolved handler as
success, so the action showed "Message deleted", "{{ user }} has been
muted" and so on even though nothing happened. This only affects custom
messages and handlers, since `Message.tsx` always passes the message.
### 🛠 Implementation details
The guards now throw instead of returning:
| Handler | Before | Now |
| --- | --- | --- |
| `useMuteHandler` | `console.warn`, return | throws
`missingUseMuteHandlerParamsWarning` |
| `useFlagHandler` | `console.warn`, return | throws
`missingUseFlagHandlerParameterWarning` |
| `useDeleteHandler` | silent return | throws "useDeleteHandler was
called but it is missing one or more necessary parameters." |
| `usePinHandler` | silent return | throws "usePinHandler was called but
it is missing the message." |
| `useMarkUnreadHandler` | `console.warn`, return | throws "Mark unread
handler does not have access to message id" |
- The exported `missingUseMuteHandlerParamsWarning` /
`missingUseFlagHandlerParameterWarning` constants are kept and used as
the error message, so no exports change.
- The default actions show `error.message`, so a misconfigured custom
setup now shows this developer-facing message instead of a false
success. That is deliberate: it only happens when integrator code is
wrong, and it makes the bug visible.
- Known gap: that message is untranslated English, and the end user sees
it in the snackbar in every locale. Failed requests already show the
server's raw error text the same way. REACT-1285 tracks showing the
translated fallback (e.g. "Error deleting message") as the
notification's `message` while keeping the original in its `error` field
for logging. That fix covers these errors too, so this PR adds nothing
extra for it.
- The vite example's custom message UI catches `handleFlag` rejections,
like it already does for pin and delete.
- Tests: the mute and flag tests that expected a warning, and the
mark-unread tests that expected a silent no-op, now expect the error and
check that no request was sent. Delete and pin gain a missing-parameter
test.
Note for custom UIs: `handleDelete`, `handlePin`, `handleMute`,
`handleFlag` and `handleMarkUnread` now reject when called without the
parameters they need.
### 🎨 UI Changes
No visual changes. A handler called without its required parameters now
shows the error notification instead of the success one.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Bug Fixes**
* Deleting, flagging, marking unread, muting, or pinning a message now
reports an error when required message details or client information are
missing, rather than silently doing nothing.
* The example flag-message button now handles failed requests and avoids
leaving rejected errors unhandled.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent d88dbf0 commit 290d2db
11 files changed
Lines changed: 60 additions & 23 deletions
File tree
- examples/vite/src/CustomMessageUi
- src/components/Message/hooks
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
277 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
278 | 287 | | |
279 | 288 | | |
280 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
62 | 75 | | |
63 | 76 | | |
64 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
| 53 | + | |
| 54 | + | |
55 | 55 | | |
56 | | - | |
57 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
59 | | - | |
| 58 | + | |
60 | 59 | | |
61 | | - | |
62 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
171 | 182 | | |
172 | 183 | | |
173 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | 13 | | |
| 14 | + | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| |||
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
50 | | - | |
| 49 | + | |
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
54 | | - | |
| 53 | + | |
55 | 54 | | |
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
59 | | - | |
| 58 | + | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
65 | | - | |
| 64 | + | |
66 | 65 | | |
67 | 66 | | |
68 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
| 18 | + | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
| 33 | + | |
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
| |||
0 commit comments