MCPcopy Create free account
hub / github.com/dailydotdev/apps / installDomMutationGuard

Function installDomMutationGuard

packages/shared/src/lib/domMutationGuard.ts:32–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30
31// @see https://github.com/facebook/react/issues/11538#issuecomment-417504600
32export const installDomMutationGuard = (): void => {
33 if (isInstalled || typeof Node === 'undefined') {
34 return;
35 }
36
37 isInstalled = true;
38
39 const originalRemoveChild = Node.prototype.removeChild;
40 Node.prototype.removeChild = function removeChild<T extends Node>(
41 this: Node,
42 child: T,
43 ): T {
44 if (child.parentNode !== this) {
45 reportHit('removeChild');
46 return child;
47 }
48
49 return originalRemoveChild.call(this, child) as T;
50 };
51
52 const originalInsertBefore = Node.prototype.insertBefore;
53 Node.prototype.insertBefore = function insertBefore<T extends Node>(
54 this: Node,
55 node: T,
56 child: Node | null,
57 ): T {
58 if (child && child.parentNode !== this) {
59 reportHit('insertBefore');
60 return node;
61 }
62
63 return originalInsertBefore.call(this, node, child) as T;
64 };
65};

Callers 2

_app.tsxFile · 0.90

Calls 1

reportHitFunction · 0.85

Tested by

no test coverage detected