Skip to content

Commit 94d5728

Browse files
authored
fix(ui): upsertPreferences did not return preferences when creating new preferences (#15321)
This fixes a bug where `upsertPreferences` returned undefined if the preferences did not exist before. In the list view, this causes url params to be ignored on the first page load, as the following happened: 1. take query params from url 2. store them in preferences using `upsertPreferences` 3. work with the result of `upsertPreferences` 4. original query params are lost, even though they should have been returned from `upsertPreferences` An e2e test for this is added in #15320, which depends on this PR.
1 parent 0c235c3 commit 94d5728

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/ui/src/utilities/upsertPreferences.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const upsertPreferences = async <T extends Record<string, unknown> | stri
8383
let newPrefs = existingPrefs?.value
8484

8585
if (!existingPrefs?.id) {
86-
await req.payload.create({
86+
const createdPrefs = await req.payload.create({
8787
collection: 'payload-preferences',
8888
data: {
8989
key,
@@ -97,6 +97,7 @@ export const upsertPreferences = async <T extends Record<string, unknown> | stri
9797
disableTransaction: true,
9898
user: req.user,
9999
})
100+
return createdPrefs.value
100101
} else {
101102
let mergedPrefs: T
102103

0 commit comments

Comments
 (0)