Skip to content

Commit 43ab996

Browse files
committed
fix
1 parent 5c0fc90 commit 43ab996

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

web_src/js/modules/dirauto.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {isDocumentFragmentOrElementNode} from '../utils/dom.js';
2+
13
// for performance considerations, it only uses performant syntax
24

35
function attachDirAuto(el) {
@@ -18,7 +20,7 @@ export function initDirAuto() {
1820
const len = mutation.addedNodes.length;
1921
for (let i = 0; i < len; i++) {
2022
const addedNode = mutation.addedNodes[i];
21-
if (addedNode.nodeType !== Node.ELEMENT_NODE && addedNode.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) continue;
23+
if (!isDocumentFragmentOrElementNode(addedNode)) continue;
2224
if (addedNode.nodeName === 'INPUT' || addedNode.nodeName === 'TEXTAREA') attachDirAuto(addedNode);
2325
const children = addedNode.querySelectorAll('input, textarea');
2426
const len = children.length;

web_src/js/modules/tippy.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import tippy, {followCursor} from 'tippy.js';
2+
import {isDocumentFragmentOrElementNode} from '../utils/dom.js';
23

34
const visibleInstances = new Set();
45

@@ -136,8 +137,6 @@ function attachChildrenLazyTooltip(target) {
136137
}
137138
}
138139

139-
const elementNodeTypes = new Set([Node.ELEMENT_NODE, Node.DOCUMENT_FRAGMENT_NODE]);
140-
141140
export function initGlobalTooltips() {
142141
// use MutationObserver to detect new "data-tooltip-content" elements added to the DOM, or attributes changed
143142
const observerConnect = (observer) => observer.observe(document, {
@@ -152,11 +151,10 @@ export function initGlobalTooltips() {
152151
if (mutation.type === 'childList') {
153152
// mainly for Vue components and AJAX rendered elements
154153
for (const el of mutation.addedNodes) {
155-
if (elementNodeTypes.has(el.nodeType)) {
156-
attachChildrenLazyTooltip(el);
157-
if (el.hasAttribute('data-tooltip-content')) {
158-
attachLazyTooltip(el);
159-
}
154+
if (!isDocumentFragmentOrElementNode(el)) continue;
155+
attachChildrenLazyTooltip(el);
156+
if (el.hasAttribute('data-tooltip-content')) {
157+
attachLazyTooltip(el);
160158
}
161159
}
162160
} else if (mutation.type === 'attributes') {

web_src/js/utils/dom.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ export function onDomReady(cb) {
5959
}
6060
}
6161

62+
export function isDocumentFragmentOrElementNode(el) {
63+
try {
64+
return el.nodeType === Node.ELEMENT_NODE || el.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
65+
} catch {
66+
// in case the el is not in the same origin, then the access to nodeType would fail
67+
return false;
68+
}
69+
}
70+
6271
// autosize a textarea to fit content. Based on
6372
// https://github.com/github/textarea-autosize
6473
// ---------------------------------------------------------------------

0 commit comments

Comments
 (0)