payloadcms / payloadcms/payload

[v3] "Create New" form immediately closes/redirects after leaving a dirty form via "Leave anyway"

Open
#17,233 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area: ui status: needs-triage v3
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

Describe the Bug

Note: This is a core routing bug reproducible on a completely fresh install of the standard blank template.

In the Payload v3 Admin UI, when a user modifies a document and then attempts to navigate away via the sidebar, the Leave without saving modal correctly intercepts the navigation. However, if the user confirms by clicking "Leave anyway" and is routed to a collection's list view, the internal state of the interceptor (or Next.js router state) is not properly cleared.

If the user then immediately clicks the "Create New" button on that list view, the /create view attempts to mount but is instantly aborted or redirected back to the list view (effectively making it look like the form "quickly closes" or refuses to open).

A manual browser refresh (F5) on the list view clears this broken in-memory state, allowing the "Create New" button to function normally again.

Expected Behavior

Clicking "Leave anyway" should completely reset the useLeaveWithoutSaving routing state so that subsequent UI navigations (like clicking "Create New") process normally without triggering an unintended closure or redirect.

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/tree/main/templates/blank

Reproduction Steps
  1. Go to the CMS Admin panel and log in.
  2. Navigate to a collection (e.g., Users) and enter the Create or Edit view.
  3. Make a change to the form or trigger a validation error (e.g., click Save with missing required fields) so the form is marked as "dirty" (modified).
  4. Click on the Users collection link from the left-side navigation menu.
  5. The Leave without changes modal will appear.
  6. Click the "Leave anyway" button. You will be routed to the Users list view.
  7. Click the "Create New" button on the list view.
  8. Observe: The form attempts to open but quickly closes/redirects back to the list view. The user is unable to create a new record unless they refresh the page.
Which area(s) are affected?

area: ui

Environment Info
Payload Version: 3.81.0 (Also reproduced on 3.85.1)
Next.js Version: 15.0.0

---

Binaries:
  Node: 22.17.0
  npm: 10.9.2
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  payload: 3.81.0
  next: 16.2.1
  @payloadcms/db-postgres: 3.81.0
  @payloadcms/drizzle: 3.81.0
  @payloadcms/graphql: 3.81.0
  @payloadcms/next/utilities: 3.81.0
  @payloadcms/plugin-cloud-storage: 3.81.0
  @payloadcms/plugin-multi-tenant: 3.81.0
  @payloadcms/plugin-nested-docs: 3.81.0
  @payloadcms/richtext-lexical: 3.81.0
  @payloadcms/storage-s3: 3.81.0
  @payloadcms/translations: 3.81.0
  @payloadcms/ui/shared: 3.81.0
  react: 19.2.1
  react-dom: 19.2.1
Operating System:
  Platform: linux
  Arch: x64

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the navigation sequence in the templates/blank app, then trace the useLeaveWithoutSaving state through the sidebar transition and the collection list's Create New route. Check the Next.js router state after clicking "Leave anyway"; done means the create view remains open and usable without a browser refresh.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.