Skip to content

Conversation

justin808
Copy link
Member

@justin808 justin808 commented Oct 16, 2025

Summary

Documents the content_for pattern to prevent FOUC (Flash of Unstyled Content) when using auto_load_bundle = true with server-side rendering.

Fixes #1864

Problem

When using auto_load_bundle = true with SSR, there's a chicken-and-egg problem:

  • Stylesheets must load in the <head> to prevent FOUC
  • But react_component calls in <body> trigger append_stylesheet_pack_tag after the head has rendered
  • This violates Shakapacker's constraint that appends must happen before the main pack tag

Solution

This PR documents three solutions in the troubleshooting section:

Option 1: content_for pattern (Recommended)

Render body content BEFORE the head using content_for blocks, ensuring all auto-appends happen before the head renders:

<% content_for :body_content do %>
  <%= react_component "NavigationBarApp", prerender: true %>
  <%= yield %>
<% end %>
<!DOCTYPE html>
<html>
<head>
  <%= stylesheet_pack_tag(media: 'all') %>
</head>
<body>
  <%= yield :body_content %>
</body>
</html>

Option 2: Disable auto_load_bundle

Set auto_load_bundle = false and manually manage pack loading.

Option 3: HMR-related FOUC

Clarifies that HMR FOUC in development is separate from the SSR issue.

Changes

  • Updated: docs/core-concepts/auto-bundling-file-system-based-automated-bundle-generation.md
    • Rewrote the FOUC troubleshooting section (lines 523-594)
    • Added detailed explanation of the root cause with SSR + auto_load_bundle
    • Documented the content_for workaround pattern with full example
    • Provided alternative solutions for different architectures
    • Separated HMR FOUC from SSR FOUC issues

References

Test Plan

  • Documentation is clear and accurate
  • Code examples are properly formatted
  • All linters pass (RuboCop, ESLint, Prettier)
  • Pattern tested in react-webpack-rails-tutorial

🤖 Generated with Claude Code


This change is Reviewable

Summary by CodeRabbit

  • Documentation
    • Reworked troubleshooting to focus on SSR-related Flash of Unstyled Content (FOUC), adding a body-first rendering pattern and an option to disable auto-loading.
    • Added a dedicated FOUC guidance section with symptoms, root cause, solutions, and a quick-fix example.
    • Expanded SSR guidance for "document is not defined" errors, dynamic-import/client-only patterns, and skeleton fallbacks.
    • Broadened troubleshooting for missing bundles, manual pack issues, bundle size/performance, dev vs prod differences, and updated quick-diagnosis layout.

Copy link
Contributor

coderabbitai bot commented Oct 16, 2025

Walkthrough

Documentation updates: rework FOUC troubleshooting for file-system auto-bundling to explain SSR auto_load_bundle ordering, add content_for :body_content pattern and an alternative, expand SSR error guidance (e.g., "document is not defined"), and broaden troubleshooting and debugging guidance.

Changes

Cohort / File(s) Summary
Docs: auto-bundling / FOUC & SSR troubleshooting
docs/core-concepts/auto-bundling-file-system-based-automated-bundle-generation.md
Replace prior HMR-centric FOUC entry with SSR root-cause (late append_stylesheet_pack_tag when auto_load_bundle = true), add content_for :body_content solution with ERB example, document alternative to disable auto-loading and include packs manually, add "document is not defined" SSR guidance (dynamic imports, skeletons, client-only rendering), expand troubleshooting (bundles not generated, manual pack tag conflicts, bundle size, dev vs prod), and update related notes/resources.
Docs: deployment troubleshooting / Quick Diagnosis & FOUC
docs/deployment/troubleshooting.md
Add/rename Quick Diagnosis row to "Flash of Unstyled Content (FOUC)", insert link to new FOUC article and sample ERB body-first pattern, reorder table columns/anchors, and adjust alignment and references for SSR/installation/compilation/runtime sections.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Layout as Layout (ERB)
    participant Head as Head (stylesheet_pack_tag)
    participant Body as Body (render body)
    participant Renderer as Server Renderer (react_component)
    Note over Layout,Renderer: Original problematic flow
    Layout->>Head: render head
    Layout->>Body: render body
    Body->>Renderer: react_component (calls append_stylesheet_pack_tag)
    Renderer-->>Head: append_stylesheet_pack_tag happens after head rendered
    Note over Head: Result: stylesheets missing from head -> FOUC
Loading
sequenceDiagram
    autonumber
    participant Layout as Layout (ERB with content_for)
    participant Collector as content_for(:body_content)
    participant Renderer as Server Renderer (react_component)
    participant Head as Head (stylesheet_pack_tag)
    participant Body as Body (yield :body_content)
    Note over Layout,Renderer: Revised flow using content_for to collect body first
    Layout->>Collector: capture body rendering (react_component -> append_stylesheet_pack_tag collected)
    Collector-->>Layout: body content + collected appends available
    Layout->>Head: render head with collected append_stylesheet_pack_tag before stylesheet_pack_tag
    Layout->>Body: render body via yield :body_content
    Note over Head,Body: Result: stylesheets present in head before body -> avoids FOUC
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • Judahmeek

Poem

🐇 I nudged the docs to chase the sun,
Pulled body-first so styles would run,
No flash of white, the layout hums,
Bundles land where goodness comes,
Hooray — the page is nicely done.

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Document content_for pattern to prevent FOUC with SSR and auto_load_bundle (#1864)" is clear, specific, and directly summarizes the main change. It accurately reflects the primary objective of the changeset, which is to document a solution pattern for preventing Flash of Unstyled Content when using server-side rendering with auto_load_bundle. The title is concise and avoids vague language, making it immediately understandable to someone reviewing the repository history.
Linked Issues Check ✅ Passed The PR successfully addresses the core coding requirements of issue #1864. It documents the root cause of the FOUC problem with SSR and auto_load_bundle, clearly explaining why stylesheets must load in the head but auto-appends occur during body rendering. The changeset implements Option 1 (document the pattern) from the proposed solutions by providing a detailed code example demonstrating the content_for :body_content pattern, which is the primary workaround needed to prevent FOUC. Additionally, the PR documents alternatives such as disabling auto_load_bundle for manual control and clarifies that HMR-related FOUC is a separate concern, providing developers with multiple pathways depending on their architecture.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fouc-auto-load-bundle-docs

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32c22aa and 53f08fd.

📒 Files selected for processing (2)
  • docs/core-concepts/auto-bundling-file-system-based-automated-bundle-generation.md (1 hunks)
  • docs/deployment/troubleshooting.md (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx,css,scss,json,yml,yaml,md}

📄 CodeRabbit inference engine (CLAUDE.md)

Prettier is the sole authority for formatting all non-Ruby files; never manually format them

Files:

  • docs/deployment/troubleshooting.md
  • docs/core-concepts/auto-bundling-file-system-based-automated-bundle-generation.md
🪛 LanguageTool
docs/core-concepts/auto-bundling-file-system-based-automated-bundle-generation.md

[grammar] ~572-~572: There might be a mistake here.
Context: ...hakapacker Preventing FOUC documentation](https://github.com/shakacode/shakapacker/blob/master/docs/preventing_fouc.md) - Working example: [react-webpack-rails-...

(QB_NEW_EN)


[grammar] ~573-~573: There might be a mistake here.
Context: ...*: react-webpack-rails-tutorial PR #686 - Related issue: [Shakapacker #720](http...

(QB_NEW_EN)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: build-dummy-app-webpack-test-bundles (3.2, 20)
  • GitHub Check: build
  • GitHub Check: claude-review
  • GitHub Check: rspec-package-tests (3.2, minimum)
  • GitHub Check: build-and-test
🔇 Additional comments (5)
docs/deployment/troubleshooting.md (2)

9-16: Quick Diagnosis table updates look good. The reordering and new "Styling (FOUC)" row provide clear navigation. The anchor link to #flash-of-unstyled-content-fouc should correctly resolve to the section heading.


168-193: FOUC quick-fix section is clear and actionable. The ERB code example correctly demonstrates the content_for :body_content pattern, and the reference to the comprehensive guide in the auto-bundling file (line 176) is helpful for users seeking deeper understanding.

Please confirm that the external link on line 176 (../core-concepts/auto-bundling-file-system-based-automated-bundle-generation.md#2-css-not-loading-fouc---flash-of-unstyled-content) correctly maps to the section heading in the auto-bundling file.

docs/core-concepts/auto-bundling-file-system-based-automated-bundle-generation.md (3)

523-577: Comprehensive FOUC documentation is well-structured and addresses PR objectives. The section clearly explains the root cause of the auto_load_bundle ordering issue with SSR, provides a detailed step-by-step solution using the content_for :body_content pattern with a complete ERB example, documents an alternative (disabling auto_load_bundle), and distinguishes development HMR-related FOUC from production SSR FOUC.


534-559: ERB code example is syntactically correct and well-documented. The three-step comment structure (Step 1: capture content and trigger appends, Step 2: render head with accumulated tags, Step 3: render captured body content) effectively explains the counter-intuitive execution order when using content_for before the HTML declaration.


570-576: External resource references are helpful, but verify link validity. The references to Shakapacker's FOUC prevention guide, react-webpack-rails-tutorial PR #686, and Shakapacker issue #720 provide concrete examples and context. Static analysis flagged potential grammar issues around these lines—if these are false positives, they can be safely ignored, but please verify the links remain active and accurately point to the intended resources.

Verify that the three external links (Shakapacker docs, tutorial PR, and issue) are current and accurate:


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

claude bot commented Oct 16, 2025

PR Review: Document content_for pattern to prevent FOUC with SSR and auto_load_bundle

Summary

This PR provides excellent documentation for a non-trivial SSR + auto_load_bundle issue. The changes are well-structured, clear, and provide actionable solutions.

Strengths

1. Clear Problem Definition

The PR does an excellent job explaining the root cause:

  • Clearly identifies the chicken-and-egg problem with Shakapacker's stylesheet tag ordering
  • Distinguishes between SSR FOUC and HMR FOUC (important!)
  • Provides proper context for when this issue occurs

2. Well-Structured Solutions

The three-option approach is excellent:

  • Option 1 (content_for): Recommended solution with full example
  • Option 2 (disable auto_load_bundle): Alternative for different architectures
  • Option 3 (HMR FOUC): Clarifies development-only concerns

This gives users flexibility based on their specific needs.

3. Code Examples

The ERB examples are:

  • Complete and runnable
  • Well-commented
  • Include important Rails helpers (csrf_meta_tags, csp_meta_tag)
  • Show realistic component placement

4. Documentation Quality

  • Clear progression from problem → cause → solutions
  • Proper use of markdown formatting
  • Helpful inline comments in code blocks
  • References to working example and related issues

Minor Suggestions

1. Clarify the "counter-intuitive" note

Line 561 mentions that the pattern "may seem counter-intuitive" but could be slightly clearer:

**Note**: While this pattern may seem counter-intuitive (rendering body content before `<!DOCTYPE html>`), it ensures proper stylesheet loading order and prevents FOUC. Rails processes the `content_for` block first, capturing the content, but renders the actual HTML in document order.

This addition clarifies that Rails still outputs proper HTML structure.

2. Consider adding a decision tree

For users wondering which option to choose, consider adding:

**Which option should I use?**
- Using SSR + auto_load_bundle? → Use Option 1 (content_for)
- Need fine-grained control over pack loading? → Use Option 2 (manual)
- Seeing FOUC only in development with HMR? → See Option 3 (expected behavior)

3. Trailing newline check

Per CLAUDE.md requirements, verify the file ends with a newline character.

4. Cross-reference opportunity

Consider adding a forward reference in the auto_load_bundle introduction (earlier in the doc) mentioning that SSR users should read the FOUC troubleshooting section.

Code Quality Assessment

Documentation: Excellent
Clarity: Very clear and well-organized
Completeness: Covers all major scenarios
Accuracy: Technical explanation is correct
Examples: Complete and realistic

Potential Issues

None identified - but verify:

  1. ✅ File ends with newline (per CLAUDE.md)
  2. ✅ Prettier formatting applied (markdown files)
  3. ✅ Links are valid and accessible
  4. ✅ Code examples follow Rails best practices

Test Coverage

As this is documentation-only, traditional test coverage doesn't apply. However:

  • ✅ Author mentions testing in react-webpack-rails-tutorial
  • ✅ Provides link to working example PR
  • ✅ Clear test plan in PR description

Security Concerns

✅ None - documentation only, no code changes

Performance Considerations

✅ None - the documented pattern doesn't add performance overhead (content_for is zero-cost abstraction)

Recommendations

  1. Approve and merge - this is high-quality documentation
  2. Consider the minor clarification suggestions above in a follow-up (optional)
  3. Ensure file has trailing newline before merge (per CLAUDE.md requirements)

Overall Assessment

Score: 9.5/10

This PR significantly improves the documentation by solving a real pain point users encounter with SSR + auto_load_bundle. The explanations are clear, solutions are practical, and the organization is excellent.

The minor suggestions above are truly minor - this PR is ready to merge as-is, pending the standard formatting checks.

Great work documenting this tricky interaction! 🎯

Copy link

claude bot commented Oct 16, 2025

Code Review: PR #1865

Overall Assessment

Approved with minor suggestions

This is an excellent documentation update that addresses a real pain point for users implementing SSR with auto_load_bundle. The technical explanation is accurate and the solutions are practical.


Strengths

1. Clear Problem Definition

  • Excellent explanation of the root cause: the chicken-and-egg problem between react_component calls triggering append_stylesheet_pack_tag in the body while stylesheet_pack_tag needs to be in the head
  • The technical detail about Shakapacker's constraint is valuable for understanding WHY this happens

2. Comprehensive Solutions

  • Three well-structured options (content_for pattern, disabling auto_load_bundle, HMR clarification)
  • Code examples are complete and functional
  • Proper prioritization (Option 1 as recommended)

3. Code Example Quality

  • The ERB example in Option 1 is complete and shows the full layout structure
  • Includes all necessary Rails helpers (csrf_meta_tags, csp_meta_tag)
  • Demonstrates proper defer usage for JavaScript

Suggestions for Improvement

1. Minor Typo/Formatting (Line 560)

- **Note**: While this pattern may seem counter-intuitive (body content before `<!DOCTYPE html>`), it ensures proper stylesheet loading order and prevents FOUC.
+ **Note**: While this pattern may seem counter-intuitive (body content defined before `<!DOCTYPE html>`), it ensures proper stylesheet loading order and prevents FOUC.

The word "defined" adds clarity that we're defining the content block, not literally rendering the body before DOCTYPE.

2. Enhanced Explanation (Optional)

Consider adding a brief note about execution order:

<% # Step 1: This block executes first, defining body_content AND triggering auto-appends %>
<% content_for :body_content do %>
  <%= react_component "NavigationBarApp", prerender: true %>
<% end %>

<% # Step 2: Then the head renders with all accumulated stylesheet appends %>
<head>
  <%= stylesheet_pack_tag(media: 'all') %>
</head>

<% # Step 3: Finally, the defined body_content is yielded here %>
<body>
  <%= yield :body_content %>
</body>

This could help readers understand the execution flow more clearly.

3. Cross-Reference Opportunity (Line 594+)

The new section mentions "Additional checks" but these seem to be generic CSS troubleshooting. Consider explicitly noting:

**Additional checks** (for all FOUC issues):
- **Layout**: Verify your layout includes `<%= stylesheet_pack_tag %>` placeholder
- **Component imports**: Check that CSS files are properly imported: `import styles from './Component.module.css';`

For SSR-specific FOUC with auto_load_bundle, see Options 1-2 above.

Testing Verification

Documentation-only change - No code execution tests needed

  • Linting would pass (markdown file)
  • Referenced working example exists in react-webpack-rails-tutorial
  • Pattern is validated in real-world usage

Security & Performance

No concerns

  • Documentation change only
  • No security implications
  • No performance implications
  • The recommended pattern (Option 1) is actually MORE performant as it prevents FOUC

Alignment with CLAUDE.md

Follows repository conventions

  • Documentation is clear and well-structured
  • Code examples follow ERB best practices
  • Maintains the troubleshooting section structure

Final Recommendation

LGTM - Approve and Merge 🚀

This PR significantly improves the documentation for a common pitfall. The only suggestions above are minor enhancements that could be addressed in a follow-up if desired, but they shouldn't block merging.

Impact: High positive impact - will save users significant debugging time on a confusing issue.

@justin808 justin808 force-pushed the fouc-auto-load-bundle-docs branch 2 times, most recently from 921af01 to 32c22aa Compare October 16, 2025 20:55
justin808 added a commit that referenced this pull request Oct 16, 2025
…undle

Fixes #1864

When using auto_load_bundle = true with server-side rendering, there's a
chicken-and-egg problem: stylesheets must load in the <head>, but
react_component calls in <body> trigger auto-appends after the head has
rendered, causing FOUC (Flash of Unstyled Content).

This commit documents the content_for workaround pattern and references
the comprehensive Shakapacker FOUC prevention guide (PR #737).

Key improvements:
- Explains the root cause of FOUC with SSR + auto_load_bundle
- Documents the content_for :body_content pattern with execution flow
- Added step-by-step comments showing Rails execution order
- References Shakapacker's comprehensive FOUC prevention documentation
- Links to working example in react-webpack-rails-tutorial PR #686
- Provides alternative solution (disable auto_load_bundle)
- Clarifies that HMR FOUC is separate from this SSR issue
- Addresses code review feedback from PR #1865 comment #3412140475

Aligns with Shakapacker PR #737 preventing_fouc.md documentation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copy link

claude bot commented Oct 16, 2025

Code Review - PR #1865

✅ Overall Assessment

This is an excellent documentation improvement that addresses a real pain point for developers using SSR with auto_load_bundle = true. The PR is well-structured, clear, and follows best practices.


🎯 Strengths

1. Clear Problem Statement

  • Excellent job explaining the root cause of the FOUC issue
  • The "chicken-and-egg" problem description is accurate and easy to understand
  • Good distinction between SSR-related FOUC vs HMR-related FOUC

2. Comprehensive Solution Documentation

  • The content_for :body_content pattern is well-documented with a complete, working example
  • Step-by-step comments in the ERB example make the execution order crystal clear
  • Alternative solution (disabling auto_load_bundle) provides flexibility

3. Good Resource Links

4. Code Quality

  • Documentation follows markdown best practices
  • Code examples are properly formatted and indented
  • No linting issues (as verified by CI)

💡 Suggestions for Enhancement

1. Technical Clarification - Line 549

Consider adding a more explicit comment about why the stylesheet appends work:

  <%# Step 2: Head renders with all accumulated stylesheet/JS appends %>
  <%# Note: Empty stylesheet_pack_tag() calls render ALL accumulated appends %>
  <%= stylesheet_pack_tag(media: 'all') %>
  <%= javascript_pack_tag(defer: true) %>

This would help developers understand that calling stylesheet_pack_tag() without arguments is intentional and renders all auto-appended packs.

2. Potential Gotcha - Line 559-564

When documenting the alternative solution, consider mentioning the trade-off:

# config/initializers/react_on_rails.rb
config.auto_load_bundle = false
# Trade-off: You'll need to manually add pack tags for each component bundle
# Example: <%= javascript_pack_tag 'NavigationBarApp' %>

This helps developers make an informed decision.

3. Minor: Consistency in Line 550

The HTML comment syntax differs from ERB comments:

  <%# Step 2: Head renders with all accumulated stylesheet/JS appends %>
  <%= stylesheet_pack_tag(media: 'all') %>

vs. the original:

  <!-- All auto-appended stylesheets will be included here -->

Recommendation: Keep the HTML comment style for consistency with typical Rails layouts, or convert to ERB comment style (I personally prefer ERB comments in .html.erb files for clarity).

4. Educational Enhancement

Consider adding a brief "Why this works" explanation:

**How this pattern solves the problem**:

1. Rails processes the `content_for :body_content` block first
2. During this processing, `react_component` calls trigger `append_stylesheet_pack_tag`
3. These appends are queued in memory
4. When `stylesheet_pack_tag` is called in `<head>`, it renders all queued appends
5. Finally, the captured body content is yielded into the `<body>`

🔒 Security Considerations

No security concerns - This is documentation-only change with no code execution or data handling modifications.


🧪 Test Coverage

Appropriate for documentation - The PR references a working implementation in react-webpack-rails-tutorial PR #686, which serves as validation.

Optional: Consider adding a spec file test in spec/dummy that demonstrates this pattern working correctly, especially since this is addressing a bug (#1864).


🎨 Style & Conventions

Follows CLAUDE.md requirements:

  • Documentation is clear and accurate
  • Code examples are properly formatted
  • Markdown formatting is consistent
  • Links are valid and helpful

⚡ Performance Considerations

No performance impact - Documentation-only change. The content_for pattern has no runtime overhead compared to the broken approach.


🐛 Potential Issues

None identified - The solution is technically sound and well-documented.


📝 Final Recommendation

✅ APPROVE with minor suggestions

This PR significantly improves the developer experience by documenting a critical SSR+auto-bundling pattern. The suggestions above are optional enhancements that could make good documentation even better, but they don't block merging.

Action Items (all optional):

  1. Consider clarifying that stylesheet_pack_tag() without args renders all appends
  2. Document the trade-off when disabling auto_load_bundle
  3. Consider standardizing comment style (ERB vs HTML comments)
  4. Optionally add a working spec example in spec/dummy

Great work addressing issue #1864! 🎉


Review conducted following repository CLAUDE.md guidelines

Copy link

claude bot commented Oct 16, 2025

Pull Request Review

Summary

This PR provides excellent documentation improvements for addressing FOUC issues with SSR and auto_load_bundle. The changes are clear, well-structured, and provide practical solutions.


Strengths

1. Clear Problem Definition

  • Excellent explanation of the root cause linking SSR, auto_load_bundle, and Shakapacker timing requirements
  • The chicken-and-egg problem is articulated clearly

2. Comprehensive Solution Documentation

  • The content_for pattern is well-documented with a complete working example
  • Step-by-step comments help developers understand execution order
  • Alternative solution provided for edge cases

3. Quality Code Examples

  • The ERB example is production-ready and self-contained
  • Includes essential Rails helpers
  • Shows realistic use cases

4. Excellent Supporting Resources

  • Links to Shakapacker documentation
  • Working example in react-webpack-rails-tutorial
  • Related issue for context

5. Proper Scope Separation

  • Clearly distinguishes HMR-related FOUC from SSR FOUC issues

Minor Suggestions

1. Typo (Line 561)
Change "counter-intuitive" to "counterintuitive" (one word is standard)

2. Code Comment (Line 555)
Consider simplifying: "Step 3: The captured body_content is output here"

3. Technical Precision (Line 527)
Consider clarifying: "the append_stylesheet_pack_tag calls happen too late to be included in the already-rendered head"


Assessment

Documentation Standards: Excellent
Technical Accuracy: Verified
Completeness: Comprehensive
Best Practices: Followed
Security: No concerns
Test Coverage: Appropriate for documentation
Performance: Positive impact


Overall

Rating: 5/5 Excellent

Recommendation: Approve with minor optional refinements

The suggested improvements are cosmetic and do not block approval. The PR is ready to merge as-is.


Additional Notes

  • Consider adding this pattern to the main tutorial if FOUC is common
  • Ensure Shakapacker links remain valid after reorganizations

Great work on improving the developer experience!

…undle

Fixes #1864

When using auto_load_bundle = true with server-side rendering, there's a
chicken-and-egg problem: stylesheets must load in the <head>, but
react_component calls in <body> trigger auto-appends after the head has
rendered, causing FOUC (Flash of Unstyled Content).

This commit documents the content_for workaround pattern and references
the comprehensive Shakapacker FOUC prevention guide (PR #737).

Key improvements:
- Explains the root cause of FOUC with SSR + auto_load_bundle
- Documents the content_for :body_content pattern with execution flow
- Added step-by-step comments showing Rails execution order
- References Shakapacker's comprehensive FOUC prevention documentation
- Links to working example in react-webpack-rails-tutorial PR #686
- Provides alternative solution (disable auto_load_bundle)
- Clarifies that HMR FOUC is separate from this SSR issue
- Addresses code review feedback from PR #1865 comment #3412140475
- Adds FOUC troubleshooting section to docs/deployment/troubleshooting.md
- Includes quick fix example and link to detailed guide

Aligns with Shakapacker PR #737 preventing_fouc.md documentation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@justin808 justin808 force-pushed the fouc-auto-load-bundle-docs branch from 32c22aa to 53f08fd Compare October 17, 2025 01:37
Copy link

claude bot commented Oct 17, 2025

Code Review: PR #1865 - Document content_for pattern to prevent FOUC

Overall Assessment: ✅ Excellent Documentation Improvement

This PR provides clear, actionable documentation for a common FOUC issue when using SSR with auto_load_bundle. The changes are well-structured, technically accurate, and provide multiple solution paths.


✅ Strengths

1. Clear Problem Definition

  • Excellent explanation of the root cause (chicken-and-egg problem with stylesheet appends)
  • Technical details about Shakapacker's constraints are accurate
  • Clearly distinguishes between different types of FOUC (SSR vs HMR)

2. Comprehensive Solutions

  • Primary solution (content_for pattern) is well-documented with complete example
  • Alternative approaches provided (disabling auto_load_bundle)
  • Good use of inline comments in code examples explaining the execution order

3. Code Quality

  • ERB examples are properly formatted and syntactically correct
  • Examples follow Rails conventions
  • Step-by-step comments in the code example are particularly helpful

4. Documentation Structure

  • Clear organization with Problem, Root Cause, Solution, and Alternative sections
  • Cross-references to related documentation are appropriate
  • Added to troubleshooting index for easy discovery

💡 Suggestions for Improvement

1. Minor: Link Validation

The PR references several external resources. Consider verifying these links are accessible and anchors work correctly.

2. Minor: Example Completeness

In troubleshooting.md:180-193, the Quick fix example is minimal. Consider adding a comment indicating it's a simplified example.

3. Terminology Consistency

The phrase 'body content before ' (line 561) might confuse beginners. Consider clarifying that Rails processes blocks in execution order, not file order.


🔒 Security Considerations

✅ No security concerns - This is documentation-only with safe ERB examples.


⚡ Performance Considerations

✅ Positive impact - The documented solution prevents FOUC, improving perceived performance and user experience.


🧪 Test Coverage

✅ Documentation tested - The PR mentions testing in react-webpack-rails-tutorial, which is appropriate for documentation changes.


🎯 Recommendation

APPROVE - This is a high-quality documentation improvement that solves a real pain point. The suggestions above are minor enhancements that don't block approval.

The PR successfully:

  1. ✅ Clearly explains a complex rendering order issue
  2. ✅ Provides working solutions with complete examples
  3. ✅ Offers alternatives for different use cases
  4. ✅ Maintains consistency with existing documentation style
  5. ✅ Adds proper cross-references for discoverability

Great work! This will help many developers avoid a confusing FOUC issue.


Files reviewed:

  • docs/core-concepts/auto-bundling-file-system-based-automated-bundle-generation.md:523-594
  • docs/deployment/troubleshooting.md:6-193

@justin808 justin808 merged commit 2b5bab8 into master Oct 17, 2025
14 of 15 checks passed
@justin808 justin808 deleted the fouc-auto-load-bundle-docs branch October 17, 2025 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FOUC with auto_load_bundle: Need better pattern for stylesheet_pack_tag in head

1 participant