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

Instance-based API instead of global singleton #64

Open
rtsao opened this issue Dec 30, 2016 · 6 comments
Open

Instance-based API instead of global singleton #64

rtsao opened this issue Dec 30, 2016 · 6 comments

Comments

@rtsao
Copy link

rtsao commented Dec 30, 2016

I think it would be nice if styled-jsx had a non-singleton interface.

The main use case I've found where a global singleton is problematic is related to rendering within iframes. In short, styles from components rendered within a iframe get rendered outside the iframe, preventing the styles from reaching inside the iframe.

The common pattern to solve this is to rely on React context to share instances, which allow the instance to be overridden within an iframe by overriding context. Then styles from components within a given iframe will be rendered within the iframe using its own instance.

This is somewhat uncommon use case, but creating a singleton interface from an instance is straightforward whereas going the reverse direction is much more difficult. I think making separate packages for the core and singleton interface would not add too much additional complexity or maintenance effort. I'd be happy to work on a PR, otherwise feel free to close this issue.

@rauchg
Copy link
Member

rauchg commented Jan 3, 2017

After we did an implementation example of Styletron with custom <Document> in next, @nkzawa and I both thought that your approach with the higher order component and context is probably the best one for server rendering stuff :)

@giuseppeg
Copy link
Collaborator

@rtsao would you like / have time to implement this?

@rtsao
Copy link
Author

rtsao commented May 19, 2017

@giuseppeg Someone else can jump on this as it looks like I probably won't be able to get to this anytime soon.

@giuseppeg
Copy link
Collaborator

We are going to tackle this in #389

@merrywhether
Copy link

Is this something with any internal momentum? Or is it something that a community member will probably have to tackle?

varl added a commit to dhis2/ui-core that referenced this issue May 6, 2019
Because of vercel/styled-jsx#64 styled-jsx needs
to be a peer dependency for all libraries, and pulled in once by the
App, so the instance can be shared.
varl added a commit to dhis2/ui-widgets that referenced this issue May 6, 2019
Because of vercel/styled-jsx#64 styled-jsx needs
to be a peer dependency for all libraries, and pulled in once by the
App, so the instance can be shared.

Related to: dhis2/ui-core#204
@giuseppeg giuseppeg added this to the v4 milestone Aug 8, 2019
@lifeiscontent
Copy link

@giuseppeg any update on this? I'm running into this issue and I'm trying to launch a UI kit with styled-jsx.

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