Commit 9be387a
## Summary
Fixes #1895 - Body duplication problem when streaming SSR responses
encounter connection errors and retry.
## Problem
When streaming SSR responses encountered connection errors
mid-transmission (e.g., "descriptor closed"), the HTTPx retries plugin
would automatically retry the request. However, since partial HTML
chunks were already sent to the client, the retry would append the full
response again, resulting in duplicated/corrupted HTML and hydration
failures.
**Example of the issue:**
- Original request: sends chunks 1, 2, 3, then fails
- Retry: sends chunks 1, 2, 3, 4, 5 (all chunks)
- Client receives: 1, 2, 3, 1, 2, 3, 4, 5 (duplicated content!)
## Root Cause
The HTTPx retries plugin (configured with `max_retries: 1` in
`create_connection`) was automatically retrying failed streaming
requests. Unlike regular requests, streaming responses can be partially
transmitted before failing, so retrying at the HTTP layer causes body
duplication.
## Solution
- Disable HTTPx retries plugin specifically for streaming requests by
creating a separate connection without retries
- `StreamRequest` class already handles retries properly by starting
fresh requests (lines 78-89 in `stream_request.rb`)
- Non-streaming requests continue to use retries for persistent
connection reliability
## Changes
1. **Added `connection_without_retries` method** - Creates HTTPx
connection without retries plugin
2. **Updated `perform_request`** - Uses `connection_without_retries`
when `stream: true`
3. **Updated `reset_connection`** - Closes both connection types
4. **Updated `create_connection`** - Accepts `enable_retries` parameter
to conditionally enable retries
5. **Added test** - Verifies streaming requests use connection without
retries
## Test Plan
- [x] Added test case verifying streaming requests don't use HTTPx
retries
- [x] All existing tests pass (verified git hooks ran successfully)
- [x] RuboCop checks pass
- [x] Code follows project formatting standards
## Breaking Changes
None - This is a bug fix that changes internal implementation only.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg"
height="34" align="absmiddle"
alt="Reviewable"/>](https://reviewable.io/reviews/shakacode/react_on_rails/1900)
<!-- Reviewable:end -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Prevented duplicated chunks for streaming responses by ensuring
streaming requests do not use automatic retry behavior.
* **New Features**
* Added a secondary no-retries connection path so streaming is routed
separately from regular requests to avoid body duplication.
* **Tests**
* Added tests for streaming retry scenarios and no-duplication,
introduced a streamable test component, and updated integration
assertions and test helpers.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude <[email protected]>
1 parent 2acff83 commit 9be387a
File tree
6 files changed
+83
-20
lines changed- react_on_rails_pro
- lib/react_on_rails_pro
- spec
- dummy
- client/app/ror-auto-load-components
- spec
- helpers
- system
- react_on_rails_pro
6 files changed
+83
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
85 | 91 | | |
86 | 92 | | |
87 | 93 | | |
88 | 94 | | |
89 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
90 | 104 | | |
91 | 105 | | |
92 | 106 | | |
93 | 107 | | |
94 | 108 | | |
95 | | - | |
| 109 | + | |
96 | 110 | | |
97 | 111 | | |
98 | 112 | | |
| |||
217 | 231 | | |
218 | 232 | | |
219 | 233 | | |
220 | | - | |
| 234 | + | |
221 | 235 | | |
222 | 236 | | |
223 | 237 | | |
224 | 238 | | |
225 | 239 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
231 | 248 | | |
232 | 249 | | |
233 | 250 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
78 | 81 | | |
79 | 82 | | |
80 | 83 | | |
| |||
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| 333 | + | |
333 | 334 | | |
334 | 335 | | |
335 | 336 | | |
| |||
Lines changed: 12 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
| 177 | + | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
| 184 | + | |
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
| 189 | + | |
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
| 242 | + | |
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | | - | |
| 247 | + | |
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
410 | | - | |
411 | | - | |
412 | | - | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
420 | | - | |
421 | | - | |
| 420 | + | |
| 421 | + | |
422 | 422 | | |
423 | 423 | | |
424 | 424 | | |
| |||
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
197 | 224 | | |
198 | 225 | | |
0 commit comments