Skip to content
This repository was archived by the owner on Jan 28, 2026. It is now read-only.

🐛 Catch removeChild error use semantic node instead of text node#309

Merged
asim-shrestha merged 1 commit intoreworkd:mainfrom
l2hyunwoo:feature/catch-remove-child-error
Apr 22, 2023
Merged

🐛 Catch removeChild error use semantic node instead of text node#309
asim-shrestha merged 1 commit intoreworkd:mainfrom
l2hyunwoo:feature/catch-remove-child-error

Conversation

@l2hyunwoo
Copy link
Copy Markdown
Contributor

ref: facebook/react#11538 (comment)

fixed: #212

Additional Question) There's another workaround that if removeChild will cause error keep child node and make not crush. Is below code useful to this situation?

if (typeof Node === 'function' && Node.prototype) {
  const originalRemoveChild = Node.prototype.removeChild;
  Node.prototype.removeChild = function(child) {
    if (child.parentNode !== this) {
      if (console) {
        console.error('Cannot remove a child from a different parent', child, this);
      }
      return child;
    }
    return originalRemoveChild.apply(this, arguments);
  }

  const originalInsertBefore = Node.prototype.insertBefore;
  Node.prototype.insertBefore = function(newNode, referenceNode) {
    if (referenceNode && referenceNode.parentNode !== this) {
      if (console) {
        console.error('Cannot insert before a reference node from a different parent', referenceNode, this);
      }
      return newNode;
    }
    return originalInsertBefore.apply(this, arguments);
  }
}

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 22, 2023

@l2hyunwoo is attempting to deploy a commit to the reworkd Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
agent-gpt ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 22, 2023 5:40am

@asim-shrestha asim-shrestha merged commit 10c0364 into reworkd:main Apr 22, 2023
@l2hyunwoo l2hyunwoo deleted the feature/catch-remove-child-error branch April 22, 2023 15:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Failed to execute 'removeChild' on 'Node'

2 participants