[✨] Expose a function to render a JSXNode into an element in memory #258
Replies: 11 comments
-
|
I am not sure I follow, @DustinJSilk. Creating an HTML element would not benefit from any reactivity, as far as I see. Perhaps you are missing something like That way, instead of creating an HTML element from JSX, you can simply reference any element already rendered. Please take a look at the hook In any case, I also found this: QwikDev/qwik#1100 |
Beta Was this translation helpful? Give feedback.
-
|
Hey @phcoliveira! Thanks for taking the time to have a think about this! 🙂 Im not looking to capture a reference to an element in the DOM, which using a ref works just fine for, im wanting to turn a JSXNode into an HTML element. I also dont need to benefit from reactivity, i need to create HTML elements and pass them into a library like Mapbox. Unfortunately, referencing an element from the DOM wont work either, as the element gets moved by Mapbox, which breaks Qwiks. I've solved the problem by manually building the element with native JavaScript. Its not difficult, its just a poor DX which other libraries have a solution to. Hope that helps to clear things up a little! |
Beta Was this translation helpful? Give feedback.
-
|
Sure, @DustinJSilk. Although I think I understood your argument, I am not sure there is a viable solution to it. https://bundlephobia.com/package/[email protected] And I am only considering the package size. Unfortunately I am not able to tell if this library can actually run in the browser of if it requires some features from Node or another runtime like Demo or Bun. |
Beta Was this translation helpful? Give feedback.
-
|
Qwik builds elements on the frontend when ever it rerenders, so this is possible. |
Beta Was this translation helpful? Give feedback.
-
|
So sorry, @DustinJSilk, the library only weights 146 B. Somehow I confused it with 146 KB. |
Beta Was this translation helpful? Give feedback.
-
|
if QwikDev/qwik#3758 is solved, you can use |
Beta Was this translation helpful? Give feedback.
-
|
Ooo that looks right, thanks for pointing it out @revintec ! Hopefully it gets fixed soon |
Beta Was this translation helpful? Give feedback.
-
yes please! We need this badly! |
Beta Was this translation helpful? Give feedback.
-
|
Adding another example of why this is needed: When using Leaflet, let's say we want to show a qwik element inside a leaflet popup. If we take qwik's own example in qwik/starters/features/leaflet-map/src/components/leaflet-map/index.tsx:55: We would like to have something like this: Well of course that's not working, Leaflet is crying that it In React we could solve that by rendering to string, like so: So one would think that we can use qwik's renderToString in a similar way: However this fails currently (qwik v1.3.1) with |
Beta Was this translation helpful? Give feedback.
-
|
I forgot to mention the workaround, can be of value to OP. That's how we can achieve it currently with qwik: |
Beta Was this translation helpful? Give feedback.
-
|
We moved this issue to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem?
To attach an element to external libraries like mapbox, we need to create html elements in memory.
Currently, we have to create the element using native JavaScript functions.
To improve DX, it would be great to be able to import a Qwik component and to render it into an HTML element.
This means the element can be used standalone in Playwright, Vitest, Storybook and in an app, as well as dynamically rendered into external libraries.
Describe the solution you'd like
A function with a potential signature
createElement(node: JSX.Element). We can then do this:Describe alternatives you've considered
Manually creating elements in JavaScript, which sucks
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions