qwik icon indicating copy to clipboard operation
qwik copied to clipboard

Runtime dependency

Open klemenoslaj opened this issue 3 years ago • 2 comments

Is your feature request related to a problem?

In a highly configurable environments we would need a dynamic way to tell Qwik where to import a component from. Potentially by providing an import string or better yet a URL to the required component.

Describe the solution you'd like

component$(async ({ name }) => {
  const config = await fetch('/config');
  const Component = await fetchComponent(config[name].url);

  return <Component />;
});

Describe alternatives you've considered

Instead of runtime dependency we could declare a map of import promises and use that. However that would require a rebuild and redeploy.

Additional context

I guess what I am wondering here is if something similar to Module Federation would be possible directly from Qwik.

klemenoslaj avatar Jul 27 '22 11:07 klemenoslaj

I like the idea 👍 Just about this line:

I guess what I am wondering here is if something similar to Module Federation would be possible directly from Qwik.

Qwik has containers which is similar to micro frontends. link to the docs: https://qwik.builder.io/docs/advanced/containers/#what-do-containers-solve quick intro by @manucorporat : https://www.youtube.com/watch?v=Mi7udzhcCDQ&t=1753s

zanettin avatar Oct 30 '22 19:10 zanettin

I like the idea 👍 Just about this line:

I guess what I am wondering here is if something similar to Module Federation would be possible directly from Qwik.

Qwik has containers which is similar to micro frontends. link to the docs: https://qwik.builder.io/docs/advanced/containers/#what-do-containers-solve quick intro by @manucorporat : https://www.youtube.com/watch?v=Mi7udzhcCDQ&t=1753s

Yes I saw the containers section in docs, but had no time to decipher yet how to include containers into another container.

Module federation can be powerful because the federated apps can be configured at runtime - (e.g. configuration that does not live in code), which provides a great deal of flexibility. Is that possible with containers in qwik?

klemenoslaj avatar Oct 31 '22 11:10 klemenoslaj

I haven't worked with containers so far, so i can't tell you if they are nestable or not. but i just found a vite based method to enable module federation: https://github.com/originjs/vite-plugin-federation. maybe that would be something to dive into.

zanettin avatar Nov 24 '22 22:11 zanettin

I haven't worked with containers so far, so i can't tell you if they are nestable or not. but i just found a vite based method to enable module federation: https://github.com/originjs/vite-plugin-federation. maybe that would be something to dive into.

Yes, there are good alternatives to Webpack reference implementation, here is another one:

I was just thinking if the same thing could be achieved by Qwik out of the box. I'd try to migrate some larger projects in this case.

klemenoslaj avatar Nov 25 '22 11:11 klemenoslaj

Hi @klemenoslaj did you find a solution for this issue? can we close it?

gioboa avatar Dec 29 '23 10:12 gioboa

Hi @gioboa, no, sadly I haven't found a way in my limited exposure and didn't return to it ever since. If there is a way feel free to point me to it and I'll document it with a comment and close the issue myself.

klemenoslaj avatar Dec 29 '23 21:12 klemenoslaj

Hi @gioboa, no, sadly I haven't found a way in my limited exposure and didn't return to it ever since. If there is a way feel free to point me to it and I'll document it with a comment and close the issue myself.

I found this example created by the amazing @PatrickJS and it's exactly what you are asking for.

gioboa avatar Dec 31 '23 13:12 gioboa

yeah what I have there is the solution of dynamically grab any component at runtime (the method I posted in that stackblitz is just like how webpack module federation works). we ideally want to make it easier in qwik. @klemenoslaj feel free to message me in the qwik discord and I can help you set it up so we can close this issue

I'm also working on example repo for these patterns https://github.com/PatrickJS/experiments-qwik-runtime-components/tree/main

PatrickJS avatar Dec 31 '23 20:12 PatrickJS

Thanks @PatrickJS 👏 @klemenoslaj I'm closing this issue for now, feel free to re-open it if it's still an issue for you.

gioboa avatar Jan 01 '24 16:01 gioboa