Skip to content

@tailwindcss/turbopack serves stale CSS in next dev after editing the CSS file #20581

Closed

Description

@natefzz

What version of Tailwind CSS are you using?

v4.3.3

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

Next.js 16.4.0 with Turbopack (next dev). The project was created with [email protected] (Tailwind enabled, default bundler), which sets up the @tailwindcss/turbopack loader in next.config.ts.

What version of Node.js are you using?

v25.2.1

What browser are you using?

Chrome

What operating system are you using?

macOS 26.4.1

Reproduction URL

https://github.com/natefzz/tailwind-turbopack-stale-css

The README has the steps and a script (check-stale.mjs) that edits globals.css repeatedly and checks the CSS served by the dev server.

Describe your issue

With the @tailwindcss/turbopack loader added in #20367, editing the input CSS file during next dev makes the dev server keep serving the previous version of that CSS. Saving again without changing the content does not help; only restarting the dev server does. With @tailwindcss/postcss and the same Turbopack dev server, the problem goes away.

What I think is happening

The loader caches one compiler per CSS file and decides whether to rebuild it by comparing mtimes on disk, not the source it receives. I added logging to dist/index.js (input value, statSync(resourcePath).mtimeMs, rebuild decision, output). For a single save from #ffffff to #ff0000, Turbopack invoked the loader twice:

CALL  input=#ffffff  fileMtime=1791964831511.853   <- old source, but the mtime is already new
      decide=full    newCompiler=true              <- compiler rebuilt from the OLD source
      OUTPUT=#ffffff
CALL  input=#ff0000  fileMtime=1791964831511.853   <- correct source
      decide=incremental newCompiler=false         <- mtime unchanged, stale compiler reused
      OUTPUT=#ffffff                               <- stale output

The first call gets the previous source but already sees the new mtime, so it rebuilds the compiler from the old source and records the new mtime. The second call gets the correct source, but the mtime matches, so it reuses that stale compiler.

I'm not sure why Turbopack first runs the loader with the previous source. My guess is that the loader registers both file dependencies and a context dependency on the project directory, which gives two invalidation paths. As far as I can tell, the mtime check works with webpack, which calls the loader once with fresh content, but it doesn't hold up under Turbopack's behavior.

Possible fix

Store the last source (or a hash of it) on the cache entry, and force a full rebuild whenever source differs, in addition to the existing mtime checks. I'm happy to open a PR if this direction sounds right.

Activity

  1. natefzz commented on Oct 16, 2026

    @natefzz
    Author

    I looked at how @tailwindcss/postcss decides whether to rebuild, and it already handles this case. After the same mtime checks, it also compares the incoming CSS with the CSS from the previous run:

    let inputCss = root.source?.input.css ?? root.toString()
    if (context.inputCss !== inputCss) {
      rebuildStrategy = 'full'
      context.inputCss = inputCss
    }

    So even when the mtime hasn't changed, a different source still triggers a full rebuild. The Turbopack loader only checks mtimes and doesn't store the previous source on its cache entry, which is why the second call in the log above reuses the stale compiler.

    Adding the same inputCss comparison to the loader should fix this, and would make both integrations behave the same way.

  2. self-assigned this
    on Oct 16, 2026
  3. RobinMalfait commented on Oct 16, 2026

    @RobinMalfait
    Contributor

    After an edit of globals.css, the Turbopack loader sometimes reused a compiler from the previous version of the file, because it compared only the mtimes and not the source it received. Now the loader also compares the input CSS with the previous run, as @tailwindcss/postcss does, so next dev serves the new CSS after each save. The @tailwindcss/webpack loader gets the same fix.

    This should be fixed by #20582, and will be available in the next release.

    You can already try it with the insiders build. It is published a few minutes after the merge:

    npm install tailwindcss@insiders @tailwindcss/turbopack@insiders

    Sent by an AI assistant on behalf of @RobinMalfait.

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