Log details about the node that failed to be removed / inserted
This commit is contained in:
parent
33f22ac483
commit
cdef07ca2c
1 changed files with 24 additions and 2 deletions
|
@ -96,12 +96,28 @@ function checkBrowserFeatures() {
|
||||||
* try to log in, which is also a fairly terrible failure mode).
|
* try to log in, which is also a fairly terrible failure mode).
|
||||||
*/
|
*/
|
||||||
function monkeyPatchForReact() {
|
function monkeyPatchForReact() {
|
||||||
|
function findAncestorWithClass(node) {
|
||||||
|
let depth = 0;
|
||||||
|
while (node) {
|
||||||
|
if (node.className) return [node, depth];
|
||||||
|
node = node.parentNode;
|
||||||
|
++depth;
|
||||||
|
}
|
||||||
|
return [null, 0];
|
||||||
|
}
|
||||||
|
|
||||||
const originalRemoveChild = Node.prototype.removeChild;
|
const originalRemoveChild = Node.prototype.removeChild;
|
||||||
Node.prototype.removeChild = function(...args) {
|
Node.prototype.removeChild = function(...args) {
|
||||||
try {
|
try {
|
||||||
return originalRemoveChild.apply(this, args);
|
return originalRemoveChild.apply(this, args);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Caught exception from removeChild", e);
|
const [ancestor, depth] = findAncestorWithClass(args[0]);
|
||||||
|
console.log(
|
||||||
|
"Caught exception from removeChild, removing node of type " +
|
||||||
|
args[0].type + ". Closest ancestor with class is a " + ancestor.type +
|
||||||
|
" with class " + ancestor.className + " " + depth + " levels above. " +
|
||||||
|
"See https://github.com/vector-im/riot-web/issues/13557", e,
|
||||||
|
);
|
||||||
return originalRemoveChild.apply(args[0].parentNode, args);
|
return originalRemoveChild.apply(args[0].parentNode, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +127,13 @@ function monkeyPatchForReact() {
|
||||||
try {
|
try {
|
||||||
return originalInsertBefore.apply(this, args);
|
return originalInsertBefore.apply(this, args);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Caught exception from insertBefore", e);
|
const [ancestor, depth] = findAncestorWithClass(args[0]);
|
||||||
|
console.log(
|
||||||
|
"Caught exception from removeChild, removing " + args[0].type +
|
||||||
|
". Closest ancestor with class is a " + ancestor.type +
|
||||||
|
" with class " + ancestor.class + " " + depth + " levels above. " +
|
||||||
|
"See https://github.com/vector-im/riot-web/issues/13557", e,
|
||||||
|
);
|
||||||
// We could use appendChild instead, then the node would
|
// We could use appendChild instead, then the node would
|
||||||
// be in the DOM but not necessarily in the right place?
|
// be in the DOM but not necessarily in the right place?
|
||||||
// For now, do nothing.
|
// For now, do nothing.
|
||||||
|
|
Loading…
Add table
Reference in a new issue