Skip to content

Solve the Google Translate problem in v2 #7461

Open
@Varixo

Description

@Varixo

Probably we should use some comments nodes for this


One of developer reported, that this code fixed problems with google translate in v2 (worth checking):

export const fix = () => {
    if (typeof Node !== "function" || !Node.prototype) {
        return;
    }

    const originalRemoveChild = Node.prototype.removeChild;
    const originalInsertBefore = Node.prototype.insertBefore;

    // @ts-expect-error
    Node.prototype.removeChild = function (child, ...rest) {
        if (child.parentNode !== this) {
            return child;
        }

        return originalRemoveChild.apply(this, [child, ...rest]);
    };

    // @ts-expect-error
    Node.prototype.insertBefore = function (newNode, referenceNode, ...rest) {
        if (referenceNode && referenceNode.parentNode !== this) {
            return newNode;
        }

        return originalInsertBefore.apply(this, [
            newNode,
            referenceNode,
            ...rest,
        ]);
    };
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status

      Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions