-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
expose __unsafe_useEmotionCache from @emotion/react #2441
expose __unsafe_useEmotionCache from @emotion/react #2441
Conversation
🦋 Changeset detectedLatest commit: ac6b36b 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 |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ac6b36b:
|
packages/react/src/index.js
Outdated
export { | ||
withEmotionCache, | ||
CacheProvider, | ||
useEmotionCacheContext | ||
} from './context' |
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 naming here feels a bit strange:
- Why do we have
CacheProvider
not mentioning "emotion" butwithEmotionCache
does? - Why do we have
withEmotionCache
not mentioning "context" butuseEmotionCacheContext
does?
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.
Agreed 😞 I'm stupid for putting 'Context'
,
However withEmotionCache
and CacheProvider
were named this way already. It's in the diff only because prettier rearranged the statement because it was becoming too long for a single line.
I assume it is out of the question to introduce breaking change for fixing name inconsistency.
That in mind what would you see as a better name for the hook?
useCache
oruseEmotionCache
I personally prefer useEmotionCache
, it is more consistent with withEmotionCache
with which it shares the same goal of providing access to the cache.
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 have rebased to export useEmotionCache
instead of useEmotionCacheContext
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.
Ok, in any case, I'm not a maintainer of this GitHub repository
208ffa0
to
772ba3f
Compare
It would be a goodness if this could be merged! |
@mitchellhamilton what are your thoughts about this? It definitely shouldn't be encouraged to use this because there are not a lot of use cases this allows and they are mainly related to generating string class names that break 0-config SSR. OTOH, it's already possible to get access to the cache leveraging the public |
772ba3f
to
4a1aa67
Compare
Hi @Andarist, |
packages/react/src/context.js
Outdated
export let __unsafe_useEmotionCache = | ||
function __unsafe_useEmotionCache(): EmotionCache | null { | ||
return useContext(EmotionCacheContext) | ||
} | ||
|
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.
export let __unsafe_useEmotionCache = | |
function __unsafe_useEmotionCache(): EmotionCache | null { | |
return useContext(EmotionCacheContext) | |
} | |
export function __unsafe_useEmotionCache(): EmotionCache | null { | |
return useContext(EmotionCacheContext) | |
} | |
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.
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 wouldn't really bother about the existing convention here. The main reason why withEmotionCache
is defined like that is because of the fact that it might be reassigned a few lines below - this doesn't apply to the __unsafe_useEmotionCache
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.
4a1aa67
to
ae143e2
Compare
No problem, I will still wait on @mitchellhamilton's opinion though, before moving this forward. |
I'm fine with exposing this as |
Seeing this export make me think about something else related to emotion's cache & React context.
Would it make sense to reexport the API of the packages that |
@Andarist Is there any remaining blocking for this PR to be merged? |
Sorry for not handling this yet. Gonna go through all pending PRs tomorrow and ship a new version |
Don't feel embarrassed! I do not so hurry for that issue to be resolved. Thanks for all of your work! |
No need to apologize, I can't imagine the amount of work required to maintain a project as widely used as emotion.
Thanks for your understanding 😊 You are welcome. |
Thank you 😊 |
Since the use of this feature is discouraged if not for interoperability, I doubt @Andarist will be encline to let the type definitions be added for it. But maybe I'm wrong? |
Sounds good, thank you for the advice! |
What:
Expose
__unsafe_useEmotionCache()
from@emotion/react
Why:
Needed for seamless integration of tss-react with
@emotion/react
.tss-react will be the new
makeStyles
in@material-ui
v5.How:
I exposed a proxy to
useContext(EmotionCacheContext)
Checklist:
Hi @Andarist,
I implemented
makeStyles
on top of@emotion/react
as you discussed with @oliviertassinari.It's tss-react.
In v5 of material-ui
makeStyle
will be dropped and tss-react will be mentioned in the v4 to v5 migration guide for the teams that don't want to make the switch to the styled API.It would be great if I could have access to the cache,
tss-react
have just been released and it has already been requested that it supports custom cache.Of course I could expose my own provider but it would be much better if
tss-react
could blend in transparently with@emotion/react
.