Commit 15dd5e1
refactor: introduce WithComponents context provider (#3542)
## 🎯 Goal
Replace the prop-drilling of 120+ component overrides with a single
`WithComponents` context provider. This eliminates massive boilerplate
across `Channel`, `ChannelList`, and all consumer components.
**Before:**
```tsx
<Channel Message={MyMessage} SendButton={MySendButton} Reply={MyReply} channel={channel}>
```
**After:**
```tsx
<WithComponents overrides={{ Message: MyMessage, SendButton: MySendButton, Reply: MyReply }}>
<Channel channel={channel}>
</WithComponents>
```
## 🛠 Implementation details
### Design principle
**All components are read from `useComponentsContext()`. All other
contexts only provide data + APIs — never components.**
### New `ComponentsContext`
- `WithComponents` provider — nestable, inner overrides win. Uses
`overrides` prop (aligned with `stream-chat-react`)
- `useComponentsContext()` hook — returns all components with defaults
filled in
- `ComponentOverrides` type — auto-derived from `DEFAULT_COMPONENTS` map
(`Partial<typeof DEFAULT_COMPONENTS>`)
- `defaultComponents.ts` — single source of truth for all ~120 default
component mappings (lazy-loaded to avoid circular deps)
- Adding a new overridable component only requires editing
`defaultComponents.ts` — the type is derived automatically
### What changed
- **Stripped component keys** from `MessagesContextValue`,
`InputMessageInputContextValue`, `ChannelContextValue`,
`ChannelsContextValue`, `AttachmentPickerContextValue`,
`ThreadsContextValue`, `ImageGalleryContextValue` — these now only carry
data + APIs
- **Simplified `useCreate*Context` hooks** — no longer receive or
forward component params
- **Simplified `Channel.tsx`** — removed ~90 component imports, prop
defaults, and forwarding lines
- **Simplified `ChannelList.tsx`** — removed ~19 component props
- **Updated ~80 consumer files** — switched from old context hooks to
`useComponentsContext()` for component reads
- **Removed component override props** from ALL individual components
(Chat, Thread, ThreadList, Poll, ChannelPreview, ImageGallery, etc.)
- **No component accepts component overrides as props anymore** —
everything goes through `WithComponents`
- **`ComponentsContext.tsx` reduced from ~350 lines to ~55 lines** —
type is derived from defaults, no manual type maintenance
- **Updated all 3 example apps** (SampleApp, ExpoMessaging,
TypeScriptMessaging) to use `WithComponents`
### Net result
- **90+ files changed**, net **-2500+ lines** removed
- Each component override name went from being listed 4 times to 0 in
the forwarding pipeline
- One place to override components: `<WithComponents overrides={{ ...
}}>`
- One place to read components: `useComponentsContext()`
- One place to add new overridable components: `defaultComponents.ts`
## BREAKING CHANGE
- **Component override props removed from all SDK components** —
`<Channel Message={X}>`, `<ChannelList Preview={X}>`, `<Thread
MessageComposer={X}>`, etc. no longer accept component overrides as
props. Use `<WithComponents overrides={{ Message: X }}>` instead.
- **Component keys removed from context value types** —
`MessagesContextValue`, `InputMessageInputContextValue`,
`ChannelContextValue`, `ChannelsContextValue`,
`AttachmentPickerContextValue`, `ThreadsContextValue`,
`ImageGalleryContextValue` no longer include component-type keys. Use
`useComponentsContext()` to read component overrides.
- **`List` prop removed from `ChannelList`** — use custom
`EmptyStateIndicator` override or wrap `ChannelListView` directly.
- **`LoadingIndicator` prop removed from `Chat`** — use `<WithComponents
overrides={{ ChatLoadingIndicator: X }}>`.
## 🎨 UI Changes
No visual changes — this is a pure structural refactor.
## 🧪 Testing
- `yarn build` — 0 type errors
- `yarn lint` — passes clean (0 warnings, 0 errors)
- `yarn test:unit` — 91/92 suites pass; 1 pre-existing timeout failure
in `offline-support` that also fails on `develop`
- New test: `defaultComponents.test.ts` verifies all default component
mappings are defined and optional keys are explicitly listed
- Updated test files to use `<WithComponents overrides={...}>` wrapper
instead of removed component override props
## ☑️ Checklist
- [x] I have signed the [Stream
CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform)
(required)
- [x] PR targets the `develop` branch
- [ ] Documentation is updated
- [x] New code is tested in main example apps, including all possible
scenarios
- [x] SampleApp iOS and Android
- [x] Expo iOS and Android
---------
Co-authored-by: Ivan Sekovanikj <ivan.sekovanikj@getstream.io>1 parent 482b782 commit 15dd5e1
111 files changed
Lines changed: 1705 additions & 3203 deletions
File tree
- examples
- ExpoMessaging
- app/channel/[cid]
- components
- SampleApp/src/screens
- package
- src
- __tests__/offline-support
- components
- AttachmentPicker
- components/AttachmentMediaPicker
- Attachment
- Giphy
- UrlPreview
- AutoCompleteInput
- ChannelList
- __tests__
- hooks
- ChannelPreview
- __tests__
- Channel
- __tests__
- hooks
- Chat
- hooks
- ImageGallery
- __tests__
- components
- MessageInput
- components
- AttachmentPreview
- AudioRecorder
- InputButtons
- OutputButtons
- MessageList
- MessageMenu
- __tests__
- Message
- MessageItemView
- ReactionList
- __tests__
- Poll
- components
- PollResults
- Reply
- ThreadList
- Thread
- components
- ui/Avatar
- contexts
- attachmentPickerContext
- channelContext
- channelsContext
- chatContext
- componentsContext
- __tests__
- imageGalleryContext
- messageInputContext
- hooks
- messagesContext
- overlayContext
- __tests__
- threadsContext
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | | - | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 13 | + | |
19 | 14 | | |
20 | 15 | | |
21 | 16 | | |
| |||
254 | 249 | | |
255 | 250 | | |
256 | 251 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
265 | 266 | | |
266 | 267 | | |
267 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
268 | 277 | | |
269 | 278 | | |
270 | | - | |
271 | | - | |
272 | 279 | | |
273 | 280 | | |
274 | 281 | | |
275 | 282 | | |
276 | 283 | | |
277 | 284 | | |
278 | | - | |
279 | 285 | | |
280 | | - | |
281 | 286 | | |
282 | 287 | | |
283 | 288 | | |
| |||
306 | 311 | | |
307 | 312 | | |
308 | 313 | | |
| 314 | + | |
309 | 315 | | |
310 | 316 | | |
311 | 317 | | |
| |||
Lines changed: 30 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
338 | 339 | | |
339 | 340 | | |
340 | 341 | | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
350 | 346 | | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | 347 | | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
367 | 373 | | |
368 | 374 | | |
369 | 375 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
| |||
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
| 14 | + | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| |||
145 | 144 | | |
146 | 145 | | |
147 | 146 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 147 | + | |
| 148 | + | |
153 | 149 | | |
154 | 150 | | |
155 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
| 159 | + | |
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
183 | | - | |
184 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
185 | 186 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
195 | 200 | | |
196 | 201 | | |
197 | 202 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
151 | 158 | | |
152 | 159 | | |
153 | | - | |
154 | 160 | | |
155 | 161 | | |
156 | 162 | | |
157 | 163 | | |
158 | 164 | | |
159 | | - | |
160 | 165 | | |
161 | 166 | | |
162 | 167 | | |
| |||
174 | 179 | | |
175 | 180 | | |
176 | 181 | | |
| 182 | + | |
177 | 183 | | |
178 | 184 | | |
179 | 185 | | |
Binary file not shown.
0 commit comments