-
Notifications
You must be signed in to change notification settings - Fork 818
feat: tag transform #6211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: tag transform #6211
Conversation
|
Hi @johnjenkins, would these changes extend to the framework adapters OOTB/'as is', or would that require additional changes in the output-targets repo? We're running a React MFE architecture and would really benefit from being able to transform the tags at runtime to avoid version registration clashes between feature teams running different versions of the stencil component lib - just wondering whether these changes could facilitate that in future. Thanks! |
|
hey @elliottdaviesss - Thanks for the interest! Yes, it would involve some tweaks in the output adapters (wrapping On reflection, idk if what i've done here is the best approach; @Cliffback has came up with a slightly different strategy which you can use at https://github.com/Cliffback/stencil-custom-suffix-output-target (doesn't work with react output atm I think). |
@johnjenkins I could give transforming the other output targets the same way, so that it would work with react as well? My main focus has been on angular so far, as that is what we need at work, but would be nice to expand it now that it is on npm regardless |
|
@Cliffback - I decided to roll your work into this, tysm ❤️ |
That's amazing to hear! Really happy that it has been of use! 🤩 |
|
@johnjenkins btw. do you do anything with the Without this patch, all emitters lost their type and would have to be set to it turns: interface HTMLElementTagNameMap {
"my-component-one": HTMLMyComponentOneElement;
"my-component-two": HTMLMyComponentTwoElement;
}into: interface HTMLElementTagNameMap {
"my-component-one": HTMLMyComponentOneElement;
[key: \`my-component-one--\${string}\`]: HTMLMyComponentOneElement;
"my-component-two": HTMLMyComponentTwoElement;
[key: \`my-component-two--\${string}\`]: HTMLMyComponentTwoElement;
}This made it necessary to differentiate the postfix from the tagname with All in all, I think this differentation also is a good thing, as it separates more clearly the acutal tagname from the transformed one. Any thoughts on this? |
I think it's neat @Cliffback ... idk how it would work with what I have done though seeing as I make no assumptions at either
I can't see a way to get the run-time's tagTransformer result into a useable ts template literal type. In reality, I think this would mainly affect 'vanilla' consuming applications(?) as JS-framework consumers when using wrappers continue to be typed correctly no-matter the transformer used. Perhaps there would still be a need for a custom output target for those that need it :) |
Yes, that makes a lot of sense, especially given that my output targets main purpose has been getting it to work with angular (and that's were the emitter type issue arose). However the element map patch is non-destructive, it just adds support for tagnames having a postfix as well, as long as it is distinguished with a However for this to work with your solution, enforcement of Regardless, when this is released, I'll see how much of our setup could be migrated, and a way to solve the rest could be to change Eagerly looking forward to this getting merged! 🤩 |
Scoped custom element registries support is currently tiny.
As a WC compiler Stencil has an opportunity to offer devs first-class workarounds until there is greater Scoped custom element registries support.
What is the current behavior?
importing and registrering
@my/wc-components/my-componentv1 and@my/wc-components/my-componentv2 will error unless they have a different tag name. A global custom element registry means only one class CTOR can be registered per tag-name.GitHub Issue Number:
What is the new behavior?
2 new core functions -
setTagTransformerandtagTransform- have been made available which will work across all Stencil outputs.Examples
dist
Within your lib's
src/index.ts:Within any relevant consuming project html file:
dist-custom-elements
Within your lib's
src/index.ts:Within any relevant consuming project:
dist-hydrate-script
Within any relevant consuming project server handler:
Additional tag transformers
Any component lib that chooses to expose
setTagTransformerwill need to adjust their codebase; wrapping any potentially affected tags intagTransform(...)(or in css, avoiding using tag names altogether!)For example:
additionalTagTransformersto the rescue (special thanks to @Cliffback !)Setting a new config option:
Will additionally transform all css selectors and
querySelectors(and more) within your component's code base:CSS:
Query selectors:
Documentation
TODO
Does this introduce a breaking change?
Testing
TODO
Other information