-
-
Notifications
You must be signed in to change notification settings - Fork 716
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
How to use CSS Modules with TanStack Start? #3023
Comments
In addition to this. on build, the CSS is not referenced by
export default defineConfig({
server: {
preset: 'node-server',
// preset: 'cloudflare-pages',
// unenv: cloudflare,
},
})
import '@shopify/polaris/build/esm/styles.css'
import './client.css' |
Having the same flash of unstyled content (FOUC) problem. Waiting for a Messiah. |
This worked:
Full code: import {
Outlet,
ScrollRestoration,
createRootRoute,
} from '@tanstack/react-router'
import { Meta, Scripts } from '@tanstack/start'
import type { ReactNode } from 'react'
import CSS from '../app.css?url' // this
export const Route = createRootRoute({
head: () => ({
meta: [
{
charSet: 'utf-8',
},
{
name: 'viewport',
content: 'width=device-width, initial-scale=1',
},
{
title: 'TanStack Start Starter',
},
],
links: [{ rel: 'stylesheet', href: CSS }] // and this
}),
component: RootComponent,
})
function RootComponent() {
return (
<RootDocument>
<Outlet />
</RootDocument>
)
}
function RootDocument({ children }: Readonly<{ children: ReactNode }>) {
return (
<html>
<head>
<Meta />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
)
} "@tanstack/start": "^1.91.3", |
Thx @gioruu. I verified this works as well. |
@roboncode are you sure, I cloned this guys repo and I can clearly see both his red and green squares loading without styling and then being hydrated giving the 'flicker' effect. I am having the same error using pigment css |
@gioruu, your example works because you use the URL directly in the root. However, it doesn't make sense; we need to have the ability to write CSS and place it next to a component using CSS Modules. Neither CSS Modules nor imports work properly within a component. It works as expected in other frameworks like Next.js. |
@SeanCassiere could you please reopen it? Not everyone use tailwind. |
I agree with @nikolayemrikh I am trying to implement a monorepo using tanstack start. I was previously using styled-components + vite + tanstack with great success. I am shifting to tanstack start and am getting the FOUC issues on mount https://github.com/j-mcfarlane/tanstack-start-monorepo/ I believe this is inline with this error nksaraf/vinxi#79 How the FOUC do I fix this |
@j-mcfarlane, not sure about his repo but when i added the the ?url it worked for me and it started including it in my build import { AppProvider } from '@shopify/polaris'
import POLARIS_CSS from '@shopify/polaris/build/esm/styles.css?url'
import enTranslations from '@shopify/polaris/locales/en.json'
import type { ReactNode } from 'react'
import CLIENT_CSS from '../client.css?url'
import { QueryProvider } from '../providers/QueryProvider'
export const Route = createRootRoute({
head: () => ({
meta: [
{
charSet: 'utf-8',
},
{
name: 'viewport',
content: 'width=device-width, initial-scale=1',
},
{
title: 'TanStack Start Starter',
},
],
links: [
{ rel: 'stylesheet', href: CLIENT_CSS },
{ rel: 'stylesheet', href: POLARIS_CSS },
],
}),
component: RootComponent,
}) |
That's because you're not using CSS Modules in your example ;) |
Got similar issues using TailwindCSS 4.0 with TSS as well. update: now there's a new issue related to that. #2899 |
Just tried @gioruu 's solution above while setting up Tailwind with TanStack Start and I got some weird issues with it. I then realized that I had a rogue service worker running in that address (using the same port 3000 for a lot of local development stuff). After i de-registered it the issues went away and worked as expected. Probably a edge case for many, but thought I'd mention if this saves some headache from someone in the future 👍 |
I got a hydration error after running import tailwind from "~/styles/tailwind.css?url";
export const Route = createRootRoute({
head: () => ({
meta: [
{
charSet: "utf-8",
},
{
name: "viewport",
content: "width=device-width, initial-scale=1",
},
{
title: "TanStack Start Starter",
},
],
links: [{ rel: "stylesheet", href: tailwind }],
}),
component: RootComponent,
}); "tailwindcss": "4.0.0-beta.8",
"@tanstack/react-router": "^1.92.6",
"@tanstack/start": "^1.92.6",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"vinxi": "^0.5.1" |
I have same issue, is anyone can help? 🫣 |
Which project does this relate to?
Start
Describe the bug
I'm struggling to make CSS Modules work properly. Currently, the styles are being loaded only on the client, causing a flash of unstyled content (FOUC) during initial render.
I tried in this repo https://github.com/tanstack/router/tree/main/examples/react/start-basic
Your Example Website or App
https://github.com/nikolayemrikh/start-css-modules-bug
Steps to Reproduce the Bug or Issue
Expected behavior
I would like to see a working example or documentation on how to properly configure TanStack Router with CSS Modules and SSR.
The desired behavior is to have styles included in the server-rendered HTML, so there is no flash of unstyled content (FOUC).
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: