Skip to content

Config change reported during a dev reload is lost, Payload keeps the stale config #19053

Open

Description

@RafalFilipek

Describe the Bug

In development, a config change reported while Payload is already reloading the config is lost. Payload keeps the config read at the start of that reload until another file change is reported or the dev server restarts.

This happens whenever several files are saved within a short time: a new component saved as several files one after another, git checkout / git pull, a formatter or codemod rewriting files, an editor's "save all".

Cause. The dev reload callback in connectDevReload (packages/payload/src/index.ts) ignores a change while a reload is in progress:

cached.devReloadCleanup = strategy.connect(() => {
  if (cached.reload instanceof Promise) {
    return
  }
  cached.reload = true
})

and getPayload clears the flag unconditionally once that reload finishes:

await reload(config, cached.payload, false, options)

resolve()
cached.reload = false

The reload in progress already awaited options.config from the module graph that was current when it started, so it may hold the config from before the second change. Nothing marks that another reload is needed, so the next getPayload call returns the stale instance.

This is independent of the reload strategy: it affects the default Next.js HMR WebSocket strategy, the TanStack Start strategy and a custom devReloadStrategy alike.

Expected: the config contains both changes.
Actual: only the first change is applied; the second appears only after another file change or a restart.

Link to the code that reproduces this issue

https://github.com/RafalFilipek/payload/blob/fix/hmr-config-reload-queued/packages/payload/src/getPayload.spec.ts

Reproduction Steps

  1. Run a Payload app in dev (next dev).
  2. Change the config (for example add a field to a collection) and, while Payload is still reloading after that change, save a second change (for example in another file imported by the config). Easiest to hit with a reload that takes a moment (Postgres/SQLite schema push, import map generation) or with a git checkout between two branches with different configs.
  3. Open the admin panel or call getPayload again: only the first change is there.

The linked unit test reproduces it without a dev server: it captures the callback passed to devReloadStrategy.connect, holds a reload in progress with a pending config promise, reports a second change, and checks that the next getPayload call reloads again (it fails on main).

Which area(s) are affected?

area: core

Environment Info

Payload: 4.0.0-beta.4 (also main at aebbf75b9; same code in 3.x)
Next.js: 16.4.2
Node.js: 24.22.1

Activity

  1. added
    area: core
    and removed
    area: core
    on Oct 27, 2026
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions