router: Hydration mismatch errors in linked stylesheets.

Which project does this relate to?

Start

Describe the bug

After making a change that introduces an exception in the css loading, once you’ve corrected the error, you’ll get a persistent hydration mismatch until the vinxi server is restarted. This continues even after hard refreshes of the page.

Your Example Website or App

https://stackblitz.com/github/tanstack/router/tree/main/examples/react/start-basic

Steps to Reproduce the Bug or Issue

  1. Make a change in the css with an error, e.g., sahflsdjfhls somewhere in the file.
  2. See the error. HMR doesn’t seem to work on stackblitz, but you’ll see it locally immediately.
  3. Correct the error. The CSS is fixed, but you’ll have a hydration mismatch in the console.

Expected behavior

I expect to not have any error messages after correcting the CSS.

Screenshots or Videos

Video

Platform

  • OS: macOS
  • Browser: Chrome and Firefox

Additional context

I noticed while recording the video that the error happened again after restarting Vinxi without making any erroneous edits to the CSS, just refreshing the page. 🤷‍♂

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 20
  • Comments: 26 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Also getting this error with a new create-tsrouter-app. It happens with any change in the CSS, either in styles.css or any JSX. Restarting the dev server somewhat fixes it, editing styles.css reintroduces it but editing JSX is fine. Package versions:

I do have a postcss.config.ts file with the same contents as what @oveigam suggested (generated by create-tsrouter-app)

I saw a similar error on both 4.1.10 and 4.0.7, but my problem was that I tried to include styles as ?url and manually append them to the head. Letting vite take care of the CSS worked just fine.

 import { Paragraph } from "~/components/atoms/paragraph";
 import { Footer } from "~/components/molecules/footer";
 import { Header } from "~/components/molecules/header";
-import styles from "~/globals.css?url";
+import "../globals.css";

 export const Route = createRootRoute({
   head: () => ({
@@ -84,7 +84,6 @@ export const Route = createRootRoute({
         content: "nb-NO",
       },
     ],
-    links: [{ rel: "stylesheet", href: styles }],
   }),
   component: function RootLayout() {

Still seeing this on 4.0.8 in my case.

Especially when i change app.css then refresh the page.

Also seeing this error with @tanstack/start 1.107.0 alongside tailwindcss 4.0.7 and @tailwindcss/vite 4.0.7.

To me the error appears every time you start the dev server and open the web for the first time: In production seems to happen every time i refresh the page

I think i found a workaround using postcss

  • Remove the vite plugin from app.config.ts

  • Install postcss and @tailwindcss/postcss

  • Add the following postcss.config.mjs to your root folder

    // postcss.config.mjs
    export default {
      plugins: {
        "@tailwindcss/postcss": {},
      },
    };
    
    

@junlarsen I am experiencing the same thing as you. Your solution removes the server file trying to reference a non existent css file, but were you able to get it to properly reference the correct outputted css file?

Using latest tailwind plugin by the way

Yeah everything works fine with what I showed in my original comment

going to close this now that the latest tailwindcss plugin seems to have resolved this issue. if anyone encounters any problem here, please open up a new issue including a complete example.

Hi, the issue still happens in the alpha version 1.121.0-alpha.27 or at least for me, the only way to fix it in my side was to downgrade the TailwindCSS Vite plugin to 4.0.7.

From 4.0.8 some logic in the plugin changed in the way the classes are searched (see tailwindlabs/tailwindcss#16958 (comment)).

ps: I tried all the solutions of switching to PostCSS, use source, etc…

Also seeing this on 1.121.27, downgrading to @tailwindcss/vite@4.0.7 fixed the hydration error which was being caused by a non existent css file being linked.

Hi, the issue still happens in the alpha version 1.121.0-alpha.27 or at least for me, the only way to fix it in my side was to downgrade the TailwindCSS Vite plugin to 4.0.7.

From 4.0.8 some logic in the plugin changed in the way the classes are searched (see https://github.com/tailwindlabs/tailwindcss/discussions/16958#discussion-8042351).

ps: I tried all the solutions of switching to PostCSS, use source, etc…