Theme isn't provided in a monorepo #3324
-
Hey guys, We're working on a few custom Flex plugins which have many things in common. So an obvious choice for us was to store plugins in a monorepo and have a shared package in the same monorepo for sharing a reusable code between the plugins. What we would like to eventually achieve is to have a library of shared components, including a wrapper around It turned out to be tricky to make it all work in a monorepo, and one of the issues that we faced was the inability to apply Twilio Paste theme to React components imported from a shared package. It seems that styles simply do not apply. Now I have a reproducible example in this repo: https://github.com/dmitriy-kudelko/flex-plugins. It is based on yarn workspaces. Basically the way it works is that we pre-bundle the shared package using Now a problem is that when we use a component locally defined in the Similarly if we import some shared component from the shared library to And the only combination when both types of components work is when we wrap them in both local and shared theme providers. So is Twilio Paste monorepo-ready? I would really appreciate if you can have a look and provide some help, as it's kinda a show stopper for us at the moment. This question is somehow similar to #1591. However it doesn't seem that any of the answers there are relevant. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi @dmitriy-kudelko, Theoretically, this should work just fine. I'm unable to to build your sample repo locally because of the hard dependency on Flex, however if you can provided a generic reproduction without that dependency I would be able to test it. It would also help us better determine if the issue is coming from Paste, the implementation, or the Flex plugin system - in your repo things are a little too coupled to figure that out easily. Another thing I'm thinking about looking at this, is when compilation/bundling should happen. It could be that because you're compiling things separately, by the time the final bundling is happening references are getting lost. Maybe you can ship the source and do bundling once at the final plugin level? That may make debugging what's happening at the end easier if you can peek at the source without minifaction. |
Beta Was this translation helpful? Give feedback.
-
Hi @TheSisb 👋 First of all thank you for the quick turnover! I've updated the example and instructions to include Storybook so that you're able to easily reproduce the issue. I also followed one of suggested solutions from the aforementioned thread - to alias dependencies in Webpack config, and it worked. The only issue is that it's seem to be more like a hack/patch. And I still don't have a good answer why this is happening in the first place. So if you uncomment this it magically starts working. Regarding bundling the code differently... Well, I've tried it either ways. But the thing is that the code which creates context is executed in the browser and not when we bundle the code. So in theory this shouldn't matter. |
Beta Was this translation helpful? Give feedback.
@SiTaggart , I think yes, it's mostly the context. I didn't notice any other issues.
No, not really. But it seems that it only happens with a context created by one of dependencies. If I define context in the shared library myself (or in the plugin A and try to access it from within a shared component), it works.
And AFAIU now, it's more related to the way Webpack resolves modules in monorepo, …