From 7a1530d91160912a633cb7cc878135620de63b0d Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Wed, 6 Aug 2025 22:26:30 +0800 Subject: [PATCH] refactor: remove unnecessary `Element` check [DOMPurify v3.2.2][1] narrowed down the types of these hooks so that these are known to have the `Element` type, which means checking the type of these at runtime is unnecessary. [1]: https://github.com/cure53/DOMPurify/releases/tag/3.2.2 See: fe3cffbb673a25b81989aacb06e5d0eda35326db See: https://github.com/cure53/DOMPurify/commit/4cdfd1ffef091823d72d91cc78616eb7070b22a0 --- packages/mermaid/src/diagrams/common/common.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mermaid/src/diagrams/common/common.ts b/packages/mermaid/src/diagrams/common/common.ts index 00c9b8313..4b73bb02f 100644 --- a/packages/mermaid/src/diagrams/common/common.ts +++ b/packages/mermaid/src/diagrams/common/common.ts @@ -33,13 +33,13 @@ function setupDompurifyHooks() { const TEMPORARY_ATTRIBUTE = 'data-temp-href-target'; DOMPurify.addHook('beforeSanitizeAttributes', (node) => { - if (node instanceof Element && node.tagName === 'A' && node.hasAttribute('target')) { + if (node.tagName === 'A' && node.hasAttribute('target')) { node.setAttribute(TEMPORARY_ATTRIBUTE, node.getAttribute('target') ?? ''); } }); DOMPurify.addHook('afterSanitizeAttributes', (node) => { - if (node instanceof Element && node.tagName === 'A' && node.hasAttribute(TEMPORARY_ATTRIBUTE)) { + if (node.tagName === 'A' && node.hasAttribute(TEMPORARY_ATTRIBUTE)) { node.setAttribute('target', node.getAttribute(TEMPORARY_ATTRIBUTE) ?? ''); node.removeAttribute(TEMPORARY_ATTRIBUTE); if (node.getAttribute('target') === '_blank') {