GithubHelp home page GithubHelp logo

Comments (12)

sheepsteak avatar sheepsteak commented on May 30, 2024 3

I think this may be because react-router also uses broadcasts via react-broadcast and there is a clash as both put broadcasts onto the context. I think the fix above is just papering over the cracks.

Maybe it would be better to remove the broadcast stuff in this module and depend on react-broadcast instead? The code is very similar and there would be no overwriting happening on the context.

from styled-components.

madeinfree avatar madeinfree commented on May 30, 2024

I got the same error.
I found this issue happened StyledComponent.js#L44, it can get the this.context but didn't have __styled-components__, I try to fixed this line become

const subscribe = this.context.broadcasts[CHANNEL]
  this.unsubscribe = subscribe && subscribe(theme => {
  // This will be called once immediately
  this.setState({ theme })
})

it works fine

from styled-components.

mxstbr avatar mxstbr commented on May 30, 2024

Interesting, @madeinfree would you mind submitting a PR with this change? Then I can take a look if that fixes the issue once and for all! Thanks!

from styled-components.

madeinfree avatar madeinfree commented on May 30, 2024

@mxstbr no problem ~

from styled-components.

mxstbr avatar mxstbr commented on May 30, 2024

I think this may be because react-router also uses broadcasts via react-broadcast and there is a clash as both put broadcasts onto the context. I think the fix above is just papering over the cracks.

Interesting theory. We could just not use the broadcast context property and use theme instead?

Maybe it would be better to remove the broadcast stuff in this module and depend on react-broadcast instead? The code is very similar and there would be no overwriting happening on the context.

The reason we don't do this (if you look at the PR I actually initially built it this way: #56) is that it would mean that every styled component is wrapped in two components instead of one, which has a non-negligible performance impact. I thought I integrated it properly so it doesn't matter if there's another broadcast happening, but obviously I was wrong.

from styled-components.

garmjs avatar garmjs commented on May 30, 2024

I'm getting the same error with react-router v4, i think i'm goin to use @madeinfree fix for now

from styled-components.

mxstbr avatar mxstbr commented on May 30, 2024

Can replicate – working on a fix now! 🔥

from styled-components.

mxstbr avatar mxstbr commented on May 30, 2024

Could you try out #86 in your project and report back if it fixes the issue? It did for me in a simple test, but I want to make 100% sure!

from styled-components.

madeinfree avatar madeinfree commented on May 30, 2024

I can try ~~ 👍🏻

from styled-components.

gbozee avatar gbozee commented on May 30, 2024

Just tested the PR #86 . Issue resolved. 👍

from styled-components.

mxstbr avatar mxstbr commented on May 30, 2024

Awesomeee, thanks!

from styled-components.

mxstbr avatar mxstbr commented on May 30, 2024

Released as 1.0.4 – thanks for reporting and testing this everyone!

from styled-components.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.