-
Notifications
You must be signed in to change notification settings - Fork 59
FOUC with components inside Suspense #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I believe this is due to things like this e.g. in ProgressBar:
Including this component outside of any Suspense renders properly in SSR. I'm not sure if any work-arounds short of including a hidden copy of the element outside of Suspense to get the css to load during SSR. |
I think of two solutions:
Both of these solutions will deprecate |
Makes sense that there would would need to be some sort of pass like tailwind does to collect styles, but I'm confused if it's actually required. The html content is there because cargo leptos runs all Suspense components once in SSR to know if it needs to suspend, so I'm not clear why that couldn't be used to pick up styles, using the Style component for example in leptos meta for example, which sticks any styles it finds in the head |
Also if it helps, I have been using a a bit of a hack that solves the issue by including specific thaw components above the Suspense boundary with a style of |
Because leptos_meta is deeply integrated with leptos_axum. Related code: // The build_response function executes the `SSRMountStyleProvider` component
// (which completes the style collection here)
// and the asynchronous function that collects `Suspend`.
let (owner, stream) = build_response(
app_fn,
additional_context,
stream_builder,
supports_ooo,
);
let sc = owner.shared_context().unwrap();
let stream = stream.await.ready_chunks(32).map(|n| n.join(""));
// Executes the asynchronous function collected by `Suspend`
while let Some(pending) = sc.await_deferred() {
pending.await;
}
// `leptos_meta` will inject styles after the asynchronous functions collected by `Suspend` are executed
let mut stream = Box::pin(
meta_context.inject_meta_context(stream).await.then({
let sc = Arc::clone(&sc);
move |chunk| {
let sc = Arc::clone(&sc);
async move {
while let Some(pending) = sc.await_deferred() {
pending.await;
}
chunk
}
}
}),
);``` |
Ah! Thanks for the context. A build.rs seems fine, but just wondering what the impact would be for including a lot of css on conditional paths, when the source of truth for SSR is actually running the code. Is there a possibility of adding a generic SSR injection mechanism similar to how leptos-use implements for use_cookie? Or just adding axum/actix feature flags for SSR? |
Flash of unstyled content when using components inside Suspense.
Does not happen 100% of the time, but frequently enough:
Minimal repo, with Thaw
0.4.6
and Leptos0.7.8
:The text was updated successfully, but these errors were encountered: