From 6b78bc926f1d85dabc6bd1c43ecd98892ec2ab56 Mon Sep 17 00:00:00 2001 From: Yves Rijckaert Date: Tue, 10 Dec 2024 14:14:13 +0100 Subject: [PATCH] fix: undefined mappings in csm --- packages/content-source-maps/src/richText.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/content-source-maps/src/richText.ts b/packages/content-source-maps/src/richText.ts index e1885005..28a51623 100644 --- a/packages/content-source-maps/src/richText.ts +++ b/packages/content-source-maps/src/richText.ts @@ -15,15 +15,18 @@ export const encodeRichTextValue = ({ hiddenStrings: SourceMapMetadata; }) => { const source = mappings[pointer]; - // remove old pointer to rich text field as we will just be mapping the text nodes - delete mappings[pointer]; - const textNodes = findRichTextNodes(data, pointer); - for (const textNode of textNodes) { - mappings[textNode] = source; - const currentTextNodeValue = get(data, textNode); - const encodedValue = combine(currentTextNodeValue, hiddenStrings); - set(data, textNode, encodedValue); + if (source) { + // remove old pointer to rich text field as we will just be mapping the text nodes + delete mappings[pointer]; + + const textNodes = findRichTextNodes(data, pointer); + for (const textNode of textNodes) { + mappings[textNode] = source; + const currentTextNodeValue = get(data, textNode); + const encodedValue = combine(currentTextNodeValue, hiddenStrings); + set(data, textNode, encodedValue); + } } };