From 0221880d796441059c7657b072dbcbc2e9c5b278 Mon Sep 17 00:00:00 2001 From: Kashargul <144968721+Kashargul@users.noreply.github.com> Date: Sun, 17 Aug 2025 03:33:53 +0200 Subject: [PATCH] fix chat highlights (#92589) ## About The Pull Request If we always define the fragment, the if after the loop will always pass. ## Why It's Good For The Game fixes #92468 grafik ## Changelog :cl: fix: chat highlights /:cl: --- tgui/packages/tgui-panel/chat/replaceInTextNode.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tgui/packages/tgui-panel/chat/replaceInTextNode.ts b/tgui/packages/tgui-panel/chat/replaceInTextNode.ts index 5a4bb526f89..f58ca0fe4fd 100644 --- a/tgui/packages/tgui-panel/chat/replaceInTextNode.ts +++ b/tgui/packages/tgui-panel/chat/replaceInTextNode.ts @@ -27,9 +27,9 @@ function regexParseNode(params: ReplaceInTextNodeParams): { return { nodes: [], n: 0 }; } - const fragment = document.createDocumentFragment(); const nodes: Node[] = []; const textLength = text.length; + let fragment: Node | undefined; let count = 0; let lastIndex = 0; let match: RegExpExecArray | null; @@ -44,6 +44,10 @@ function regexParseNode(params: ReplaceInTextNodeParams): { if (++count > 9999) { return { nodes: [], n: 0 }; } + // Lazy init fragment + if (!fragment) { + fragment = document.createDocumentFragment(); + } const matchText = captureAdjust ? captureAdjust(match[0]) : match[0]; const matchLength = matchText.length;