Skip to content

Start + Rsbuild: shared chunks cause CSS issues in the initial SSR response #8415

Description

@christiango

Which project does this relate to?

Start

Describe the bug

In a production TanStack Start build using Rsbuild, two routes sharing a component with a CSS Module import receive incorrect stylesheet dependencies in their initial SSR responses.

The reproduction has /alpha and /beta, each importing a shared Header and its own route CSS. A Rspack cache group extracts the shared component into a separate chunk.

On the tested baseline:

/alpha receives its required styles but also receives /beta’s CSS.
/beta is missing the shared header stylesheet. Its header renders as display: block instead of grid, approximately 79px tall instead of 64px.
/ correctly loads only root styles.
This reproduces with JavaScript disabled, before hydration or client navigation. With JavaScript enabled, the missing stylesheet loads later and causes a layout shift.

Complete minimal reproducer

https://github.com/christiango/tanstack-rsbuild-css-repro

Steps to Reproduce the Bug

  1. Clone and install:
git clone https://github.com/christiango/tanstack-rsbuild-css-repro.git
cd tanstack-rsbuild-css-repro
pnpm install
pnpm exec playwright install chromium
pnpm repro
  1. Observe two failing browser tests: unrelated CSS on Alpha and missing shared-header CSS on Beta. The home-route control passes.3.
  2. Run pnpm verify:repro. This confirms the expected failures, rebuilds with shared extraction disabled, and verifies that all three browser checks pass. Dynamic route imports remain split.
  3. For manual inspection, run pnpm start, disable browser JavaScript, and open http://127.0.0.1:4317/beta.

pnpm test also contains isolated regressions for dependency mapping and cyclic CSS collection. Those assert correct behavior and fail on the affected baseline.

Expected behavior

The initial SSR response should include every stylesheet required by the matched route and its static dependencies, without including styles needed only by unrelated routes.

Both Alpha and Beta should render the shared header as a 64px grid before hydration. Results should not depend on manifest traversal order.

Screenshots or Videos

No response

Platform

OS: macOS, Apple Silicon
Browser: Chromium supplied by Playwright 1.60.0
Node: 24.15.0; pnpm: 11.25.0
@tanstack/react-start: 1.168.25
@tanstack/react-router: 1.170.15
@tanstack/start-plugin-core: 1.171.17
Bundler: Rsbuild 2.1.11, resolving Rspack 2.1.10 locally
React / React DOM: 19.2.4

Additional context

[This section is AI generated, I didn't have enough context in the codebase to prove/disprove this claim as the root cause]

The captured graph suggests two contributing defects:

  1. computeAsyncChunkImports treats loading-group siblings as mutual imports. The shared header consequently appears to import its consuming routes, although its source does not.
    createChunkCssAssetCollector caches incomplete results after encountering dependency cycles, leaving later routes with missing CSS.
  2. The fixture uses minSize: 0 and enforce: true to trigger shared extraction without artificially enlarging the component. This points to TanStack’s interpretation of Rspack’s graph, not incorrect CSS emission by Rspack.

Related reports: #4224 covered missing recursive CSS discovery; #7057 covered overwritten route entries; #8224 concerns CSS removal after client navigation; #8202 concerns Windows paths. This reproduction instead fails during initial SSR on macOS and demonstrates false dependency edges plus incomplete cycle caching.

Activity

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