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

Contexts seem to break when there are multiple React instances (1 per package) #3532

Closed
Bockit opened this issue Mar 27, 2015 · 4 comments
Closed

Comments

@Bockit
Copy link

Bockit commented Mar 27, 2015

I realise contexts are basically undocumented and unsupported so this is shaky territory API wise.

I have a use-case for multiple node packages with their own React installed. Each package provides a Component or two using its own React instance, from its own node_modules folder. I'm finding when using contexts I get the message:

Warning: owner-based and parent-based contexts differ (values:undefinedvsbar) for key (message) while mounting Message (see: http://fb.me/react-context-by-parent)

When I try and pass contexts down to all the elements.

If I consolidate the Components into one package then everything works as expected. If I keep separate packages, but export a factory that takes the React instance as a function, everything works as expected. Browserify probably conveniently gets around this with the dedupe if they're all identical versions. Running on the server unfortunately does not.

Here's a code sample with everything in 1 package working fine. You'll need to run npm install from the project root directory and run node index.js.

Here's a code sample with the separate package and its own instance of React. You'll need to npm install from the project root directory and /node_modules/sub-component.

I have three questions:

  1. Is this expected behaviour for contexts, to depend on the React instance?
  2. I've seen people running into problems with multiple React instances in other issues. Is this something I should be avoiding?
  3. If it is something I should be avoiding, is it expected to remain this way for the short/medium/long term or forever?

Alternatively, am I using contexts incorrectly?

Thanks for your time, and a wonderful library.

@syranide
Copy link
Contributor

Running multiple instances of React is not currently supported. It's possible to work around that with some tweaks, but they still have to be isolated from each other, so you cannot use the instances interchangeably.

@sophiebits
Copy link
Collaborator

Yeah, unfortunately we don't support this right now. We'd like to but don't know how to do a good job of it. #3252 is our issue tracking that.

@mridgway
Copy link
Contributor

This is especially an issue with npm link with packages that also depend on React. It seems like ReactContext should go away when React switches to parent context instead of owner. Is that the case and will it fix this issue specifically?

@ikr
Copy link
Contributor

ikr commented Nov 4, 2015

@mridgway I bumped into the same problem with React 0.13.3 and npm link. What did you do in the end?

Did you try using react as a peer dependency in sub-components? That didn't work for me.

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

No branches or pull requests

5 participants