Seeking a standard for handling Tailwind CSS layout shifts for Dioxus Web #4478
Replies: 2 comments 4 replies
-
Just sharing one possible idea. This is my main.rs mod components;
use dioxus::prelude::*;
use components::Route;
const TAILWIND_CSS: Asset = asset!("/assets/css/tailwind_output.css");
fn main() {
dioxus::launch(App);
}
#[component]
fn App() -> Element {
use_effect(move || {
document::eval(
r#"document.body.classList.add('loaded');"#
);
});
rsx! {
document::Link { rel: "stylesheet", href: TAILWIND_CSS }
Router::<Route> {}
}
} And I have customized the CSS: body {
opacity: 0;
}
body.loaded {
opacity: 1;
} CSS is loaded with Asset which should resolve to the hashed file name at production. But FOUC still happens so I made the page initially white. When the components have been loaded, the js command will make the content actually appear. I noticed FOUC is less likely to happen but it still happens sometimes. So the problem is still lurking around. |
Beta Was this translation helpful? Give feedback.
-
You can add the tailwind link without the hash to your index.html file in the root of your project (with a
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I’ve been learning Dioxus + Tailwind CSS and noticed that web tailwind projects (not using dioxus fullstack) cause Flash of Unstyled Content (FOUC) during page load. Lighthouse plugin reports a CLS of 0.95. I've noticed perhaps the problem is that Tailwind uses hashed filenames in production (e.g.,
tailwind-d2c30edb.css
), but the generatedindex.html
references a static filename:This mismatch causes the styles to not load immediately, resulting in a flash of unstyled raw HTML.
I tried to write a PowerShell script that finds the latest tailwind-*.css in the assets/ folder and updates index.html to reference the correct hashed filename, which replaces the html scramble with just a static white screen instead. I'd like to remove the flash completely. Ideally the site should not display anything until css is loaded and html is already styled.
My questions:
If anyone has faced this or knows a more idiomatic Dioxus approach, I’d appreciate your insights!
Thanks,
Remy
Beta Was this translation helpful? Give feedback.
All reactions