-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Make RelayStore Contextual #603
Conversation
|
||
this.props.relayContext.injectBatchingStrategy( | ||
ReactDOM.unstable_batchedUpdates | ||
); |
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.
ReactDOM.unstable_batchedUpdates
is not suitable for server-side rendering. And generally, I believe RelayRenderer
should not be responsible for defining the batching strategy, and should not override it either. It may cause problems such as: denvned/isomorphic-relay-router#5 (comment). Still, ReactDOM.unstable_batchedUpdates
might be the default injected by the constructor of RelayContext
.
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.
Or even better, do not inject ReactDOM.unstable_batchedUpdates
at all. The user can inject that himself if he needs it.
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.
I think it might be good for Relay to have a sensible default here... Maybe we could introduce a BatchingStrategyLayer
that by default injects ReactDOM.unstable_batchedUpdates
on the client side, etc. Then you can override this if you'd like.
(In this particular case, the change was made to keep the same behavior as master
.)
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.
I think the following can solve the problem temporarily, and be compatible with master
:
RelayStore.injectBatchingStrategy(
ReactDOM.unstable_batchedUpdates
);
But, since you are deprecating RelayStore
the following might be better:
const defaultContext = RelayContext.getDefaultInstance();
defaultContext.injectBatchingStrategy(
ReactDOM.unstable_batchedUpdates
);
RelayRenderer.defaultProps = {
context: defaultContext,
}
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.
But the later approach have a problem that only the default instance will have the batching strategy injected. Injecting ReactDOM.unstable_batchedUpdates
to every new RelayContext
by default is also bad, because in couples Relay to ReactDOM too much.
I think, that could be solved by subclassing RelayContext
with ReactDOMRelayContext
, so only the later will inject ReactDOM.unstable_batchedUpdates
. And make ReactDOMRelayContext
the default for the context
property of RelayRenderer
:
RelayRenderer.defaultProps = {
context: ReactDOMRelayContext.getDefaultInstance(),
}
And make RelayStore
an alias of ReactDOMRelayContext.getDefaultInstance()
for backward compatibility.
|
Good catch 👍 Thanks for the feedback! |
}; | ||
|
||
RelayRenderer.defaultProps = { | ||
relayContext: RelayStore, |
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.
Since you are deprecating RelayStore
, may be RelayContext.getDefaultInstance()
is better?
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.
relayContext
is a required prop, there's no need for a default
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.
Default was added here because tons of tests are shallow rendering a RelayRenderer
. Will update those when I get a chance 👍
This is a cleaner shot at #570.
RelayGarbageCollection
hasn't been updated yet (needs clarification)RelayRenderer
takesRelayContext
as a prop (instead of as context from RelayRootContainer).GraphQLStoreQueryResolver
changes.Relay.Store
deprecation calls.RelayStore
mock.This ignores the clean up of interdependencies in
RelayStoreData
, since the discussion on that is ongoing.