Skip to content
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

fix: fix web-component tag name transform issue #1318

Merged

Conversation

rqzheng2015
Copy link
Contributor

Description

Fix the web-component tag issue mentioned in #1303

Issue Reason

The babel transform will automatically identify the "-" as an operator, and add a space before and after it.
So when it met a tag name such as swiper-container provided by web-components, it will transform the tag name as swiper - container.

How to Fix

We need to replace ' - ' with '-' in the babel transformed code to fix this issue.

Copy link

vercel bot commented Dec 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mitosis-fiddle ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 4, 2024 6:41am

Copy link

nx-cloud bot commented Dec 11, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 3d812d5. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 4 targets

Sent with 💌 from NxCloud.

// For exmaple: we pass a tag called "swiper-container", and it will be renamed as "swiper - container" after babel transforming,
// because babel will automatically identify the "-" as an operator, and add a space before and after it.
// So we need to replace ' - ' with '-' to fix this issue.
return babelTransform({ code, visitor, stripTypes })?.code?.replace(' - ', '-') || '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution is too extreme/broad: it will replace every single occurrence of - with - across every code block evaluated by the Mitosis compiler. That includes all props, state, event handlers, etc. This means that even comments inside functions will be transformed by this change.

I don't mind having a .replace() approach, but it would need to be localized to only the JSX tag name.

Copy link
Contributor

@samijaber samijaber Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • If you run yarns snapupdate in mitosis/core, you will see how much this code change impacts generated code.
  • you also need to yarn run fmt:prettier to lint this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks @samijaber. I will soon submit a new patch for this PR.

@samijaber
Copy link
Contributor

I just commented a better solution to this problem here: #1303 (comment)

Thanks a lot for taking this on!

@rqzheng2015
Copy link
Contributor Author

Hi @samijaber, I have commited new changes based on your advices, and have added snapshot and unit test. Please hava a look when you have time.

@rqzheng2015
Copy link
Contributor Author

Hi @samijaber! Please check the pr if you have the free time, thanks.

Copy link

nx-cloud bot commented Jan 2, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit f4b2c92. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 4 targets

Sent with 💌 from NxCloud.

Copy link
Contributor

@samijaber samijaber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful fix. Well done. Thanks for the contribution! 🎉

@samijaber samijaber merged commit 603c2ff into BuilderIO:main Jan 4, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants