-
-
Notifications
You must be signed in to change notification settings - Fork 883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hard to move elements around using solid-js, insertExpression isn't fully DOM aware #2030
Comments
I see. These are scenarios where you are keeping a DOM reference, and Solid thinks it knows where it was inserted, but when we get Solid to insert somewhere it is no longer where Solid thinks. This is the kind of issue I'd like to fix if it isn't prohibitive. The challenge is I imagine stuff not being where we expect could have a multitude of possible issues, but trying to fix these should have no impact on people not using these patterns accept if there is some some small performance considerations. |
In version 2 the bug is here: https://github.com/ryansolid/dom-expressions/blob/f691a482cea35336e7206759f0e8d2322f9371dd/packages/dom-expressions/src/reconcile.js#L72 What happens is that here The (The two elements in |
Describe the bug
When wanting to only create two components once, but then switching them around in the DOM (wrapping and unwrapping them), solid-js doesn't really play nicely.
According to a discord conversation this isn't intended behavior, so here's a bug report.
Why do I want to do this? For switching between desktop and mobile layouts I don't see a reason to rerender big components and all their children just to wrap/unwrap them in a div.
Your Example Website or App
https://playground.solidjs.com/anonymous/30690d0e-bff5-4cd5-9309-a847e3b08683
Steps to Reproduce the Bug or Issue
Version 1: Definitely a bug (crashes)
If you don't deem this misusing solid it's probably a bug:
Uncaught DOMException: Failed to execute 'replaceChild' on 'Node': The new child element contains the parent.
From the error message, I suspect this could be avoided by using
element.replaceWith
or another one of the new DOM manipulation functions but I'm not sure (and I understand they are probably slower)Version 2: Doesn't work as expected
This could be interpreted as expected behavior because there's no error but I'd still really love if this worked:
Expected behavior
In example 1: No crash, element is moved
In example 2: Elements don't disappear, are moved instead
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: