[AskJS] WebComponents and version management
Consider this scenario fellow redditors:
My application uses two React Components, ListOfSheep and ListOfCows which both have a dependency on ListOfAnimals. Though, due to evolving requirements, ListOfSheep requires ListOfAnimals 1.2 and ListOfCows requires LitsOfAnimals 2.1 - which is a breaking change!
While it would be ideal to not use two different versions of the same components, it is also no biggie: no matter which package manager I use, this case is handled - each component can require the version they need, and this scenario doesn't cause any problems. Maintainers of Cow module can bump their version to suit their needs, without worrying about breaking Sheep module code and the whole case ends with an email note to the other team "hey, maybe you should bump your version of ListOfAnimals, it is quite old".
Now, the same scenario usig WebComponets ends with one of the modules (the one loading later) throwing exception
Failed to execute 'define' on 'CustomElementRegistry': the name "list-of-animals" has already been used with this registry
that you can't really even recover from.
For those unfamiliar with CustomElements, they need to be registered with a global name. Yes.
Does anyone here have some experience working with WebComponents at at least moderate scale (i.e. application large enough to be maintained by largely separate teams that enjoy (and often need) working as independently as possible) and maybe has some tips how to handle such scenario in app using WebComponents?
I'm also interested in your opinions about WebComponents standard - I can hardly believe that the standard that is supposed to be "the future" is implemeted in a way that basically requires you to use global variables (or rather global names, but well, same problems). Is the standard really poorly thought out, or am I missing something?
It seems silly to me that a case that is basically a non-issue when using React is such a PITA when using WebComponents.
8 comments · 86% upvoted · other discussions
Not discussing whether or not having several versions of the same component is good or bad: https://github.com/w3c/webcomponents/issues/716 this is what you're looking for, although as you can see it's still only a proposal
At the moment you have to make sure everyone uses the same version of the comp or introduce an "always backward compatible" policy within your org and force everyone on latest
Src: worked in large scale orgs with web components for a few years