How to keep reactivity when passing props
to a Solid component from a third party that's dynamically imported (as a plugin)?
#1751
-
I'm building a webapp that allows users to load 3rd party plugins. These plugins have access to the DOM. My project is in Solid, and for now let's assume all plugins are also in Solid. Loading Solid components as plugins works using const App: Component = () => {
const [count, setCount] = createSignal(0)
const [plugin] = createResource(async () => {
let encodedPlugin = await toModule<{
default: VoidComponent<{ i: number }>
}>(script) // function that converts an arbitrary string to a module
return encodedPlugin.default
})
return (
<div class={styles.App}>
<button onClick={() => setCount((x) => x + 1)}>Inc {count()}</button>
<Dynamic component={plugin()} i={count()} />
</div>
)
} However, the component is not updating when the prop changes. The exported component is a simple import { VoidComponent } from "solid-js"
const Comp: VoidComponent<{ i: number }> = (props) => {
return <h1>Hello world!!! {props.i} x</h1>
}
export default Comp |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The problem here is that the plugin is using it's own instance of solid, which breaks reactivity. You need to find a way to provide the same instance of solid to your app and to the plugins. The only way I can think of right now is to use external in the rollup options of vite: https://rollupjs.org/configuration-options/ |
Beta Was this translation helpful? Give feedback.
The problem here is that the plugin is using it's own instance of solid, which breaks reactivity.
You need to find a way to provide the same instance of solid to your app and to the plugins. The only way I can think of right now is to use external in the rollup options of vite: https://rollupjs.org/configuration-options/