TanStack / TanStack/router

@import CSS seems to be duplicated during development SSR

Open
#7,794 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
15.1k
Forks
1.9k
Avg merge
1d 20h
Merged PRs (30d)
143

Description

Which project does this relate to?

Start

Describe the bug

If a stylesheet imported by the root route contains a CSS @import, the imported stylesheet appears twice in TanStack Start’s generated development stylesheet.

The first copy is inlined where the @import occurs. A second copy is appended after the parent stylesheet. This changes the cascade order, so declarations from the imported stylesheet can override declarations written after the @import.

In the reproduction, base.css sets background: white. styles.css imports base.css, then sets background: dark. During a full development refresh, the page briefly renders white, then returns to dark after hydration.

This only seems to happen during development. The production build emits the styles in the expected order.

I’m not sure whether this is an intended limitation of development CSS collection or an issue with how imported stylesheets are collected. The root-route side-effect import and CSS @import both appear to follow the documented usage.

Complete minimal reproducer

https://stackblitz.com/edit/github-qmf2qf6v

Steps to Reproduce the Bug
  1. Open the stackblitz above
  2. Wait for WebContainer/npm install && npm run dev
  3. Keep refreshing the Preview
Expected behavior

I expected the dark background from styles.css to be used for the initial styled render too.

base.css is imported first, then the dark body rule follows it in styles.css, so I did not expect the base background: white declaration to win during the development SSR render.

Screenshots or Videos

https://github.com/user-attachments/assets/348d3b2e-7ac3-4cb9-b86c-f5e905adde34

Platform
  • Router / Start Version: 1.168.27
  • OS: macOS
  • Browser: Chrome
  • Browser Version: 150.0.7871.115
  • Bundler: vite
  • Bundler Version: 8.1.4
Additional context

Docs followed:
https://tanstack.com/start/latest/docs/framework/react/guide/css-styling
https://vite.dev/guide/features.html#import-inlining-and-rebasing

?url method does not have this issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin with the linked StackBlitz reproducer and inspect the root-route import of styles.css, its @import of base.css, and the generated development stylesheet during SSR. Compare the development output with the production build and verify completion when base.css appears only once, in import order, so the dark rule in styles.css controls the initial render.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, react, vite
Domain
build-system, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.