BUG: Mitosis does not camelCase HTML attributes in React
See original GitHub issueScope
- This impacts ALL Mitosis outputs
- This only impacts specific generators/outputs (please list them here): React
Describe the bug
Attributes like srcset
are camelCased in React (possibly other frameworks? Not sure). However, Mitosis does not account for that
To Reproduce
A link to a https://mitosis.builder.io/ fiddle containing the bug: link
Expected behavior
scrset
should become srcSet
in the React output. Same goes for all HTML attributes that are multi-word: https://reactjs.org/docs/dom-elements.html
Additional context
- I am not sure what the comprehensive list of camelCased DOM elements is, but we can probably look at React’s JSX types to determine what to do
- I am also not sure if other frameworks do this camelCasing. We might need to do this elsewhere too
Issue Analytics
- State:
- Created a year ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Why does my camelCase attributes work well with TypeScript ...
Okay I found the problem, it's coming from Styled Components, which puts the props on the generated HTML:
Read more >Intercepting the case battle between snakes and camels in ...
Yes, you got the issue. The naming style in JSON data has been changed from camelCase to snake_case. Assuming this naming style change...
Read more >Content - 3811e52cdfcda707d47b0ed2f8fb560e94e67923
Previously this would not fallback to default content: ```html ... <a name="1.5.3"></a> # 1.5.3 diplohaplontic-meiosis (2016-03-25) ## Bug Fixes ...
Read more >page> < - Massachusetts Institute of Technology
<ref>[http://www.mutualist.org/id112.html]</ref> ... The tradition is a form of [[philosophical anarchism]], which does not recommend any ...
Read more >Untitled
JPG https://www.geeksforgeeks.org/html-interview-questions-answers-set-1/ ... -from-the-given-array-such-that-their-sum-is-not-present-in-any-of-the-arrays/ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
super interesting that solidjs supports both. I personally like that approach if it’s not a logistical headache on the implementation side
my main suggesting is just avoiding hardcoded lists of element tags/properties however possible. all frameworks need to do that for JSX types, but I’ve never seen it be built into the frameworks itself and affecting logic in these types of ways. I think the main reason why is it’s ok if a type is wrong or incomplete (you can override it locally or use
any
), but it’s not ok if a framework makes a wrong assumption internallyso types can be seen as a nice to have (that you can override/augment), but framework logic you can’t override and needs to support more than just what is in the HTML spec today (including custom elements, custom attributes, etc) in a predictable way
I hadn’t realized we wanted to match React more closely than the other ones. Thanks for the context
No concern, we could do it one way or the other! My thinking was that since every non-React framework I looked at sticks with the original syntax (Solid supports both
srcSet
andsrcset
btw), it’d be good to stick with the native casing as React is the odd one out (do a transformation in 1 generator vs in all-but-1)Worth noting that either way, we’ll have to manually add every new HTML tag & attribute to our JSX type, so we are constantly maintaining a mirror of the HTML spec regardless. I’d rather stick with the list that’s already hardcoded for this issue, and I can go in and replace it with a
isFirstLetterLowerCase(json.name)
check in a follow-up PR if we feel strongly about this.New Approach
@shubham-y , hold off on working on this temporarily, I’ll add a comment later with details about the new approach we want to take to address this.