Fix unstyled modals in dev: re-read document styles after page load#4242
Conversation
documentStylesSheet() read the document's <style> tags once at module-eval time, but in dev Vite injects the Tailwind styles during module evaluation, after that read — so shadow-DOM modals got a near-empty stylesheet (7 rules instead of the full Tailwind sheet) and rendered unstyled. Production was unaffected because the styles come from a <link> that is fetched by URL. Re-populate the constructed sheet once the window load event fires; constructed sheets are live, so already-rendered components pick the styles up automatically. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe PR fixes a development-time race condition where the shared stylesheet module initializes before Vite injects the page's ChangesDev HMR Stylesheet Population Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed due to a network error. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
Since #4229, modals render unstyled in
npm run dev(no black backdrop, no Tailwind styling). Production/staging is unaffected.documentStylesSheet()reads the document's<style>tags once, at module-eval time. In dev, Vite injects the Tailwind styles during module evaluation — after that read — so the shared constructed stylesheet ended up with 7 CSS rules instead of the full Tailwind sheet. In production the styles come from a<link rel=stylesheet>that is fetched by URL, so timing doesn't matter there.Fix
If the document hasn't finished loading when the sheet is first created, re-populate it once on the window
loadevent (which fires after the entry module graph — and therefore all style injection — completes). Constructed stylesheets are live, so already-rendered components pick the styles up without re-rendering. The existing HMR re-populate hook is unchanged.Test plan
npx tsc --noEmit, ESLint clean🤖 Generated with Claude Code