Skip to content

Dev: generated route.js is rewritten with identical content on every compile, thrashing the webpack watcher #3451

Description

@AaronRutley

What happens

withWorkflow regenerates app/.well-known/workflow/v1/**/route.js on every dev compile. The contents are byte-identical each time — only the mtime changes.

Webpack's watcher keys on mtime, and those generated files sit inside the watched Next app directory. So every compile rewrites a file that re-invalidates the compiler that just wrote it.

Reproduce

Run next dev (webpack), then:

shasum -a 256 src/app/.well-known/workflow/v1/step/route.js
touch src/lib/any-unrelated-file.ts
curl -s -o /dev/null http://localhost:3000/some-page

shasum -a 256 src/app/.well-known/workflow/v1/step/route.js   # identical hash
stat -f %m src/app/.well-known/workflow/v1/step/route.js      # mtime bumped

Impact

From .next/trace, a single touch of one leaf source file produced:

count
webpack compilations 3
client invalidations 2
HMR pushes 4
CSS module rebuilds 4

In our app (~520 source files, 53 pages, 93 route handlers) that meant roughly 2.2s of rebuilding across three compilations after every edit, and a 1.37s cold compile on a heavy route. The generated step/route.js is 603 KB, so it is not a cheap entry to rebuild.

Workaround

next dev --turbopack. Turbopack hashes content rather than trusting mtime, so the identical rewrite becomes a no-op: one compilation per edit at 68ms, and the same cold route at 0.13s. The plugin still rewrites the file — the cascade just stops.

Suggested fix

Skip the write when the generated output already matches what is on disk. That fixes it for webpack users without requiring Turbopack, and saves a 603 KB write per compile for everyone else.

Versions

next 15.5.20
workflow 4.6.0
@workflow/next 4.1.0
node 24.11.1
OS macOS 26.5.2

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