payload icon indicating copy to clipboard operation
payload copied to clipboard

Switching list-view tabs (All / By Folder / Trash) wipes the collection's saved preferences (columns, sort, limit)

Open mishery97 opened this issue 3 months ago • 2 comments

Describe the Bug

DefaultListViewTabs saves which sub-view is active with:

// @payloadcms/ui/dist/elements/DefaultListViewTabs/index.js (3.87.0, ~line 41)
await setPreference(`collection-${collectionConfig.slug}`, {
  listViewType: newViewType
});

setPreference defaults to merge = false (providers/Preferences/index.js, line 76), so this call replaces the entire collection-<slug> preference record with { listViewType } — silently destroying the user's saved columns, sort, limit and any other list preferences, every time they click between "All " and "By Folder" (or Trash).

We confirmed the mechanism by reading the payload-preferences record before/after a tab click: a record containing { limit, columns, listViewType } is reduced to { listViewType: "folders" } by a single click on the By Folder pill.

This hits folder-enabled upload collections hardest: users add the Folder column, visit By Folder to organise, come back — and their column setup is gone. Non-technical editors experience this as "my columns keep randomly disappearing".

Reproduction steps

  1. Any collection with folders: true (or trash: true) so the tab pills render.
  2. In the list view, add a column via the Columns panel (e.g. Folder). Confirm the collection-<slug> preference record now contains columns.
  3. Click By Folder, then All .
  4. The added column is gone; the preference record contains only { listViewType }.

Expected / Actual

  • Expected: switching tabs remembers the active sub-view without touching other saved preferences.
  • Actual: every tab switch replaces the whole preference record.

Proposed fix

Pass the existing merge flag (one argument):

  await setPreference(`collection-${collectionConfig.slug}`, {
    listViewType: newViewType
- });
+ }, true);

Note the same handler is also inlined (minified) in dist/exports/client/index.js, which is what some import sites actually execute — the fix needs to land in the source so both builds pick it up. We've been running this exact change in production via a pnpm patch with no side effects.

Environment

  • Payload: 3.86.0 (found), verified still present in 3.87.0 source
  • @payloadcms/db-postgres, @payloadcms/next
  • Next.js: 16.2.11
  • Node: 22.14.0
  • pnpm 10.30.3, macOS / Vercel

mishery97 avatar Aug 06 '26 05:08 mishery97

Hey! Thanks for writing up such a clear reproduction for this bug. I just opened a PR (#17680) to get this fixed.

As suggested, it was just a matter of adding the true merge flag to the setPreference call in DefaultListViewTabs so it doesn't wipe out the existing column/sort setups. Hopefully, this gets merged soon!

NitinSemwal2605 avatar Aug 06 '26 15:08 NitinSemwal2605

Thanks for looking at it.

mishery97 avatar Aug 09 '26 21:08 mishery97