Skip to content

Conversation

jhb-dev
Copy link
Contributor

@jhb-dev jhb-dev commented Jul 21, 2025

What?

Optimize the relationship value loading by selecting only the useAsTitle field when fetching document data via the REST API.

Why?

Previously, all fields were fetched via a POST request when loading the document data of a relationship value, causing unnecessary data transfer and slower performance. Only the useAsTitle field is needed to display the related document’s title in the relationship UI field.

How?

Applied a select to the REST API POST request, similar to how the options list is loaded, limiting the response to the useAsTitle field only.

Related: #12251

@jacobsfletch
Copy link
Member

We've explored this in the past but unfortunately this would be considered a breaking change as users consuming this component might be currently relying on fully populated data. This would have to be made opt-in.

@jhb-dev
Copy link
Contributor Author

jhb-dev commented Jul 22, 2025

Thanks for the quick response, @jacobsfletch. I just pushed a commit to make this performance optimization opt-in at the relationship field level via a new populateDocumentTitleOnly option.
Please let me know if you have any feedback or would prefer a different name or approach.

@jacobsfletch
Copy link
Member

jacobsfletch commented Jul 28, 2025

@jhb-dev I meant opt-in at the component-level, not on the config. Buuut after looking into this further, we only ever dispatch the document ID to the onChange handlers and ultimately form state. We no longer expose the full document data, so I think this is a safe change to make after all!

…p field to ensure backwards compatability"

This reverts commit 71ed479.
@jhb-dev
Copy link
Contributor Author

jhb-dev commented Jul 30, 2025

Thanks, @jacobsfletch, that's great! I've reverted the commit that added the opt-in.

@JarrodMFlesch
Copy link
Contributor

@jacobsfletch 👀

Copy link
Member

@jacobsfletch jacobsfletch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @jhb-dev

@jacobsfletch jacobsfletch merged commit 1b31c74 into payloadcms:main Aug 1, 2025
163 of 166 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants