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 for passing classname
to the DOM in WebComponents created with Html2React
#741
Conversation
🦋 Changeset detectedLatest commit: 41a3fc4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
classname
to the DOM in WebComponents created with Html2React
ESLint Summary View Full Report
Report generated by eslint-plus-action |
Codecov Report
|
@DAreRodz I've realized that using |
I've proposed another approach here: #742 (comment) |
module.exports = rootConfig; | ||
module.exports = { | ||
...rootConfig, | ||
snapshotSerializers: ["@emotion/jest/serializer"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added https://emotion.sh/docs/@emotion/jest to improve jest snapshots.
packages/html2react/src/libraries/__tests__/__snapshots__/component.tests.tsx.snap
Show resolved
Hide resolved
I've posted it in the #742 but here again for completeness. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolutely right.
What about using a <Wrapper>
, like Mateusz explained here: emotion-js/emotion#1071 (comment)?
I have done a quick test and I think it can work: https://www.loom.com/share/3b38039890a2499297959026a2ef9b9e
This is the code of the Wrapper
:
const Wrapper = ({ Component, children, className, ...props }) => {
return (
<Component {...props} class={className}>
{children}
</Component>
);
};
if (
typeof node.component === "string" &&
isCustomComponent(node.component, node.props)
) {
return (
<Wrapper
key={index}
css={node.props.css}
Component={node.component}
{...node.props}
>
{node.children ? handleNodes({ nodes: node.children, ...payload }) : null}
</Wrapper>
);
}
Also, could you please add more props and children to the tests? That way we can make sure that either solution you finally choose (Wrapper
or ClassNames
) will correctly pass down any props and children to the custom component.
I'm going to approve this now so you can merge it once it's done and continue your work with the AMP processors 🙂👍
ESLint Summary View Full Report
Report generated by eslint-plus-action |
OK, awesome. Thanks for the tip about the I've added some extra tests to check for passing children, passing other props and handling nested custom components like you suggested. I've also realized that we have another small bug in the Will merge this now 🙂 |
Awesome. Great work Michal! 👏😄 |
What:
Fix the issue where adding
style
on a custom component likeamp-img
causes passing ofclassName
property to the DOM.Why:
To fix #742
How:
I think we can change it by updating the
parse
function in@frontity/html2react
to check if the current node is a custom component.Tasks:
Unrelated Tasks
Additional Comments