Universal route CSS preload causing render-blocking bloat in turbopack and webpack #89303
Replies: 3 comments 2 replies
-
|
Yes, this is currently expected behavior (Architecture Trade-off), but your observation on scaling is valid. The "Why" (Intent)In the App Router model,
The Optimization GapHowever, you are absolutely right that for large applications, blocking the critical path of the successful render to optimize for the failure path is a suboptimal trade-off (Lighthouse impact). Recommendations
Hope this clarifies the "Intent" vs "Side effect" question |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the clarification that makes sense. My concern is mostly about the scaling trade-off, not the behavior itself. As apps grow, prioritizing the failure path on the critical render path of every successful route starts to become noticeable especially with:
I agree that lazy-loading error UI entirely would be a UX regression, but there may be a middle ground worth exploring for example:
I’ll open a dedicated feature request to explore this more formally and attach reproduction details + measurements. Thanks again for confirming the intent this helped a lot in understanding whether this was a bug or an architectural trade-off. |
Beta Was this translation helpful? Give feedback.
-
|
Hey @dev-rohit-gupta, Sam from the Next.js team here. Let me check with some others to make sure this is expected behavior. I'll follow up shortly. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
While analyzing a Turbopack CSS issue, I noticed that CSS from universal routes (specifically
app/not-found) is being preloaded globally.After testing production builds with both Turbopack and Webpack, this does not appear to be Turbopack-only. The same behavior occurs in both pipelines.
Reproduction summary
Button.module.scssis only used inhome+not-foundThe preload link appears in unrelated routes:
This suggests universal route hoisting is promoting CSS into a higher shared chunk.
Impact
In small apps this is harmless, but in large apps it scales poorly:
Additionally, universal CSS preload appears before route-critical CSS, effectively prioritizing fallback styles over active route styles.
Question about intent
Before attempting a fix, I want to confirm:
If intentional, would there be interest in exploring an opt-out or heuristic tweak (e.g. lower-priority or deferred loading for universal error routes) so route-critical CSS remains unblocked?
Happy to prototype or explore implementation once design intent is clarified.
Related: #89252
Beta Was this translation helpful? Give feedback.
All reactions