-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
RFC: Should update child context #3973
Conversation
…pdate context dependant components down the tree
…tching context/child context keys
Re: Re: not broadcasting to the whole subtree, I think there are two valid patterns. Wormholes, as you suggested in #2517, make perfect sense. We use that pattern for grouping items within various subsystems (like focus and voice). Additionally, though, we'd want to use context to pass down i18n information to a whole section of (perhaps the entirety of) our application, and force a re-render of anything that uses it. That kind of broadcast pattern is probably relatively rare compared to the wormhole pattern, but I believe it's still valid. Right now we're occasionally using mixins for focus and voice groups from the same source. I think there are valid use cases for not forcing a 1:1 mapping, though I understand the desire for the restriction. |
Well currently the broadcast pattern can be implemented as wormholes as well. It's just more boilerplate, which might be ok if it is rare.
Any parent component that doesn't provide this context cannot intercept it with neither The only benefit We don't allow you to make fine grained |
Re: For sure, you could do broadcast with wormholes. Taking it to the extreme you could do it with props, too :) Potentially that boilerplate is fine, but I'd always lean toward avoiding boilerplate if it's reasonable to do so. |
Just to explore the boilerplate:
Let's say |
@sebmarkbage Since children is a prop, this would mean that the ContextProvider (which is presumably a parent (but not an owner) of a very large subtree) would return true any time anything on the page changed. If context is assumed to have changed on every rerender, this means the ContextProvider effectively has no way of opting out of the context change, since it needs to update because the children have changed (ie. we don't want to notify all the context recipients deep in the tree, but we must). I think the common case is that the context does not change but the children prop does change and thus a render needs to happen but we don't want all the recipients of the context variable to start rerendering themselves. |
@@ -0,0 +1,118 @@ | |||
<!DOCTYPE html> |
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.
Context isn't supported yet; I don't think we want to have an example. For now, we will want to be unit-tests only.
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.
Yeah, this was just the branch I was working on for testing my stuff visually and so all this code would need cleaning up a lot before actually going in. Seb opened up a pr for discussions sake :)
It's great to see all the discussion which has been going on though! I've been busy and away over the past week so haven't been able to get involved too much. Hopefully will have a read through everything later!
See #2517