Skip to content

Commit c0a3b59

Browse files
justin808claude
andcommitted
Refactor to use async: true for non-Redux pages
Instead of using defer: true globally, the layout now conditionally uses async: true for optimal performance on pages without Redux shared stores, and defer: true only for pages that need it. Changes: - Added uses_redux_shared_store? helper method to ApplicationController - Updated layout to conditionally use async/defer based on page type - Pages using Redux shared stores: defer: true (9 pages) - All other pages: async: true (recommended approach) Benefits: - Modern pages get optimal TTI with async: true - Redux pages still work correctly with defer: true - Demonstrates best practice: use async unless you need defer This allows CI to pass while maximizing async usage across the app. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0e45b87 commit c0a3b59

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

spec/dummy/app/controllers/application_controller.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,23 @@ class ApplicationController < ActionController::Base
1919
redirect_to server_side_log_throw_raise_invoker_path,
2020
flash: { error: msg }
2121
end
22+
23+
helper_method :uses_redux_shared_store?
24+
25+
# Returns true if the current page uses Redux shared stores with inline registration
26+
# These pages require defer: true instead of async: true for proper script execution order
27+
def uses_redux_shared_store?
28+
# Pages that use redux_store helper with inline component registration
29+
action_name.in?(%w[
30+
index
31+
server_side_redux_app
32+
server_side_redux_app_cached
33+
server_side_hello_world_shared_store
34+
server_side_hello_world_shared_store_defer
35+
server_side_hello_world_shared_store_controller
36+
client_side_hello_world_shared_store
37+
client_side_hello_world_shared_store_defer
38+
client_side_hello_world_shared_store_controller
39+
])
40+
end
2241
end

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99

1010
<%= yield :head %>
1111

12-
<%# defer: true is required because this app uses Redux shared stores with inline component
13-
registration. With async: true, the bundle executes before inline <script> tags, causing
14-
"Could not find component" errors. See docs/building-features/streaming-server-rendering.md
15-
for details. Modern apps should move registration to bundles and use async: true. %>
16-
<%= javascript_pack_tag('client-bundle', 'data-turbo-track': 'reload', defer: true) %>
12+
<%# Conditionally use defer: true for pages with Redux shared stores (inline registration).
13+
Modern apps should use async: true for optimal performance. See docs for details:
14+
docs/building-features/streaming-server-rendering.md %>
15+
<% if uses_redux_shared_store? %>
16+
<%# defer: true required for Redux shared stores with inline component registration %>
17+
<%= javascript_pack_tag('client-bundle', 'data-turbo-track': 'reload', defer: true) %>
18+
<% else %>
19+
<%# async: true is the recommended approach for modern apps (Shakapacker >= 8.2.0) %>
20+
<%= javascript_pack_tag('client-bundle', 'data-turbo-track': 'reload', async: true) %>
21+
<% end %>
1722

1823
<%= csrf_meta_tags %>
1924
</head>

0 commit comments

Comments
 (0)