hydrogen icon indicating copy to clipboard operation
hydrogen copied to clipboard

[2025-07] Flash of Unstyled Content (FOUC) in production when using Tailwind CSS v4

Open juanpprieto opened this issue 4 months ago • 1 comments

[2025-07] Flash of Unstyled Content (FOUC) in production when using Tailwind CSS v4

What is the location of your example repository?

N/A - Issue occurs with default Hydrogen scaffolding

Which package or tool is having this issue?

CLI

What version of that package or tool are you using?

@shopify/cli-hydrogen@latest

What version of Remix are you using?

React Router v7 (default in current Hydrogen)

Steps to Reproduce

  1. Create a new Hydrogen project with Tailwind CSS v4
  2. Build for production (npm run build)
  3. Preview the production build (npm run preview)
  4. Navigate between routes

Expected Behavior

Styles should load before content renders. No visual flash when navigating between routes in production.

Actual Behavior

The Problem: My production Hydrogen store using Tailwind CSS experiences flash of unstyled content (FOUC), especially when third-party scripts, custom fonts, and analytics are added. Customers briefly see unstyled HTML before CSS applies.

What I Found:

  • CSS loads after JavaScript execution (no priority hints in scaffolded template)
  • Different CSS handling between dev and prod environments
  • CSS is split per route, causing flashes on navigation
  • The default root.tsx doesn't optimize CSS loading

Why This Matters: In production with real-world conditions (third-party scripts, CDN fonts, analytics), the FOUC becomes very noticeable. Customers see broken-looking pages during navigation, making the site feel slow and unprofessional. This is especially problematic for e-commerce where first impressions matter.

The issue only appears in production builds, which means developers don't catch it during development - leading to surprises after deployment.

juanpprieto avatar Aug 22 '25 04:08 juanpprieto