payloadcms / payloadcms/payload
Relationship filterOptions do not updated after adding item to join field
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 44.8k
- Forks
- 4.2k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 53
Description
Describe the Bug
I have a collection where you can select a default post based on the posts in a join field in that same collection.
I use the filterOption on the relationship field to only show posts that are in the join field, but this does not update when you add a new item to the join field while editing.
Because this functionality does work with a relationship field instead of a join field, I was asked (on Discord) to provide a working version with a relationship field and the broken version with the join field
Link to the code that reproduces this issue
https://github.com/AaronClaes/payload-join-bug
Reproduction Steps
Step 1:
Create a join field collection without default value or posts
Step 2:
If it's created, use the "Create new Post" button from the join field and save the new post.
Step 3:
Notice how the default post select still has no possible options
Step 4:
Refresh and now the default post option is there
Remark:
You can do step 2 at any given time, it is not related to how many posts are in the join field already, step 3 will never show the newly added post
Which area(s) are affected? (Select all that apply)
area: ui
Environment Info
Binaries:
Node: 23.5.0
npm: 10.9.2
Yarn: 1.22.19
pnpm: 9.15.1
Relevant Packages:
payload: 3.28.0
next: 15.2.0
@payloadcms/db-mongodb: 3.28.0
@payloadcms/email-nodemailer: 3.28.0
@payloadcms/graphql: 3.28.0
@payloadcms/next/utilities: 3.28.0
@payloadcms/payload-cloud: 3.28.0
@payloadcms/richtext-lexical: 3.28.0
@payloadcms/translations: 3.28.0
@payloadcms/ui/shared: 3.28.0
react: 19.0.0
react-dom: 19.0.0
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000
Available memory (MB): 16384
Available CPU cores: 8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the linked reproduction repository first, then compare src/collections/RelationshipFieldCollection.ts with src/collections/JoinFieldCollection.ts. Reproduce adding a post through the join field and observe the default post filter before and after a refresh. Done means the newly added post appears as an option without refreshing the page, while the existing relationship-field behavior remains intact.
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
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 62/100