-
Notifications
You must be signed in to change notification settings - Fork 262
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
Conversation
JSXStyle
return a noop if the registry context is not providedJSXStyle
return a noop if the registry context is not provided
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.
Thanks! 🚀
🎉 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 |
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.
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?
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.
this is what we have for test environments https://github.com/vercel/styled-jsx/blob/master/src/babel-test.js
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.
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.
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.