S
SolidJS2mo ago
MikeM42

createRoot with libraries?

I have a very strange behaviour that I can't really explain. I've been building a library in which is a plugin to the rete (retejs.org) library, as part of this I have to manage component lifecycle for which I use createRoot. The strange thing is, that createRoot prevents Components from inside the library to trigger "computation created outside a 'createRoot'..." but it doesn't prevent the same if I create a child component outside the library in main code. So if I have something like the following that gets created under a createRoot call:
<div>
<Component1/> # From library
<Component2/> # Not from library
<div>
<div>
<Component1/> # From library
<Component2/> # Not from library
<div>
Then Component2 creation triggers the "computation..." issue. If I put all of the library code inside of the same app (so its not a library anymore), then everything works without triggering the error, but if I build the library and then use it, I trigger the issue. The issue can be found in this example https://github.com/mmoerman/solid-rete-plugin-examples, under the example "Example With Button Control". The library for the rete plugin is here: https://github.com/mmoerman/solid-rete-plugin I feel that this is somehow related to how Javascript handles library contexts, but don't have enough experience with Javascript to figure out what the issue might be and how to solve it.
GitHub
GitHub - mmoerman/solid-rete-plugin: A SolidJS plugin for Rete (htt...
A SolidJS plugin for Rete (https://retejs.org/). Contribute to mmoerman/solid-rete-plugin development by creating an account on GitHub.
3 Replies
bigmistqke
bigmistqke2mo ago
I think ur bundling solid in ur lib Make solid-js a peer-dependency and add it to external in the vite.config.ts
bigmistqke
bigmistqke2mo ago
I like https://github.com/solidjs-community/solid-lib-starter this starter, but it's with tsup
GitHub
GitHub - solidjs-community/solid-lib-starter: SolidJS library start...
SolidJS library starter template. Use it to create your own solid package. - solidjs-community/solid-lib-starter
MikeM42
MikeM42OP5w ago
I was bundling it but through my trials I ended up making it a peer, however still experiencing same issue. But I'll dig a little deeper. The rete bundler for plugins is rollup with a weird client of theirs, I am not sure it is a critical piece of the puzzle, so I am going to give it a try making the lib with vite, I'ved had some experience with it so will keep you posted. Seems to be working with vite library bundling, so I am probably going to switch to that for now.

Did you find this page helpful?