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: Make JSXStyle return a noop if the registry context is not provided #749

Merged
merged 1 commit into from
Sep 15, 2021

Conversation

shuding
Copy link
Member

@shuding shuding commented Sep 15, 2021

It is possible to (fully or partially) render a component without the context. One legit use case is to generate and parse the markup without rendering it in the browser (so no registry is needed). In those cases we can simply ignore all JSXStyle elements.

@shuding shuding requested a review from giuseppeg as a code owner September 15, 2021 12:56
@shuding shuding changed the title Make JSXStyle return a noop if the registry context is not provided fix: Make JSXStyle return a noop if the registry context is not provided Sep 15, 2021
Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

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

Thanks! 🚀

@timneutkens timneutkens merged commit e5c3842 into vercel:beta Sep 15, 2021
@shuding shuding deleted the noop-jsx-style branch September 15, 2021 13:08
@github-actions
Copy link

🎉 This PR is included in version 5.0.0-beta.2 🎉

The release is available on:

Your semantic-release bot 📦🚀


// If `registry` does not exist, we do nothing here.
if (!registry) {
return null
Copy link
Collaborator

Choose a reason for hiding this comment

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

The following is just an observation and me asking out of curiosity, not a big deal:

Normally I throw an error here to help users understand what's going on. In the case you described in the PR description can't you remove the babel plugin altogether so that style tags are not turned into JSXStyle elements?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

In certain use cases, for example a lib that renders a component (which has styled-jsx inside) with renderToStaticMarkup. We can't throw since it should not block rendering, and we can't ask them to disable the babel plugin as well because it's not a project level thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants