S
SolidJS10mo ago
FF

Behavior of "Portal" component

Is it possible to use the "Portal" component, so that it won't create additional wrapper (div) around?
10 Replies
bigmistqke
bigmistqke10mo ago
I don't think so
bigmistqke
bigmistqke10mo ago
SolidJS
Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.
Jasi
Jasi10mo ago
@bigmistqke are you sure? thinkies I don't see how prevent rendering an additional div here oh do you just pass isSVG? okay no this doesn't work
bigmistqke
bigmistqke10mo ago
i didn't try it out tbh 😅
Jasi
Jasi10mo ago
yea it doesn't work xD
bigmistqke
bigmistqke10mo ago
it was my intuition that mount would do the trick, since then you given it a container element to render in, but that does not seem to be the case 🤷‍♂️
FF
FF10mo ago
@core-team cc. As I understand that wrapper exists only for the sake of reactive scope, but in some situations is very annoying to have this extra div. Plus we have additional node.
ryansolid
ryansolid10mo ago
It's there mostly for event delegation. It's easier to have a parent element to catch the event and forward it up when you can insert multiple children elements in the portal. If we used the mount element as delegate then you couldn't attach more than one portal to the same element. I've been trying to think of ways to avoid this. Like maybe setting properties on the mount element that are specific to each portal. Like a unique id, but like following a pattern that the event delegation logic can follow. Also having no siblings makes things a lot simpler for addition removal as we don't need to diff the whole range.
FF
FF9mo ago
Thanks for the explanation! I think I found a solution for this problem, but it's not very efficient from a "solid-js" perspective (I think). Glad to be wrong if so. https://playground.solidjs.com/anonymous/fe29c6ef-8b4c-4656-ac41-c77249a37fdc
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
FF
FF9mo ago
And if so, wouldn't it be a good idea to add an extra prop to the "Portal" component so that the user can control whether a wrapper is needed or not.
Want results from more Discord servers?
Add your server