Commit d1a8a1a
authored
Fix component registration race condition with defer loading strategy (#1972)
## Problem
CI tests were failing intermittently with component registration errors:
This was caused by a race condition where React hydration started before
component registrations completed.
## Root Cause
With script loading (default on Shakapacker >= 8.2.0):
- Both and generated component packs used
- Scripts execute as soon as downloaded, in **any order**
- When main bundle executed first, React couldn't find registered
components
## Solution
Changed default loading strategy to for deterministic execution order:
1. **Configuration** - Default to (was )
2. **Layout** - Use for (was conditional async/defer)
3. **Result** - Scripts execute in DOM order after HTML parsing
With :
- All scripts download in parallel (fast)
- Execute in DOM order after parsing
- Generated component packs execute before main bundle
- Component registrations complete before React hydration
## Testing
Fixes CI failures in:
- spec/system/integration_spec.rb[1:1:6:1:2]
- spec/system/integration_spec.rb[1:1:6:2:2]
## Files Changed
- `lib/react_on_rails/configuration.rb` - Changed default strategy to
:defer
- `spec/dummy/app/views/layouts/application.html.erb` - Always use defer
for client-bundle
- `spec/dummy/config/initializers/react_on_rails.rb` - Updated comments
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
<!-- 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/1972)
<!-- Reviewable:end -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Fixed component registration timing to ensure completion before
hydration
* **Refactor**
* Simplified component loading strategy to consistently use defer
behavior
* Removed automatic async loading detection for more predictable
configuration
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 9d2710a commit d1a8a1a
File tree
4 files changed
+17
-24
lines changed- lib/react_on_rails
- spec
- dummy
- app/views/layouts
- config/initializers
- react_on_rails
4 files changed
+17
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
158 | 158 | | |
159 | | - | |
| 159 | + | |
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
185 | 184 | | |
186 | 185 | | |
187 | 186 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
22 | 16 | | |
23 | 17 | | |
24 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
46 | 47 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
| 287 | + | |
288 | 288 | | |
289 | | - | |
| 289 | + | |
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
| 335 | + | |
336 | 336 | | |
337 | | - | |
338 | | - | |
| 337 | + | |
339 | 338 | | |
340 | 339 | | |
341 | 340 | | |
| |||
0 commit comments