S
SolidJS4d ago
kmdr

Custom Rendering for OpenTUI

Does solid keep node references and re-use them after removal? Like in a Switch or For control flow, when things are not shown removes the nodes and when shown adds the same node again? OpenTUI renders to the terminal. The primitives like box and text must be destroyed when not used anymore to cleanup native resources and currently I see nodes being removed, but it seems like they get re-used and mounted again, which is not possible for OpenTUI nodes after they've been destroyed. Should I use a weak map for the nodes and try to let them clean up automatically? We have a bunch of other issues and I feel like we are making some wrong assumptions as the renderer complexity just grows and grows.
1 Reply
mdynnl
mdynnl2d ago
AFAICT no, solid doesn't re-use nodes but removing and remounting of nodes can happen during rendering. for dom renderer, replaceChild does it for universal, https://github.com/ryansolid/dom-expressions/blob/cf497eac6e8232d2b3223093f79b73fa7c5bf9a1/packages/dom-expressions/src/universal.js#L210-L213 same behavior is implemented
function replaceNode(parent, newNode, oldNode) {
insertNode(parent, newNode, oldNode);
removeNode(parent, oldNode);
}
function replaceNode(parent, newNode, oldNode) {
insertNode(parent, newNode, oldNode);
removeNode(parent, oldNode);
}
it looks like you're cleaning up right directly in removeNode then, the next time it's re-added, now have to revive the node or make a new one. or add a better mechanism for GC, which weakmap approach as you said is also an option

Did you find this page helpful?