question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Cannot set parent: node already has a parent

See original GitHub issue

Describe the bug

We use Liveblocks on a react app with live text input updates. The initial contents of this text input are fetched from a param value in the URL. Eg. /play/<text-input-id>

This text-input-id is then used to retrieve associated data from the database. There is also a dropdown input that lets you select valid text-input-id on selecting, we update the route history as well /play/<new-text-input-id>

Everything works as expected, however, there is a strange edge case where Liveblock fails with the following error:

index.js:194 Uncaught Error: Cannot set parent: node already has a parent
    at LiveObject._setParentLink (index.js:194:1)
    at LiveObject.update (index.js:1953:1)
    at LiveObject.set (index.js:1849:1)
    at createOrUpdateRootFromMessage (index.js:2747:1)
    at index.js:3247:1
    at doNotBatchUpdates (index.js:2637:1)
    at WebSocket.onMessage (index.js:3205:1)

To Reproduce

Steps to reproduce the behavior:

  1. Got to /play/<text-input-id>
  2. Inspect that the initial data is loaded correctly.
  3. Change the ID from the dropdown to a new ID. The route is now updated to /play/<new-text-input-id>
  4. Inspect that the initial data is loaded correctly.
  5. Switch back to the old ID. The route is now updated to /play/<text-input-id>
  6. Check the console for the above error.

Expected behavior

The input value should be updated to the old value fetched from the database.

Environment (please complete the following information):

Happy to provide any additional context to help understand the root cause here.

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
nviecommented, Nov 17, 2022

Probably a dumb question, but that should not break things, right? Providing a new room id should switch to a new room?

Not dumb at all! Actually, a good find. This may be something we need to fix indeed. Thanks for bringing it to our attention.

If that theory is correct, you should be able to work around it for now by also passing the roomId to a key prop to the RoomProvider, like so:

<RoomProvider
  key={editorId}  // 👈
  id={editorId}
  ...
>
  ...
</RoomProvider>

Doing so will cause React to unmount-then-remount the new room instead of letting the RoomProvider do the switching.

1reaction
chaitanyyacommented, Nov 16, 2022

Thanks for the update; I’ll prepare a minimal example based on our implementation and share it asap.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: "Cannot add child "18903" to parent "18774" because ...
This happened to me, the node wasn't appearing in the Components tree and I was getting this error. The problem was that my...
Read more >
TFS200020: The parent node already has a child node with ...
Trying to add a sprint and getting this error: TFS200020: The parent node already has a child node with the following name: V5....
Read more >
Getting an error "Parent node xxx is not of type 'NodeMixin ...
From this Github Issue it seems you need to explicitly set parent=None in the root node. And also it seems AnyNode expects **kwargs....
Read more >
Node.parentNode - Web APIs | MDN
The read-only parentNode property of the Node interface returns the parent of the specified node in the DOM tree.
Read more >
"Can't add child, already has parent" error when creating bullet
Hey everybody, I'm trying to spawn a bullet upon clicking the mouse. The problem is the bullet is spawned once and after that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found