-
Hey! I've been spiking on your awesome project to see if we can use it with one of our apps. However, when we do a full refresh of the page during development we have a FOUC. We are using Stimulus / Tailwindcss (now windicss). I'm loading the main CSS by importing the stylesheets from the So according to the Vite doc, it supposes to load the CSS when the associated async chunk is loaded to avoid FOUC. https://vitejs.dev/guide/features.html#css-code-splitting I'm wondering if you have any thoughts on this issue? Vite configimport { defineConfig } from 'vite'
import RubyPlugin from 'vite-plugin-ruby'
import ViteLegacy from '@vitejs/plugin-legacy'
import FullReload from 'vite-plugin-full-reload'
import StimulusHMR from 'vite-plugin-stimulus-hmr'
import WindiCSS from 'vite-plugin-windicss'
export default defineConfig({
plugins: [
RubyPlugin(),
FullReload(['config/routes.rb', 'app/views/**/*', 'app/components/**/*'], { delay: 200 }),
StimulusHMR(),
ViteLegacy({
targets: ['defaults', 'not IE 11']
}),
WindiCSS({
root: __dirname,
scan: {
fileExtensions: ['erb', 'rb', 'html', 'js'],
dirs: ['app/views', 'app/javascript', 'app/components', 'app/helpers'],
safelist: [/-span-/, /form-/, /grid-cols-/, /checked-sibling/]
}
})
]
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Hi Matthew!
I believe the documentation is talking about the Build Optimizations in Vite.js. I don't think that paragraph applies in development. Are your concerns related to the user experience once in production, or does it bother you in development? I have definitely seen FOUC during development, although after the initial load, HMR takes care of things and it does not happen again. I have not seen FOUC in production though. |
Beta Was this translation helpful? Give feedback.
-
Something that you could try in development is to render a separate Example: <%= vite_stylesheet_tag 'critical' if Rails.env.development? %> Let's say that your main JS entrypoint imports other stylesheets, such as @import "~/styles/theme.css"; Have in mind that this is only suitable for styles that you are in full control of (not dynamically injected by Vite plugins). |
Beta Was this translation helpful? Give feedback.
Something that you could try in development is to render a separate
vite_stylesheet_tag
that adds any critical CSS before the async scripts are loaded.Example:
Let's say that your main JS entrypoint imports other stylesheets, such as
theme.css
, you would then import that incritical.css
:Have in mind that this is only suitable for styles that you are in full control of (not dynamically injected by Vite plugins).