Skip to content

Commit

Permalink
fix: undefined mappings in csm
Browse files Browse the repository at this point in the history
  • Loading branch information
YvesRijckaert committed Dec 10, 2024
1 parent d47d498 commit 8dee8be
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions packages/content-source-maps/src/richText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,27 @@ 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);
// Only proceed with mapping if we have a valid source
if (source) {
// We can now safely delete the original pointer as we've preserved the source
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);
}
} else {
// If there's no source mapping, just encode the text nodes without creating mappings
const textNodes = findRichTextNodes(data, pointer);
for (const textNode of textNodes) {
const currentTextNodeValue = get(data, textNode);
const encodedValue = combine(currentTextNodeValue, hiddenStrings);
set(data, textNode, encodedValue);
}
}
};

Expand Down

0 comments on commit 8dee8be

Please sign in to comment.