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

Connected component prevents all context propagations #144

Closed
rpominov opened this issue Oct 9, 2015 · 5 comments
Closed

Connected component prevents all context propagations #144

rpominov opened this issue Oct 9, 2015 · 5 comments

Comments

@rpominov
Copy link

rpominov commented Oct 9, 2015

Because connected components have aggressive shouldComponentUpdate, and shouldComponentUpdate doesn't support context, connected components basically stop any other context variables changes to propagate to their children.

Is there a recommended solution to this problem? I found pure option (connect(..., {pure: false})), which helps, but is there a better way?

@esamattis
Copy link
Contributor

Related facebook/react#2517

@rpominov
Copy link
Author

rpominov commented Oct 9, 2015

One possible solution to this is to check only state in shouldComponentUpdate, if state didn't change always return true, and allow target component to decide if it should be updated.

This seems like a reasonable default behavior to me — check in shouldComponentUpdate only stuff we manage (this.state), and delegate any other checks to user's components.

@gaearon
Copy link
Contributor

gaearon commented Oct 9, 2015

The only better option that using { pure: false } if you rely on context propagation is helping React fix it, or helping library maintainers work around this context issue.

Related:

@gaearon gaearon closed this as completed Oct 9, 2015
rpominov added a commit to rpominov/react-redux that referenced this issue Oct 9, 2015
@rpominov
Copy link
Author

rpominov commented Oct 9, 2015

or helping library maintainers work around this context issue.

Well this is what I'm trying to do :)

I've made a PR with a possible fix #149 It requires a bit more work, but I wanted to ask first if this idea makes sense.

@gaearon
Copy link
Contributor

gaearon commented Oct 9, 2015

Well this is what I'm trying to do :)

Oh, I meant libraries-relying-on-context-propagation, e.g. remix-run/react-router#470.

Longer term it's React's problem, but there are feasible workaround for specific libs today.
As you can see, for example, React Redux isn't affected because it doesn't read values from context.

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

Successfully merging a pull request may close this issue.

3 participants