From cdf7f6937c6cc15a3b8ed63c080d7ecc0188f339 Mon Sep 17 00:00:00 2001 From: Seth Fowler Date: Fri, 15 May 2026 11:16:53 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20[PANA-7375]=20Eliminate=20?= =?UTF-8?q?unnecessary=20conditional=20node=20serialization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/rum-core/src/domain/privacy.ts | 30 +++++++------------ .../serialization/serializeMutations.ts | 2 +- .../serialization/serializeNode.node.spec.ts | 17 ++++------- .../record/serialization/serializeNode.ts | 9 +++--- 4 files changed, 21 insertions(+), 37 deletions(-) diff --git a/packages/rum-core/src/domain/privacy.ts b/packages/rum-core/src/domain/privacy.ts index 7e79edf002..ae86cc7667 100644 --- a/packages/rum-core/src/domain/privacy.ts +++ b/packages/rum-core/src/domain/privacy.ts @@ -220,37 +220,23 @@ export function censorText(text: string): string { return text.replace(/\S/g, TEXT_MASKING_CHAR) } -export function getTextContent(textNode: Node, parentNodePrivacyLevel: NodePrivacyLevel): string | undefined { +export function getTextContent(textNode: Node, parentNodePrivacyLevel: NodePrivacyLevel): string { // The parent node may not be a html element which has a tagName attribute. // So just let it be undefined which is ok in this use case. const parentTagName = textNode.parentElement?.tagName let textContent = textNode.textContent || '' - - const shouldIgnoreWhiteSpace = parentTagName === 'HEAD' - if (shouldIgnoreWhiteSpace && !textContent.trim()) { - return - } - const nodePrivacyLevel = parentNodePrivacyLevel - const isScript = parentTagName === 'SCRIPT' - - if (isScript) { + if (parentTagName === 'SCRIPT') { // For perf reasons, we don't record script (heuristic) textContent = CENSORED_STRING_MARK } else if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) { // Should never occur, but just in case, we set to CENSORED_MARK. textContent = CENSORED_STRING_MARK } else if (shouldMaskNode(textNode, nodePrivacyLevel)) { - if ( - // Scrambling the child list breaks text nodes for DATALIST/SELECT/OPTGROUP - parentTagName === 'DATALIST' || - parentTagName === 'SELECT' || - parentTagName === 'OPTGROUP' - ) { - if (!textContent.trim()) { - return - } + if (parentTagName === 'DATALIST' || parentTagName === 'SELECT' || parentTagName === 'OPTGROUP') { + // Masking the child list breaks text nodes for DATALIST/SELECT/OPTGROUP. + // TODO: Reinvestigate this. } else if (parentTagName === 'OPTION') { //