Skip to content

Commit 257214d

Browse files
justin808claude
andcommitted
Add environment variable control for testing loading strategies
Makes it easy to reproduce CI failures locally by testing with different script loading strategies (async vs defer) without code changes. Changes: - spec/dummy/config/initializers/react_on_rails.rb: Use REACT_ON_RAILS_LOADING_STRATEGY env var - spec/dummy/TESTING_LOCALLY.md: Add section on reproducing race condition failures Usage: # Test with defer (default, prevents race conditions) bundle exec rspec spec/system/integration_spec.rb -e "shared_store" # Test with async (library default for users, may show race conditions) env REACT_ON_RAILS_LOADING_STRATEGY=async bundle exec rspec spec/system/integration_spec.rb -e "shared_store" This eliminates the need for .example files and provides a simple, documented way to test both loading strategies locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent b46ece7 commit 257214d

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

spec/dummy/TESTING_LOCALLY.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,50 @@
11
# Testing Locally
22

3+
## Reproducing CI Failures with Component Registration Race Conditions
4+
5+
If you see CI failures like "Could not find component registered with name ReduxSharedStoreApp", this is due to a race condition with async script loading. Here's how to reproduce and fix it locally:
6+
7+
### Quick Reproduction
8+
9+
```bash
10+
cd spec/dummy
11+
12+
# Test with async loading (CI default for library users)
13+
REACT_ON_RAILS_LOADING_STRATEGY=async bundle exec rspec spec/system/integration_spec.rb -e "shared_store"
14+
15+
# If that passes but CI fails, run multiple times to catch intermittent failures:
16+
for i in {1..5}; do
17+
echo "Run $i:"
18+
REACT_ON_RAILS_LOADING_STRATEGY=async bundle exec rspec spec/system/integration_spec.rb:376 spec/system/integration_spec.rb:380
19+
done
20+
```
21+
22+
### Understanding the Issue
23+
24+
- **The dummy app defaults to `:defer`** to prevent race conditions during development
25+
- **Real user apps default to `:async`** (when Shakapacker >= 8.2.0) for better performance
26+
- **The race condition**: With async, `client-bundle.js` can execute before generated component packs, causing components to be missing from the registry when React tries to hydrate
27+
28+
### The Fix
29+
30+
The dummy app uses an environment variable to control the loading strategy:
31+
32+
```ruby
33+
# spec/dummy/config/initializers/react_on_rails.rb
34+
loading_strategy = ENV.fetch("REACT_ON_RAILS_LOADING_STRATEGY", "defer").to_sym
35+
config.generated_component_packs_loading_strategy = loading_strategy
36+
```
37+
38+
This allows testing both strategies without code changes.
39+
40+
### When CI Fails But Local Passes
41+
42+
1. **Check the loading strategy**: CI may be testing with `:async` while you're testing with `:defer`
43+
2. **Run with async locally**: Use the environment variable to match CI conditions
44+
3. **If it's intermittent**: The race condition timing varies - run tests multiple times
45+
46+
### SSL Issues (Not Related to Component Registration)
47+
348
## Known Issues with Ruby 3.4.3 + OpenSSL 3.6
449

550
If you're running Ruby 3.4.3 with OpenSSL 3.6+, you may encounter SSL certificate verification errors in system tests:

spec/dummy/config/initializers/react_on_rails.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,10 @@ def self.adjust_props_for_client_side_hydration(component_name, props)
4242
config.components_subdirectory = "startup"
4343
config.auto_load_bundle = true
4444
config.immediate_hydration = false
45-
config.generated_component_packs_loading_strategy = :defer
45+
46+
# Use :defer to prevent race conditions with auto-generated component packs.
47+
# To test with :async (CI default), set: REACT_ON_RAILS_LOADING_STRATEGY=async
48+
# See: spec/dummy/TESTING_LOCALLY.md for reproducing CI failures
49+
loading_strategy = ENV.fetch("REACT_ON_RAILS_LOADING_STRATEGY", "defer").to_sym
50+
config.generated_component_packs_loading_strategy = loading_strategy
4651
end

0 commit comments

Comments
 (0)