Styles for specific component loading after render
Hey there 👋 It seems that when I use a css stylesheet in a specific component, the styles are loading a short time after the initial page render, causing a flash of styling to moments after page load. This issue persists even when the stylesheet is imported in the route file only as opposed to the component file. When I move the styling to the global css file, it obviously works. Does stylesheet bundling not work on a per-route basis or per-component basis?
What is the best way to ensure these styles are available upon first render?
4 Replies
harsh-harlequin•4mo ago
is this in dev only?
we will need to collect styles in dev to prevent this
flat-fuchsiaOP•3mo ago
I haven't been able to test outside of the dev server, but I will test soon. Am I approaching styling incorrectly here?
harsh-harlequin•3mo ago
no, it's just that for the SSR response during dev we don't get the styles from vite (only for production build). so we will need to implement our own style collection for dev
wise-white•3mo ago
For now, you should import global styles with "?url" suffix and add a head to your root route like below
https://tanstack.com/start/latest/docs/framework/react/tailwind-integration#import-the-css-file-in-your-__roottsx-file
(I am not sure of the interaction with css modules though, it might also flash)