Skip to content

@tailwindcss/vite forces full page reload when editing a scanned .tsx that isn't a loaded module (Vite 8) #20320

Description

@neemski

What version of Tailwind CSS are you using?

v4.2.4 (tailwindcss and @tailwindcss/vite both 4.2.4)

What build tool (or framework if it abstracts the build tool) are you using?

Vite 8.0.11, via @tailwindcss/vite 4.2.4

What version of Node.js are you using?

v24.12.0

What browser are you using?

N/A — reproduced from the dev-server terminal (browser-agnostic). The reload is
also visible in any browser as the page's counter resetting to 0.

What operating system are you using?

macOS 26.5.1 (25F80)

Reproduction URL

https://github.com/neemski/tailwindcss-vite-full-reload-repro

npm install && npm run dev, click the button counter a few times, then (without clicking "go to route B") edit src/DeepComponent.tsx and watch the terminal (and the counter reset to 0). Full details, root-cause analysis, and a verified fix are in the repo's README.

Describe your issue

Editing a .tsx source file that Tailwind has scanned for class candidates
but that Vite has not yet loaded as a JS module
makes @tailwindcss/vite's
hotUpdate hook send { type: 'full-reload' } — a full page reload instead of
a Fast Refresh update. No CSS-like file is involved; the changed file is plain
.tsx.

The realistic way a file gets into that "scanned but not loaded" state is
code splitting. Vite lazy-transforms modules: a lazy(() => import('./RouteB'))
reference is resolved, but RouteB's contents (and anything it imports) aren't
transformed until that chunk is fetched — i.e. until you navigate there. So any
component reachable only through an un-fetched split boundary has no JS module
in the graph yet, only Tailwind's scan stub. Editing it while you're on a
different route reloads the whole app and loses all client state. With
route-level splitting (React.lazy, TanStack Router autoCodeSplitting, Next.js
dynamic imports
), every un-visited route's subtree is in this state, so it fires
on a large fraction of edits.

Root cause. hotUpdate has a fallback meant for scanned content that is not
a JS module (e.g. .html/.php templates), which fires a full-reload when:

modules.length > 0 &&
modules.every((mod) => mod.type === 'asset' || mod.id === undefined)

Tailwind's scanner registers every scanned source file via addWatchFile, which
creates an asset-type module-graph node with id === undefined. So the
discriminator is just whether the file is also present as a real, loaded JS
module:

State of the file Client module graph for the file Guard Result
loaded JS module (imported + transformed) [{js, defined}, {asset, UNDEFINED}] bails HMR update ✅
scanned only — not yet transformed (behind an un-fetched split) [{asset, UNDEFINED}] passes full-reload ❌

Because the {js, defined} node is missing for a file Vite hasn't transformed,
the .every(...) check is satisfied and Tailwind treats real .tsx source as an
external template, forcing a reload. The payload is sent directly through
environment.hot.send, bypassing Vite's logger, so nothing prints in the
terminal — the repro wraps hot.send to make it observable.

(A component directly lazy()-imported by a loaded module does not
reproduce — Vite pre-resolves that one hop, so it gets a {js, defined} node.
It's components one or more levels deeper inside the un-fetched subtree that hit
this.)

Not plugin-specific. Reproduces with @vitejs/plugin-react-swc,
@vitejs/plugin-react (Babel), or no React plugin at all. A React plugin is
included in the repro only so Fast Refresh is active — that is the baseline this
bug violates.

The fix direction from #19904 (exempting CSS-like files) would not cover this,
since the affected files are .tsx. Early-returning from hotUpdate for
JS/TS module files stops the spurious reload while newly introduced utility
classes still apply live through the normal css-update path (verified against
the repro):

hotUpdate({ file }) {
  if (/\.[cm]?[jt]sx?(?:\?.*)?$/.test(file)) return;
  // …existing fallback…
}

This suggests the fallback should exempt any file that resolves to a real JS
module, rather than only CSS-like files.

Activity

  1. self-assigned this
    on Jul 10, 2026
  2. RobinMalfait commented on Jul 13, 2026

    @RobinMalfait
    Contributor

    Hey! We definitely want to fix this, but I'm trying to understand the issue first a bit more. When you say:

    This happens constantly in apps that use route- or component-level code splitting: at any moment many .tsx files are scanned by Tailwind but are not in the currently-loaded chunk (lazy imports, unvisited routes), so editing them reloads the whole page and loses all client state.

    The moment the file is used, then hmr should kick in properly. What's a scenario where you edit a file that is currently not used on the page?

  3. neemski commented on Jul 13, 2026

    @neemski
    Author

    Hey @RobinMalfait - I updated the issue description and my example repo (https://github.com/neemski/tailwindcss-vite-full-reload-repro) please take a look and let me know if that makes things clearer!

    Here's a contrived version of the scenario we're running into, scoped to my sample repo:

    • App lazy-loads RouteB behind a button; RouteB renders DeepComponent.
    • Edit src/DeepComponent.tsx before clicking "go to route B" → full page reload. Graph: [{type:'asset', id:undefined}].
    • Click "go to route B" (fetches the chunk), then edit again → normal HMR update. Graph now: [{type:'asset', id:undefined}, {type:'js', id:defined}].

    In practice my team hit this constantly because our app uses TanStack Router with autoCodeSplitting: true, which splits every route, so at any moment most of the app's components sit behind un-fetched boundaries, and editing any of them reloads the page.

  4. RobinMalfait commented on Jul 15, 2026

    @RobinMalfait
    Contributor

    @neemski got it, yeah that makes sense. This should be fixed by #20336, and will be available in the next release.

    You can already try it by using the insiders build:
    CLI:

    npm install tailwindcss@insiders @tailwindcss/cli@insiders

    PostCSS:

    npm install tailwindcss@insiders @tailwindcss/postcss@insiders

    Vite:

    npm install tailwindcss@insiders @tailwindcss/vite@insiders

    webpack:

    npm install tailwindcss@insiders @tailwindcss/webpack@insiders
  5. neemski commented on Jul 15, 2026

    @neemski
    Author

    @RobinMalfait amazing, thanks so much!

  6. added a commit that references this issue on Jul 15, 2026
    bdcd708
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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