Skip to content

Commit dbd8cfe

Browse files
justin808claude
andcommitted
Revert Pro app to async and fix ReScript build in precompile hook
- Revert Pro dummy app back to async: true (Pro supports Selective Hydration) - Fix ReScript build to run from Rails root instead of current directory - Use File.join for proper path resolution of config files - Wrap build commands in Dir.chdir(rails_root) for correct execution - Add early Rails root resolution with proper error handling - Remove unnecessary defer strategy comment from initializer - Add blank line before main execution section for style 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ec22681 commit dbd8cfe

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

react_on_rails_pro/spec/dummy/app/views/layouts/application.html.erb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
media: 'all',
2525
'data-turbo-track': 'reload') %>
2626

27-
<%# Use defer: true to ensure proper script execution order.
28-
When using generated component packs (auto_load_bundle), defer ensures
29-
component registrations complete before React hydration begins.
27+
<%# async: true is the recommended approach for Shakapacker >= 8.2.0 (currently using 9.3.0).
28+
It enables React 18's Selective Hydration and provides optimal Time to Interactive (TTI).
29+
Use immediate_hydration feature to control hydration timing for Selective/Immediate Hydration.
30+
See docs/building-features/streaming-server-rendering.md
3031
skip_js_packs param is used for testing purposes to simulate hydration failure %>
3132
<% unless params[:skip_js_packs] == 'true' %>
32-
<%= javascript_pack_tag('client-bundle', 'data-turbo-track': 'reload', defer: true) %>
33+
<%= javascript_pack_tag('client-bundle', 'data-turbo-track': 'reload', async: true) %>
3334
<% end %>
3435
<%= csrf_meta_tags %>
3536
</head>

react_on_rails_pro/spec/dummy/bin/shakapacker-precompile-hook

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,35 @@ end
2222

2323
# Build ReScript if needed
2424
def build_rescript_if_needed
25+
# Find Rails root directory
26+
rails_root = find_rails_root
27+
unless rails_root
28+
warn "⚠️ Warning: Could not find Rails root. Skipping ReScript build."
29+
return
30+
end
31+
2532
# Check for both old (bsconfig.json) and new (rescript.json) config files
26-
return unless File.exist?("bsconfig.json") || File.exist?("rescript.json")
33+
bsconfig_path = File.join(rails_root, "bsconfig.json")
34+
rescript_config_path = File.join(rails_root, "rescript.json")
35+
return unless File.exist?(bsconfig_path) || File.exist?(rescript_config_path)
2736

2837
puts "🔧 Building ReScript..."
2938

3039
# Cross-platform package manager detection
3140
yarn_available = system("yarn", "--version", out: File::NULL, err: File::NULL)
3241
npm_available = system("npm", "--version", out: File::NULL, err: File::NULL)
3342

34-
success = if yarn_available
35-
system("yarn", "build:rescript")
36-
elsif npm_available
37-
system("npm", "run", "build:rescript")
38-
else
39-
warn "⚠️ Warning: Neither yarn nor npm found. Skipping ReScript build."
40-
return
41-
end
43+
# Run build command from Rails root directory
44+
success = Dir.chdir(rails_root) do
45+
if yarn_available
46+
system("yarn", "build:rescript")
47+
elsif npm_available
48+
system("npm", "run", "build:rescript")
49+
else
50+
warn "⚠️ Warning: Neither yarn nor npm found. Skipping ReScript build."
51+
return false
52+
end
53+
end
4254

4355
if success
4456
puts "✅ ReScript build completed successfully"
@@ -85,6 +97,7 @@ def generate_packs_if_needed
8597
exit 1
8698
end
8799
end
100+
88101
# Main execution
89102
begin
90103
build_rescript_if_needed

react_on_rails_pro/spec/dummy/config/initializers/react_on_rails.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ def self.adjust_props_for_client_side_hydration(_component_name, props)
3636
config.components_subdirectory = "ror-auto-load-components"
3737
config.auto_load_bundle = true
3838

39-
# Don't explicitly set generated_component_packs_loading_strategy - let it default to :defer
40-
# which ensures generated component packs load and register components before main bundle executes
41-
4239
################################################################################
4340
# Pro Feature Testing: Server Bundle Security
4441
################################################################################

0 commit comments

Comments
 (0)