You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document defer script impact on streaming and Selective Hydration
Add comprehensive documentation explaining why deferred scripts should not
be used with streaming server rendering, as they defeat React 18's Selective
Hydration feature.
Key improvements:
- Added detailed section to streaming-server-rendering.md explaining the
interaction between defer attribute and Selective Hydration
- Updated Pro dummy app comment to clarify defer: false is required for
streaming (not just for testing hydration failure)
- Updated main dummy app comment to explain defer: true is safe there
because no streaming is used
- Documented migration path from defer to async with Shakapacker 8.2+
Breaking changes: None
Security implications: None
This affects:
- Existing installations: Clarifies best practices but doesn't change behavior
- New installations: Provides clear guidance on script loading strategies
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Copy file name to clipboardExpand all lines: docs/building-features/streaming-server-rendering.md
+58Lines changed: 58 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,3 +211,61 @@ Streaming SSR is particularly valuable in specific scenarios. Here's when to con
211
211
- Prioritize critical data that should be included in the initial HTML
212
212
- Use streaming for supplementary data that can load progressively
213
213
- Consider implementing a waterfall strategy for dependent data
214
+
215
+
### Script Loading Strategy for Streaming
216
+
217
+
**IMPORTANT**: When using streaming server rendering, you should NOT use `defer: true` for your JavaScript pack tags. Here's why:
218
+
219
+
#### Understanding the Problem with Defer
220
+
221
+
Deferred scripts (`defer: true`) only execute after the entire HTML document has finished parsing and streaming. This defeats the key benefit of React 18's Selective Hydration feature, which allows streamed components to hydrate as soon as they arrive—even while other parts of the page are still streaming.
222
+
223
+
**Example Problem:**
224
+
225
+
```erb
226
+
<!-- ❌ BAD: This delays hydration for ALL streamed components -->
0 commit comments