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
Allow disabling Relay container shouldComponentUpdate #897
Conversation
@@ -106,6 +107,7 @@ function createContainerComponent( | |||
var fragmentNames = Object.keys(fragments); | |||
var initialVariables = spec.initialVariables || {}; | |||
var prepareVariables = spec.prepareVariables; | |||
var pure = spec.pure !== false; |
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.
edit: nevermind, this makes sense after reading the redux docs at https://github.com/reactjs/react-redux/blob/master/docs/api.md#arguments
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.
This is written as a double negative to handle the case when spec.pure
is undefined
and it should default to true
.
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.
yup, realized that after - makes sense
Instead of making this configurable, could we instead make our At the moment, we short-circuit with |
That would be ideal but I don't think it's possible because you can't introspect all possible context items. Perhaps I've overlooked some mechanism for doing so? |
I guess by default you're only going to get the |
Is there anything outstanding preventing this from being merged? |
78f61e9
to
b84c3f5
Compare
I'd like to leave this one up for a bit to give people a chance to comment on it before we proceed. Three reasons why I'm inclined to be pretty conservative about this:
So, let's gather a bit more input first. |
Okay, thanks for the update 😃 The option name was originally |
I don't see the point of this tbh. If you really want this, just wrap your Relay component with https://github.com/reactjs/react-static-container |
From react-static-container readme:
However, this PR introduces the ability to override Relay and enable updating of the subtree once again. |
I agree that this is a valid use-case, but it also seems to be uncommon enough that it would be preferable to avoid increasing the API surface area, as @wincent mentioned. Rather than add more API/options, I think we'll make more progress as a community if we focus on low-level primitives that can be composed together. What if it was so easy to build your own Relay Container that you could just do that and write your own |
That's exactly what react-static-container is designed for. It doesn't introduce any new ReactElements so you can add or remove it without triggering any DOM changes e.g. if (SHOULD_DISABLE_UPDATES) {
// Wrap Relay component.
return <StaticContainer>{relayComponent}</StaticContainer>
} else {
return relayComponent
} |
I should clarify that i'm referring to #559. |
@KyleAMathews the problem is that Relay will currently act as a static container and block updates, when the OP would prefer that it doesn't (bc data has changed on context). |
@josephsavona ah :) didn't read the OP very closely I guess. |
Hi, sorry. This is partially my fault, but I forgot to subscribe to this PR. I suggested This is useful in the case where I'm using forms that communicate data via The current userspace implementation is a bit gross: import Relay from 'react-relay';
function shouldComponentUpdate() {
return true;
}
export default function createFormInputContainer(...args) {
const Container = Relay.createContainer(...args);
function FormInputContainer(props, context) {
const container = new Container(props, context);
// Always update; this will be nested in a contained form anyway, and we
// need to not block updates from the form on context.
container.shouldComponentUpdate = shouldComponentUpdate;
return container;
}
Object.keys(Container).forEach(key => {
FormInputContainer[key] = Container[key];
});
return FormInputContainer;
} This dance is necessarily of the lazy class initialization in |
I'm not crazy about increasing the surface area of RelayContainer, but the workaround (as documented by @taion) is not at all obvious. Let's move forward with this. |
@facebook-github-bot import |
We actually just hit the opposite problem, BTW, in that there are a few places where we wish we could configure the Relay container would do shallow equality checks on non-scalar props the way the Redux container does. Probably too much to ask that this part of the code have yet another branch, though. 😉 |
Thanks for importing. If you are an FB employee go to Phabricator to review. |
It would be nice to have redux style shallow equality checks for non-scalars props. In react-native all my |
@chirag04 Relay's |
Is there no downside to putting the SCU check both in the Relay container and in the contained component, though? This came up in the context of the example F8 app, which uses a number of no-op Redux containers to make components be pure, like https://github.com/fbsamples/f8app/blob/b5df451259897d1838933f01ad4596784325c2ad/js/tabs/schedule/SharingSettingsModal.js#L91. |
The render logic of |
76477bb
Nope – I'm good for now, thanks! |
Out of curiosity, per my line note at 76477bb#commitcomment-17315176, what's the benefit of not allowing an actual |
This PR introduces an optional flag
pure
toRelayContainer
which overridesshouldComponentUpdate
to return true.Closes #674.