Skip to content

Commit d092131

Browse files
committed
feat: an updated implementation for link relation in afterRead hook.
1 parent ad6f413 commit d092131

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/fields/LexicalRichText/LexicalAfterReadHook.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,14 @@ export async function traverseLexicalField(
105105
locale
106106
);
107107
if (relation != null) {
108-
attributes.doc.data = relation;
108+
// TODO: revisit
109+
// I think these are the only properties we need to build a
110+
// link on the client - id, title, and slug. The collection slug is
111+
// already part of attributes?.doc?.relationTo
112+
// and so this should be everything that's needed - whether building
113+
// a complete URL, or a framework router link
114+
const { id, title, slug } = relation;
115+
attributes.doc.data = { id, title, slug };
109116
}
110117
}
111118
} else if (node.type === 'inline-image') {
@@ -128,6 +135,9 @@ export async function traverseLexicalField(
128135
// TODO: I'm not sure how this will affect the 'depth' option for
129136
// each related document. I believe it will effectivly retrieve the
130137
// entire tree (i.e. all children, ignoring depth)
138+
// See the test solution for link node above, where we only take
139+
// const { id, title, slug } = relation;
140+
// TODO: revist - depth option in loadRelated above
131141
if (node.children != null && node.children.length > 0) {
132142
const newChildren: SerializedLexicalNode[] = [];
133143
for (const childNode of node.children) {

0 commit comments

Comments
 (0)