Skip to content

Commit 4cc2aeb

Browse files
justin808claude
andcommitted
Fix FOUC by rendering body first to collect appends, then head with pack tags
Solution: - Wrap body content in content_for :body_content at TOP of layout - This executes all react_component calls first, triggering auto-appends - Then render head with append calls followed by main pack tags - Finally yield body content Execution order: 1. content_for :body_content executes (all react_component auto-appends happen) 2. Explicit append_*_pack_tag calls in head 3. stylesheet_pack_tag and javascript_pack_tag in head (with all appends registered) 4. yield :body_content outputs the body Result: Stylesheets load in head, eliminating FOUC, while preserving auto_load_bundle functionality. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5f7c02b commit 4cc2aeb

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
<% content_for :body_content do %>
2+
<%= react_component "NavigationBarApp" %>
3+
4+
<div class="container mx-auto px-4 flex-grow">
5+
<%= yield %>
6+
</div>
7+
8+
<%= react_component "Footer" %>
9+
10+
<!-- This is a placeholder for ReactOnRails to know where to render the store props for
11+
client side hydration -->
12+
<%= redux_store_hydration_data %>
13+
<% end %>
114
<!DOCTYPE html>
215
<html>
316
<head>
@@ -8,23 +21,12 @@
821
<%= append_stylesheet_pack_tag('stimulus-bundle') %>
922
<%= append_javascript_pack_tag('stimulus-bundle') %>
1023
<%= append_javascript_pack_tag('stores-registration') %>
11-
<%= yield :packs %>
1224
<%= stylesheet_pack_tag(media: 'all', 'data-turbolinks-track': true) %>
1325
<%= javascript_pack_tag('data-turbolinks-track': true, defer: true) %>
1426

1527
<%= csrf_meta_tags %>
1628
</head>
1729
<body class="min-h-screen flex flex-col bg-sky-50 text-gray-700">
18-
<%= react_component "NavigationBarApp" %>
19-
20-
<div class="container mx-auto px-4 flex-grow">
21-
<%= yield %>
22-
</div>
23-
24-
<%= react_component "Footer" %>
25-
26-
<!-- This is a placeholder for ReactOnRails to know where to render the store props for
27-
client side hydration -->
28-
<%= redux_store_hydration_data %>
30+
<%= yield :body_content %>
2931
</body>
3032
</html>
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
<% content_for :body_content do %>
2+
<%= react_component "NavigationBarApp" %>
3+
4+
<div class="container mx-auto px-4 flex-grow">
5+
<%= yield %>
6+
</div>
7+
8+
<%= react_component "Footer" %>
9+
<% end %>
110
<!DOCTYPE html>
211
<html>
312
<head>
@@ -7,20 +16,13 @@
716

817
<%= append_stylesheet_pack_tag('stimulus-bundle') %>
918
<%= append_javascript_pack_tag('stimulus-bundle') %>
10-
<%= yield :packs %>
1119
<%= stylesheet_pack_tag(media: 'all', 'data-turbolinks-track': true) %>
1220
<%= javascript_pack_tag('data-turbolinks-track': true, defer: true) %>
1321

1422
<%= csrf_meta_tags %>
1523
</head>
1624
<body class="min-h-screen flex flex-col bg-sky-50 text-gray-700">
17-
<%= react_component "NavigationBarApp" %>
18-
19-
<div class="container mx-auto px-4 flex-grow">
20-
<%= yield %>
21-
</div>
22-
23-
<%= react_component "Footer" %>
25+
<%= yield :body_content %>
2426
</body>
2527
</html>
2628

0 commit comments

Comments
 (0)