Skip to content

@import CSS seems to be duplicated during development SSR #7794

Closed

Description

@hydazz

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

Screen.Recording.2026-07-12.at.12.41.33.am.mov

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.

Activity

  1. lachieh commented on Sep 30, 2026

    @lachieh
    Contributor

    Another case with the same root cause, and in dev it breaks the whole page layout, not just the cascade order.

    We import a stylesheet from server code as ./embedded.css?inline to embed it as a string. It loads Tailwind in layers:

    @import 'tailwindcss/theme.css' layer(theme);
    @import 'tailwindcss/preflight.css' layer(base);
    @import 'tailwindcss/utilities.css' layer(utilities);

    collectDevStyles skips the ?inline module, but findModuleDeps still walks its imports. theme.css and preflight.css end up in /@tanstack-start/styles.css with no layer. Preflight's * { margin: 0; padding: 0; border: 0 solid } then beats every layered utility, so every Tailwind-styled component on the page loses its padding, margins and borders. A production build is fine.

    We see this on 1.171.18 with Vite 8.2.2 and Tailwind 4.3.3, and 1.171.49 still walks those imports. In #7830, resolveModuleDeps returns no dependencies for CSS nodes, and isCssFile matches .css?inline, so that PR should cover this too. I haven't run the branch yet, but I'm happy to test it against our app.

  2. lachieh commented on Sep 30, 2026

    @lachieh
    Contributor

    @schiller-manuel, would you add a test to #7830 for this case: a ?inline stylesheet whose @imports use layer(...)? Its imports shouldn't show up in the dev stylesheet.

  3. added 2 commits that reference this issue on Oct 9, 2026
    8a8e6fe
    6eee72e
  4. added a commit that references this issue on Oct 10, 2026
    4191640
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions