-
Notifications
You must be signed in to change notification settings - Fork 558
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
Support for custom components in mitosis compiler #1303
Comments
There are two things that need to be done:
input: export default function MyComponent(props) {
return (
<my-custom-div></my-custom-div>
);
} JSON output: {
"@type": "@builder.io/mitosis/component",
"imports": [],
"exports": {},
"inputs": [],
"meta": {},
"refs": {},
"state": {},
"children": [
{
"@type": "@builder.io/mitosis/node",
"name": "my - custom - div",
"meta": {},
"scope": {},
"properties": {},
"bindings": {},
"children": []
}
],
"context": {
"get": {},
"set": {}
},
"subComponents": [],
"name": "MyComponent",
"hooks": {
"onMount": [],
"onEvent": []
}
} This is where we grab the name from the parsed AST:
I am unable to see how this introduces spaces in the dash. There might be something else running a transformation on the Best bet to find the solution for this:
If you are able to take a stab at this, that would be amazing! Otherwise, I will try to whenever I have the time to dedicate to this issue. |
Hi @samijaber, I have figured out how to support the Tag name issueThe web component tag name has extra spaces after mitosis transforming, for example. ReasonI dig in the code, and found out the tag add wrong spaces after FixWe could remove the unnecessary spaces at |
Type issueAlso, another issue mentiond above, the type issue of This is a sample code to allow user to use declare namespace JSX {
interface IntrinsicElements {
'swiper-container': any,
'swiper-slide': any,
}
export default function Swiper(){
return <swiper-container slides-per-view="3" speed="500" loop="true" css-mode="true">
<swiper-slide>Slide 1</swiper-slide>
<swiper-slide>Slide 2</swiper-slide>
<swiper-slide>Slide 3</swiper-slide>
</swiper-container>
} Further details about |
Tag name issue: @rqzheng2015 that's awesome, thanks for investigating! I saw your fix to const result = `node.name.contains('-') ? node.name : codeProcessor('dynamic-jsx-elements', json)(node.name, ''); That's because we only want that Type issue Oh, this is actually already possible! You can extend the runtime by putting this in a declare module '@builder.io/mitosis/jsx-runtime' {
declare namespace JSX {
interface IntrinsicElements {
'swiper-container': any;
'swiper-slide': any;
}
}
} We should document it somewhere for clarity. 🤔 |
Thanks @samijaber! And I'm gonnna test the new solution you provided asap. |
Hi @samijaber . I've changed the code in // plugins/process-code/index.ts
const result = node.name.includes('-')
? node.name
: codeProcessor('dynamic-jsx-elements', json)(node.name, ''); But now, I met another issue when I set the targets to |
Hi @samijaber, one more question, to fix type issue, I have added the ts definition like you said above. declare module '@builder.io/mitosis/jsx-runtime' {
namespace JSX {
interface IntrinsicElements {
'swiper-container': any;
'swiper-slide': any;
}
}
} But now I am facing two issues, playground can be seen here:
|
@rqzheng2015 for the types issue: what youre showing is a playground-only issue. Mitosis component files You should add the |
@rqzheng2015 thanks for digging further into this. |
Thanks, I will fix this soon. |
Hi @samijaber, I have fixed the issue. Please check the PR here, thanks. #1318 |
I am interested in helping provide a feature!
Yes
Which generators are impacted?
What problem does this feature solve?
The feature aims to enable Mitosis compiler, to effectively handle custom components. Currently, the compiler struggles for example with lower-cased component names containing dashes, leading to issues during compilation.
Here is an example of the compilation error
What does the proposed API look like?
The proposed API enhancements would involve refining the JSX parser within Mitosis to appropriately recognize and handle custom components. This improvement would ensure that when encountered, these components are preserved as-is in the generated output without undergoing any alterations by the Mitosis compiler.
The API might involve modifications or additions to the parsing logic to accurately identify and handle these custom components during compilation.
Additional Information
No response
The text was updated successfully, but these errors were encountered: