Skip to content
Source
Sign inSign up
TanStack/router

fix(rsc): remove outdated stale hmr css references #7219

Closedjantimon(GitHub profile, opens in a new tab)wants to merge 14 commits intomain fromrefs/pull/7219/headopened

follow-up to https://github.com/vitejs/vite-plugin-react/pull/1188 on the TanStack Router side where @schiller-manuel was already mentioned

While debugging CSS HMR in TanStack Start RSC (https://tanstack.com/blog/react-server-components) I noticed a second, independent problem: <link rel="stylesheet"> tags pile up in <head> across HMR edits.. Every save appends another <link> and none of them get cleaned up

CompositeComponent and RscNodeRenderer both walk the cssHrefs set reported by the RSC Flight stream and call:

ReactDOM.preinit(href, { as: 'style', precedence: 'high' })

Obviously this is a dev only problem. Vite appends an HMR cache-bust (?t=<lastHMRTimestamp>) to every CSS href on every edit (see vite-plugin-react #1188. Each edit therefore calls preinit with a different href which adds a new <link> to <head> instead of replacing the previous one

A simple possible fix would be to skip these HMR css requests by excluding css files with /[?&]t=\d+/ as Vite only emits that query in dev so:

  • Prod path is unchanged
  • Dev path cache-busted hrefs are ignored

One open question: can we somehow add HMR e2e tests to verify:

  1. changing a css prop updates with hmr
  2. removing a css prop reverts the css value to the default

Summary by CodeRabbit

  • Refactor

    • Streamlined stylesheet pre-initialization: production preinit retained; dev skips preinit to avoid stale CSS during HMR.
  • New Features

    • Added example app with routes, navigation, server-rendered demo cards (global CSS and CSS Modules), dev tooling, and Vite/RSC config.
    • Added ESLint config and .gitignore for the example.
  • Tests

    • Added Playwright e2e tests for CSS HMR, hydration helper, and test setup/teardown.
  • Chores

    • Bumped dev tool version and added a changeset entry.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-start-rsc

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Note

      Reviews paused

      It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

      Use the following commands to manage reviews:

      • @coderabbitai resume to resume automatic reviews.
      • @coderabbitai review to trigger a single review.

      Use the checkboxes below for quick actions:

      • ▶️ Resume reviews
      • 🔍 Trigger review
      📝 Walkthrough

      Walkthrough

      Extracted CSS preinit logic into a new helper and added a complete end-to-end RSC CSS HMR test workspace (router, routes, test components, server fns, Playwright config, Vite/TS configs, and tests).

      Changes

      Cohort / File(s)Summary
      CSS Preinit Helper
      packages/react-start-rsc/src/preinitCssHrefs.ts, packages/react-start-rsc/src/CompositeComponent.tsx, packages/react-start-rsc/src/RscNodeRenderer.tsx
      Added exported preinitCssHrefs(cssHrefs) and replaced inline CSS preinit loops in CompositeComponent and RscNodeRenderer to delegate to this helper; preinit now no-ops outside production.
      E2E Package Config
      e2e/react-start/rsc-hmr/package.json, e2e/react-start/rsc-hmr/vite.config.ts, e2e/react-start/rsc-hmr/tsconfig.json, e2e/react-start/rsc-hmr/eslint.config.js, e2e/react-start/rsc-hmr/.gitignore
      New e2e workspace files: package manifest, Vite + RSC plugins enabled, TS config, ESLint config, and .gitignore for the HMR test package.
      Playwright Config & Test Lifecycle
      e2e/react-start/rsc-hmr/playwright.config.ts, e2e/react-start/rsc-hmr/tests/setup/global.setup.ts, e2e/react-start/rsc-hmr/tests/setup/global.teardown.ts
      Added Playwright defineConfig with dynamic port/baseURL and webServer setup plus global test setup/teardown modules to start/stop the dummy server and pre-optimize dev server.
      Router & Routes
      e2e/react-start/rsc-hmr/src/routeTree.gen.ts, e2e/react-start/rsc-hmr/src/router.tsx, e2e/react-start/rsc-hmr/src/routes/__root.tsx, e2e/react-start/rsc-hmr/src/routes/index.tsx, e2e/react-start/rsc-hmr/src/routes/rsc-hmr-css-modules.tsx, e2e/react-start/rsc-hmr/src/routes/rsc-hmr-global-css.tsx
      Added generated route tree, router factory, root HTML route, index route, and two test routes that load server-rendered components for CSS HMR scenarios.
      Test Components & Server Functions
      e2e/react-start/rsc-hmr/src/utils/CssModulesCard.tsx, e2e/react-start/rsc-hmr/src/utils/CssModulesCard.module.css, e2e/react-start/rsc-hmr/src/utils/GlobalCssCard.tsx, e2e/react-start/rsc-hmr/src/utils/GlobalCssCard.css, e2e/react-start/rsc-hmr/src/utils/cssModulesCardServerComponent.tsx, e2e/react-start/rsc-hmr/src/utils/globalCssCardServerComponent.tsx
      Added UI components (CSS Modules + global CSS), corresponding styles, and server functions that render those components for the routes.
      Playwright Tests & Helpers
      e2e/react-start/rsc-hmr/tests/rsc-hmr-css.spec.ts, e2e/react-start/rsc-hmr/tests/hydration.ts
      Added end-to-end test spec that snapshots and edits on-disk CSS files to validate HMR updates and a helper to wait for client hydration.
      Changeset & Root Update
      .changeset/fix-rsc-stale-css-hmr.md, package.json
      Added a changeset noting preinit skip in non-production; bumped root devDependency vite to ^8.0.10.

      Sequence Diagram(s)

      sequenceDiagram
        participant Tester as Test Runner
        participant DevServer as Dev Server (Vite)
        participant FS as File System
        participant Browser as Browser
        participant RSC as RSC Renderer
        Tester->>DevServer: start (pnpm dev:e2e)
        DevServer->>Browser: serve page (baseURL)
        Browser->>RSC: request SSR (initial render)
        RSC-->>Browser: HTML + preinit hints (preinitCssHrefs)
        Tester->>FS: edit CSS file
        FS-->>DevServer: file change event
        DevServer->>Browser: HMR update / module reload
        Browser->>RSC: apply new styles / re-render (hydration)
        Browser-->>Tester: updated computed styles observed

      Estimated code review effort

      🎯 3 (Moderate) | ⏱️ ~25 minutes

      Poem

      🐰 I hopped through helpers, routes, and test delight, Preinit waits in production's light, CSS files change and HMR takes flight, Tests nibble, watch styles swap by sight, A rabbit cheers: styles fixed just right! 🥕✨

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 11.11% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe PR title 'fix(rsc): remove outdated stale hmr css references' directly and accurately summarizes the main change—refactoring CSS preinitialization to skip cache-busted HMR hrefs and prevent stale CSS accumulation in development.
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      ✏️ Tip: You can configure your own custom pre-merge checks in the settings.
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      Bundle Size Benchmarks

      • Commit: ee96e25d1487
      • Measured at: 2026-05-06T16:43:11.457Z
      • Baseline source: history:35e88f04996d
      • Dashboard: bundle-size history
      ScenarioCurrent (gzip)Delta vs baselineRawBrotliTrend
      react-router.minimal87.16 KiB+7 B (+0.01%)273.95 KiB75.71 KiB▁▁▁▁▁▁▁▁▁▁▁█
      react-router.full90.69 KiB+6 B (+0.01%)285.45 KiB78.79 KiB▁▁▁▁▁▁▁▁▁▁▁█
      solid-router.minimal35.38 KiB0 B (0.00%)106.25 KiB31.81 KiB▅▅▅▅▅▅▅▅▅▅▅
      solid-router.full40.10 KiB-2 B (-0.00%)120.46 KiB36.02 KiB███████████▁
      vue-router.minimal52.86 KiB-300 B (-0.55%)150.28 KiB47.50 KiB███████████▁
      vue-router.full58.15 KiB-128 B (-0.21%)167.01 KiB52.14 KiB███████████▁
      react-start.minimal101.84 KiB+4 B (+0.00%)322.38 KiB88.14 KiB▁▁▁▁▁▁▁▁▁▁██
      react-start.full105.27 KiB-2 B (-0.00%)332.71 KiB90.99 KiB▁▁▁▁▁▁▁▁▁▁██
      react-start.rsbuild.minimal99.43 KiB0 B (0.00%)316.76 KiB85.51 KiB▁▁▁▁▁▁▁▁▁▁█
      react-start.rsbuild.full102.72 KiB0 B (0.00%)327.19 KiB88.31 KiB▁▁▁▁▁▁▁▁▁▁█
      solid-start.minimal49.48 KiB-2 B (-0.00%)152.35 KiB43.64 KiB▁▁▁▁▁▁▁▁▁▁██
      solid-start.full55.27 KiB+2 B (+0.00%)169.25 KiB48.64 KiB▁▁▁▁▁▁▁▁▁▁██

      Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better.

    4. 🧹 Nitpick comments (1)
      packages/react-start-rsc/tests/preinitCssHrefs.test.ts (1)

      31-93: Good coverage — consider one additional assertion for HMR skip ordering.

      The suite covers the important cases (positive match, negative match, mixed, undefined/empty, ReadonlySet). The toHaveBeenNthCalledWith assertions on lines 67-74 already implicitly verify that cache-busted entries don't shift the call order, so this is solid.

      Optional nit: the beforeEach/afterEach mockRestore pattern works, but vi.restoreAllMocks() in a top-level afterEach (or configuring restoreMocks: true in vitest config) would let you drop the preinitSpy variable declaration and the explicit restore. Not a blocker.

      🤖 Prompt for AI Agents
      Verify each finding against the current code and only fix it if needed.
      
      In `@packages/react-start-rsc/tests/preinitCssHrefs.test.ts` around lines 31 - 93,
      Add an explicit assertion that cache-busted HMR-style hrefs are skipped without
      affecting the relative ordering of non-cache-busted hrefs: update the mixed-list
      test that calls preinitCssHrefs(...) to include an assertion on the exact call
      order of ReactDOM.preinit (preinitSpy) for the non-cache-busted entries so order
      is validated (or add a new test that supplies interleaved cache-busted and
      non-cache-busted hrefs and asserts preinitSpy was called in the original
      relative order). Optionally simplify mock cleanup by replacing the
      beforeEach/afterEach preinitSpy + preinitSpy.mockRestore() pattern with a single
      afterEach(() => vi.restoreAllMocks()) and remove the preinitSpy variable if you
      prefer.
      🤖 Prompt for all review comments with AI agents
      Verify each finding against the current code and only fix it if needed.
      
      Nitpick comments:
      In `@packages/react-start-rsc/tests/preinitCssHrefs.test.ts`:
      - Around line 31-93: Add an explicit assertion that cache-busted HMR-style hrefs
      are skipped without affecting the relative ordering of non-cache-busted hrefs:
      update the mixed-list test that calls preinitCssHrefs(...) to include an
      assertion on the exact call order of ReactDOM.preinit (preinitSpy) for the
      non-cache-busted entries so order is validated (or add a new test that supplies
      interleaved cache-busted and non-cache-busted hrefs and asserts preinitSpy was
      called in the original relative order). Optionally simplify mock cleanup by
      replacing the beforeEach/afterEach preinitSpy + preinitSpy.mockRestore() pattern
      with a single afterEach(() => vi.restoreAllMocks()) and remove the preinitSpy
      variable if you prefer.

      ℹ️ Review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: 9fe7e78c-fd22-4676-962f-e436b8c8a27e

      📥 Commits

      Reviewing files that changed from the base of the PR and between c19571fd5de0e4544206d92c1d84e4e8c455f1fb and 066c6580fcd813c8aca2af9680bc1dc9322237d1.

      📒 Files selected for processing (4)
      • packages/react-start-rsc/src/CompositeComponent.tsx
      • packages/react-start-rsc/src/RscNodeRenderer.tsx
      • packages/react-start-rsc/src/preinitCssHrefs.ts
      • packages/react-start-rsc/tests/preinitCssHrefs.test.ts
    5. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit 1fec5dd5cf5fa41b3ef2f314a8caf53798b31756


      ☁️ Nx Cloud last updated this comment at 2026-05-31 21:54:02 UTC

    6. More templates

      @tanstack/arktype-adapter

      npm i https://pkg.pr.new/@tanstack/arktype-adapter@7219

      @tanstack/eslint-plugin-router

      npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7219

      @tanstack/eslint-plugin-start

      npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7219

      @tanstack/history

      npm i https://pkg.pr.new/@tanstack/history@7219

      @tanstack/nitro-v2-vite-plugin

      npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7219

      @tanstack/react-router

      npm i https://pkg.pr.new/@tanstack/react-router@7219

      @tanstack/react-router-devtools

      npm i https://pkg.pr.new/@tanstack/react-router-devtools@7219

      @tanstack/react-router-ssr-query

      npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7219

      @tanstack/react-start

      npm i https://pkg.pr.new/@tanstack/react-start@7219

      @tanstack/react-start-client

      npm i https://pkg.pr.new/@tanstack/react-start-client@7219

      @tanstack/react-start-rsc

      npm i https://pkg.pr.new/@tanstack/react-start-rsc@7219

      @tanstack/react-start-server

      npm i https://pkg.pr.new/@tanstack/react-start-server@7219

      @tanstack/router-cli

      npm i https://pkg.pr.new/@tanstack/router-cli@7219

      @tanstack/router-core

      npm i https://pkg.pr.new/@tanstack/router-core@7219

      @tanstack/router-devtools

      npm i https://pkg.pr.new/@tanstack/router-devtools@7219

      @tanstack/router-devtools-core

      npm i https://pkg.pr.new/@tanstack/router-devtools-core@7219

      @tanstack/router-generator

      npm i https://pkg.pr.new/@tanstack/router-generator@7219

      @tanstack/router-plugin

      npm i https://pkg.pr.new/@tanstack/router-plugin@7219

      @tanstack/router-ssr-query-core

      npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7219

      @tanstack/router-utils

      npm i https://pkg.pr.new/@tanstack/router-utils@7219

      @tanstack/router-vite-plugin

      npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7219

      @tanstack/solid-router

      npm i https://pkg.pr.new/@tanstack/solid-router@7219

      @tanstack/solid-router-devtools

      npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7219

      @tanstack/solid-router-ssr-query

      npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7219

      @tanstack/solid-start

      npm i https://pkg.pr.new/@tanstack/solid-start@7219

      @tanstack/solid-start-client

      npm i https://pkg.pr.new/@tanstack/solid-start-client@7219

      @tanstack/solid-start-server

      npm i https://pkg.pr.new/@tanstack/solid-start-server@7219

      @tanstack/start-client-core

      npm i https://pkg.pr.new/@tanstack/start-client-core@7219

      @tanstack/start-fn-stubs

      npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7219

      @tanstack/start-plugin-core

      npm i https://pkg.pr.new/@tanstack/start-plugin-core@7219

      @tanstack/start-server-core

      npm i https://pkg.pr.new/@tanstack/start-server-core@7219

      @tanstack/start-static-server-functions

      npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7219

      @tanstack/start-storage-context

      npm i https://pkg.pr.new/@tanstack/start-storage-context@7219

      @tanstack/valibot-adapter

      npm i https://pkg.pr.new/@tanstack/valibot-adapter@7219

      @tanstack/virtual-file-routes

      npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7219

      @tanstack/vue-router

      npm i https://pkg.pr.new/@tanstack/vue-router@7219

      @tanstack/vue-router-devtools

      npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7219

      @tanstack/vue-router-ssr-query

      npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7219

      @tanstack/vue-start

      npm i https://pkg.pr.new/@tanstack/vue-start@7219

      @tanstack/vue-start-client

      npm i https://pkg.pr.new/@tanstack/vue-start-client@7219

      @tanstack/vue-start-server

      npm i https://pkg.pr.new/@tanstack/vue-start-server@7219

      @tanstack/zod-adapter

      npm i https://pkg.pr.new/@tanstack/zod-adapter@7219

      commit: 066c658

    7. Merging this PR will not alter performance

      ✅ 6 untouched benchmarks


      Comparing jantimon:fix-rsc (066c658) with main (b57e898)[^unexpected-base] Open in CodSpeed
    8. does this still update css then in dev upon hmr? if yes, how?

    9. w.r.t. to e2e tests: we already have hmr e2e tests in e2e/react-start/e2e a similar setup should work here as well

    10. Actionable comments posted: 3

      🧹 Nitpick comments (1)
      e2e/react-start/rsc-hmr/tests/rsc-hmr-css.spec.ts (1)

      90-110: Add an assertion for the stale stylesheet-link regression.

      This second-edit test proves CSS still updates, but not that old cache-busted <link rel="stylesheet"> entries stop accumulating. Please assert the relevant stylesheet link count/hrefs in <head> remain bounded after repeated edits so the test fails on the original leak.

      🤖 Prompt for AI Agents
      Verify each finding against the current code and only fix it if needed.
      
      In `@e2e/react-start/rsc-hmr/tests/rsc-hmr-css.spec.ts` around lines 90 - 110,
      After the two editCss steps in the test `${c.label}: a second css change in the
      same file hot-updates the style`, add assertions that the document head does not
      accumulate stale cache-busted stylesheet links: query the head for <link
      rel="stylesheet"> elements (via page.evaluate or page.locator) and assert the
      count remains bounded (e.g., equals the expected number) and that their hrefs
      are the current/expected href(s) rather than many old cache-busted variants;
      place these checks after the final
      expect(page.getByTestId(c.titleTestId)).toHaveCSS(...) so the test fails if
      stale `<link rel="stylesheet">` entries leak after calling editCss twice. Ensure
      you reference the same c/titleTestId context as used in this test and use page.*
      helpers (page.evaluate or page.locator) to inspect head links.
      🤖 Prompt for all review comments with AI agents
      Verify each finding against the current code and only fix it if needed.
      
      Inline comments:
      In `@e2e/react-start/rsc-hmr/package.json`:
      - Line 4: The package.json currently declares "sideEffects": false which causes
      Vite/webpack to tree-shake CSS imports used by GlobalCssCard.tsx and
      CssModulesCard.tsx; update package.json to preserve CSS side-effects by
      replacing the boolean with an array of patterns (e.g., ["*.css", "**/*.css"] or
      the specific CSS module paths) or set "sideEffects": true so CSS imports are not
      removed during build, ensuring GlobalCssCard.tsx and CssModulesCard.tsx CSS
      remains included.
      
      In `@e2e/react-start/rsc-hmr/tests/hydration.ts`:
      - Line 1: The import currently mixes a value import and an inline type specifier
      ("expect, type Page from '@playwright/test'"), which ESLint flags; change it to
      two imports: keep the value import for "expect" from '@playwright/test' and add
      a separate type-only import for "Page" (e.g., "import type { Page } from
      '@playwright/test'") so the "expect" and "Page" symbols are imported separately
      and satisfy member ordering and type-import rules.
      
      In `@e2e/react-start/rsc-hmr/tests/rsc-hmr-css.spec.ts`:
      - Around line 1-5: Reorder the import statements so Node built-ins come before
      package imports: move "import { readFile, writeFile } from 'node:fs/promises'"
      and "import path from 'node:path'" above the third‑party imports (e.g., "import
      { expect } from '@playwright/test'" and "import { test } from
      '@tanstack/router-e2e-utils'"), keeping the local relative import "import {
      waitForHydration } from './hydration'" last; preserve the same named symbols
      (expect, test, readFile, writeFile, path, waitForHydration) and their usage.
      
      ---
      
      Nitpick comments:
      In `@e2e/react-start/rsc-hmr/tests/rsc-hmr-css.spec.ts`:
      - Around line 90-110: After the two editCss steps in the test `${c.label}: a
      second css change in the same file hot-updates the style`, add assertions that
      the document head does not accumulate stale cache-busted stylesheet links: query
      the head for <link rel="stylesheet"> elements (via page.evaluate or
      page.locator) and assert the count remains bounded (e.g., equals the expected
      number) and that their hrefs are the current/expected href(s) rather than many
      old cache-busted variants; place these checks after the final
      expect(page.getByTestId(c.titleTestId)).toHaveCSS(...) so the test fails if
      stale `<link rel="stylesheet">` entries leak after calling editCss twice. Ensure
      you reference the same c/titleTestId context as used in this test and use page.*
      helpers (page.evaluate or page.locator) to inspect head links.
      🪄 Autofix (Beta)

      Fix all unresolved CodeRabbit comments on this PR:

      • Push a commit to this branch (recommended)
      • Create a new PR with the fixes

      ℹ️ Review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: 799e91c2-3377-4117-b130-eb55afc63c02

      📥 Commits

      Reviewing files that changed from the base of the PR and between 066c6580fcd813c8aca2af9680bc1dc9322237d1 and 94b1643e6d79981042d8d85e8bc0503d2b5e107a.

      📒 Files selected for processing (23)
      • e2e/react-start/rsc-hmr/.gitignore
      • e2e/react-start/rsc-hmr/eslint.config.js
      • e2e/react-start/rsc-hmr/package.json
      • e2e/react-start/rsc-hmr/playwright.config.ts
      • e2e/react-start/rsc-hmr/src/routeTree.gen.ts
      • e2e/react-start/rsc-hmr/src/router.tsx
      • e2e/react-start/rsc-hmr/src/routes/__root.tsx
      • e2e/react-start/rsc-hmr/src/routes/index.tsx
      • e2e/react-start/rsc-hmr/src/routes/rsc-hmr-css-modules.tsx
      • e2e/react-start/rsc-hmr/src/routes/rsc-hmr-global-css.tsx
      • e2e/react-start/rsc-hmr/src/utils/CssModulesCard.module.css
      • e2e/react-start/rsc-hmr/src/utils/CssModulesCard.tsx
      • e2e/react-start/rsc-hmr/src/utils/GlobalCssCard.css
      • e2e/react-start/rsc-hmr/src/utils/GlobalCssCard.tsx
      • e2e/react-start/rsc-hmr/src/utils/cssModulesCardServerComponent.tsx
      • e2e/react-start/rsc-hmr/src/utils/globalCssCardServerComponent.tsx
      • e2e/react-start/rsc-hmr/tests/hydration.ts
      • e2e/react-start/rsc-hmr/tests/rsc-hmr-css.spec.ts
      • e2e/react-start/rsc-hmr/tests/setup/global.setup.ts
      • e2e/react-start/rsc-hmr/tests/setup/global.teardown.ts
      • e2e/react-start/rsc-hmr/tsconfig.json
      • e2e/react-start/rsc-hmr/vite.config.ts
      • packages/react-start-rsc/src/preinitCssHrefs.ts
      ✅ Files skipped from review due to trivial changes (7)
      • e2e/react-start/rsc-hmr/.gitignore
      • e2e/react-start/rsc-hmr/src/utils/GlobalCssCard.css
      • e2e/react-start/rsc-hmr/src/utils/CssModulesCard.module.css
      • e2e/react-start/rsc-hmr/tsconfig.json
      • e2e/react-start/rsc-hmr/src/utils/GlobalCssCard.tsx
      • e2e/react-start/rsc-hmr/eslint.config.js
      • e2e/react-start/rsc-hmr/src/routeTree.gen.ts
      🚧 Files skipped from review as they are similar to previous changes (1)
      • packages/react-start-rsc/src/preinitCssHrefs.ts
    11. does this still update css then in dev upon hmr? if yes, how?

      @vitejs/plugin-rsc <Resources> emits a <link rel="stylesheet" data-rsc-css-href="..."> directly in the Flight stream for every CSS dependency

      preinit was adding a second <link> for preloading

    12. The HMR e2e tests in this branch are blocked by https://github.com/vitejs/vite-plugin-react/pull/1188

      @hi-ogawa could you please take a look at both PRs and let me know what you think about the fix and the e2e tests?

    13. @hi-ogawa did a great job this weekend and finished, merged and relased my vite-plugin-react pr: vite-plugin-react changelog 🎉

      vite-plugin-react v0.5.25

      rsc: fix server css hmr with cssLinkPrecedence: false (#1188) (f4647c4)

      I will retest tanstack start again with this version and try to simplify the e2e tests today

    14. Actionable comments posted: 1

      🤖 Prompt for all review comments with AI agents
      Verify each finding against the current code and only fix it if needed.
      
      Inline comments:
      In `@e2e/react-start/rsc-hmr/tests/rsc-hmr-css.spec.ts`:
      - Around line 71-132: Add an assertion in each affected test after the CSS edit
      and final expect to verify the set/count of HMR stylesheet links to catch the
      stale-link regression: query the DOM for
      link[rel="stylesheet"][data-rsc-css-href] (e.g., via page.locator or
      page.evaluate) and assert that there is exactly one entry (or that the href set
      contains only the latest href) so that tests like the ones using editCss,
      waitForHydration, and c.titleTestId fail if old <link> nodes accumulate; place
      this check right after the final await expect(...) in each test.
      🪄 Autofix (Beta)

      Fix all unresolved CodeRabbit comments on this PR:

      • Push a commit to this branch (recommended)
      • Create a new PR with the fixes

      ℹ️ Review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: f49d6cfa-c721-44d3-89e3-24fe216ab5d7

      📥 Commits

      Reviewing files that changed from the base of the PR and between 3fa7ef96ff508a6eda0c48771be4f8bc303c49bf and 1d97f8323f4f686b357530ea0fe7dc37dc1bee83.

      📒 Files selected for processing (27)
      • .changeset/fix-rsc-stale-css-hmr.md
      • e2e/react-start/rsc-hmr/.gitignore
      • e2e/react-start/rsc-hmr/eslint.config.js
      • e2e/react-start/rsc-hmr/package.json
      • e2e/react-start/rsc-hmr/playwright.config.ts
      • e2e/react-start/rsc-hmr/src/routeTree.gen.ts
      • e2e/react-start/rsc-hmr/src/router.tsx
      • e2e/react-start/rsc-hmr/src/routes/__root.tsx
      • e2e/react-start/rsc-hmr/src/routes/index.tsx
      • e2e/react-start/rsc-hmr/src/routes/rsc-hmr-css-modules.tsx
      • e2e/react-start/rsc-hmr/src/routes/rsc-hmr-global-css.tsx
      • e2e/react-start/rsc-hmr/src/utils/CssModulesCard.module.css
      • e2e/react-start/rsc-hmr/src/utils/CssModulesCard.tsx
      • e2e/react-start/rsc-hmr/src/utils/GlobalCssCard.css
      • e2e/react-start/rsc-hmr/src/utils/GlobalCssCard.tsx
      • e2e/react-start/rsc-hmr/src/utils/cssModulesCardServerComponent.tsx
      • e2e/react-start/rsc-hmr/src/utils/globalCssCardServerComponent.tsx
      • e2e/react-start/rsc-hmr/tests/hydration.ts
      • e2e/react-start/rsc-hmr/tests/rsc-hmr-css.spec.ts
      • e2e/react-start/rsc-hmr/tests/setup/global.setup.ts
      • e2e/react-start/rsc-hmr/tests/setup/global.teardown.ts
      • e2e/react-start/rsc-hmr/tsconfig.json
      • e2e/react-start/rsc-hmr/vite.config.ts
      • package.json
      • packages/react-start-rsc/src/CompositeComponent.tsx
      • packages/react-start-rsc/src/RscNodeRenderer.tsx
      • packages/react-start-rsc/src/preinitCssHrefs.ts
      ✅ Files skipped from review due to trivial changes (15)
      • e2e/react-start/rsc-hmr/.gitignore
      • package.json
      • .changeset/fix-rsc-stale-css-hmr.md
      • e2e/react-start/rsc-hmr/src/utils/cssModulesCardServerComponent.tsx
      • e2e/react-start/rsc-hmr/src/utils/GlobalCssCard.css
      • e2e/react-start/rsc-hmr/src/utils/GlobalCssCard.tsx
      • e2e/react-start/rsc-hmr/src/utils/CssModulesCard.module.css
      • e2e/react-start/rsc-hmr/src/utils/CssModulesCard.tsx
      • e2e/react-start/rsc-hmr/tests/hydration.ts
      • e2e/react-start/rsc-hmr/src/router.tsx
      • e2e/react-start/rsc-hmr/src/routes/rsc-hmr-css-modules.tsx
      • e2e/react-start/rsc-hmr/tsconfig.json
      • e2e/react-start/rsc-hmr/eslint.config.js
      • e2e/react-start/rsc-hmr/package.json
      • e2e/react-start/rsc-hmr/src/routeTree.gen.ts
      🚧 Files skipped from review as they are similar to previous changes (10)
      • packages/react-start-rsc/src/CompositeComponent.tsx
      • e2e/react-start/rsc-hmr/tests/setup/global.teardown.ts
      • e2e/react-start/rsc-hmr/src/utils/globalCssCardServerComponent.tsx
      • e2e/react-start/rsc-hmr/src/routes/index.tsx
      • e2e/react-start/rsc-hmr/vite.config.ts
      • e2e/react-start/rsc-hmr/tests/setup/global.setup.ts
      • e2e/react-start/rsc-hmr/playwright.config.ts
      • packages/react-start-rsc/src/RscNodeRenderer.tsx
      • e2e/react-start/rsc-hmr/src/routes/rsc-hmr-global-css.tsx
      • e2e/react-start/rsc-hmr/src/routes/__root.tsx
    15. Okay so I verified that @vitejs/plugin-rsc 0.5.25 + vite 8.0.10 + this PR fixes the HMR and all new e2e tests pass

      I also verified this PR is still needed

      Removing if (process.env.NODE_ENV !== 'production') return in https://github.com/jantimon/tanstack-router/blob/1d97f8323f4f686b357530ea0fe7dc37dc1bee83/packages/react-start-rsc/src/preinitCssHrefs.ts#L11 will break the e2e test which verifies that no stale styles survive a delete:

       tests/rsc-hmr-css.spec.ts:113:5 › rsc css hmr › global .css: removing a css property hot-updates the style
       Expected: "none"
       Received: "uppercase"
    16. w.r.t. to e2e tests: we already have hmr e2e tests in e2e/react-start/e2e a similar setup should work here as well

      I looked into consolidating these tests but there are some blockers because of rspack rsc compatibility:

      1. The following import fails because there is no @rspack/core/rsc/ssr: https://github.com/TanStack/router/blob/b0024d6310f123736ea18a7f8692b45265cdee74/packages/react-start-rsc/src/rsbuild/ssr-decode.ts#L8
      2. If we exclude the rsc routes for rspack routeTree.gen.ts flip-flops between toolchains
      3. Types don't match for rspack and rsc so I ran into: src/routes/rsc-hmr-css-modules.tsx(4,38): error TS2345: Argument of type '"/rsc-hmr-css-modules"' is not assignable to parameter of type 'keyof FileRoutesByPath | undefined' src/routes/rsc-hmr-css-modules.tsx(13,11): error TS2339: Property 'Server' does not exist on type '{ crumb: string; } | undefined'

      If you like I can disable the typecheck for rspack inside e2e/react-start/rsc-hmr, exclude the HMR routes and add a git ignore entry for routeTree.gen.ts

      What do you think?

    17. these tests should not run for rspack (yet), please only let them run for vite

    18. @schiller-manuel

      agree but currently all RSC tests run for rspack and also the typecheck works

      if I now add the HMR tests to the existing RSC tests and exclude rspack for theses tests I get the issues mentioned above

      If you like I can disable the typecheck for rspack inside e2e/react-start/rsc-hmr, exclude the HMR routes and add a git ignore entry for routeTree.gen.ts

      is this okay?

    19. socket-security[bot](GitHub profile, opens in a new tab)commented

      Review the following changes in direct dependencies. Learn more about Socket for GitHub.

      Diff Package Supply Chain
      Security
      Vulnerability Quality Maintenance License
      Added@​vitejs/​plugin-rsc@​0.5.269910010095100

      View full report

    20. rsc in rsbuild is done now, so this should changed now to only apply for vite

    21. @schiller-manuel I got rspack working with source: {include: [/[\\/]node_modules[\\/]@tanstack[\\/]/]} (btw is that the correct way?) and you are right!

      rspack works with HMR out of the box without any fix needed

      do you think we could fix the css invalidation totally on the vite site without any changes to tanstack start? should I add the tests anyway?

    22. Superseded by #8277, which builds on this contribution and consolidates the related HMR and missing-chunk recovery fixes. Contributor credit is preserved in the replacement.

Sign in to join this conversation.