Live preview does not correctly find relations when using blocks inside the lexical rte.
Link to reproduction
No response
Describe the Bug
The following line in the rich text traverser detects relations based on the relationTo and value fields inside any given iterated object in a rich text tree:
https://github.com/payloadcms/payload/blob/c038acb3a4da6cda85d034aeb8b042d172ee868f/packages/live-preview/src/traverseRichText.ts#L59
However, when using the blocks feature in the lexical rte, relationships are not defined by those fields, and instead simply hold an id string reference field.
Because of this, the rich text traverser is never able to resolve relation fields inside blocks.
To Reproduce
- Enable lexical editor field on some collection.
- Use the Blocks feature
- Create a block with a
type: 'relation'field, with arelationTosome other collection. - Populate the field in the admin UI
- Implement the live preview feature, set
depth> 0 - Check the data returned from the
callbackfunction - The relation field in the respective block will always just havr a
<fieldname>: <id>entry, regardless of thedepthparameter.
Payload Version
2.11.2
Adapters and Plugins
@payloadcms/[email protected]
Hey
Any news on the solution for this problem ?
I've found a workaround for this. Just set relationTo to an array, even if you only need to reference a single collection, like relationTo: ['images'] instead of relationTo: 'images'.
In this way the resulting field values will have the form of { relationTo: <collection-slug>, value: <resolved-document> }, which is resolved correctly by traverseRichText.