Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentDidUpdate(prevProps: InternalProps) {
// TODO Check if data has changed between render and update. Schedule another
// update if so
const mustResubscribe =
prevProps.relayContext !== this.props.relayContext ||
!areEqual(
getDataIDsFromObject(fragmentNodes, prevProps.fragmentRefs),
getDataIDsFromObject(fragmentNodes, this.props.fragmentRefs),
);
if (mustResubscribe) {
this._unsubscribe();
this._subscribe();
}
}
UNSAFE_componentWillReceiveProps(nextProps) {
const relayContext = assertRelayContext(nextProps.__relayContext);
const prevIDs = getDataIDsFromObject(fragments, this.props);
const nextIDs = getDataIDsFromObject(fragments, nextProps);
// If the environment has changed or props point to new records then
// previously fetched data and any pending fetches no longer apply:
// - Existing references are on the old environment.
// - Existing references are based on old variables.
// - Pending fetches are for the previous records.
if (
relayContext.environment !== this.state.prevContext.environment ||
!areEqual(prevIDs, nextIDs)
) {
this._cleanup();
// Child containers rely on context.relay being mutated (for gDSFP).
this._resolver = createFragmentSpecResolver(
relayContext,
containerName,
static getDerivedStateFromProps(
nextProps: ContainerProps,
prevState: ContainerState,
): $Shape | null {
// Any props change could impact the query, so we mirror props in state.
// This is an unusual pattern, but necessary for this container usecase.
const {prevProps} = prevState;
const relayContext = assertRelayContext(nextProps.__relayContext);
const prevIDs = getDataIDsFromObject(fragments, prevProps);
const nextIDs = getDataIDsFromObject(fragments, nextProps);
let resolver: FragmentSpecResolver = prevState.resolver;
// If the environment has changed or props point to new records then
// previously fetched data and any pending fetches no longer apply:
// - Existing references are on the old environment.
// - Existing references are based on old variables.
// - Pending fetches are for the previous records.
if (
prevState.prevPropsContext.environment !== relayContext.environment ||
!areEqual(prevIDs, nextIDs)
) {
// Do not provide a subscription/callback here.
// It is possible for this render to be interrupted or aborted,
// In which case the subscription would cause a leak.
// We will add the subscription in componentDidUpdate().
getDerivedStateFromProps (nextProps, prevState) {
// Any props change could impact the query, so we mirror props in state.
// This is an unusual pattern, but necessary for this container usecase.
const { prevProps } = prevState
const relayContext = assertRelayContext(nextProps.__relayContext)
const prevIDs = getDataIDsFromObject(fragments, prevProps)
const nextIDs = getDataIDsFromObject(fragments, nextProps)
let resolver = prevState.resolver
// If the environment has changed or props point to new records then
// previously fetched data and any pending fetches no longer apply:
// - Existing references are on the old environment.
// - Existing references are based on old variables.
// - Pending fetches are for the previous records.
if (
prevState.prevPropsContext.environment !== relayContext.environment ||
prevState.prevPropsContext.variables !== relayContext.variables ||
!areEqual(prevIDs, nextIDs)
) {
// Do not provide a subscription/callback here.
// It is possible for this render to be interrupted or aborted,
getDerivedStateFromProps: function getDerivedStateFromProps(nextProps, prevState) {
// Any props change could impact the query, so we mirror props in state.
// This is an unusual pattern, but necessary for this container usecase.
var prevProps = prevState.prevProps;
var relayContext = assertRelayContext(nextProps.__relayContext);
var prevIDs = getDataIDsFromObject(fragments, prevProps);
var nextIDs = getDataIDsFromObject(fragments, nextProps); // If the environment has changed or props point to new records then
// previously fetched data and any pending fetches no longer apply:
// - Existing references are on the old environment.
// - Existing references are based on old variables.
// - Pending fetches are for the previous records.
if (prevState.prevPropsContext.environment !== relayContext.environment || prevState.prevPropsContext.variables !== relayContext.variables || !areEqual(prevIDs, nextIDs)) {
this._cleanup(); // Child containers rely on context.relay being mutated (for gDSFP).
this._resolver = createFragmentSpecResolver(relayContext, containerName, fragments, nextProps, this._handleFragmentDataUpdate);
return {
data: this._resolver.resolve(),
prevProps: nextProps,
prevPropsContext: relayContext,
contextForChildren: relayContext,
relayProp: this._buildRelayProp(relayContext)
function getFragmentCacheKey(
fragmentNode: ConcreteFragment,
fragmentRef: mixed,
variables: Variables,
): string {
const fragmentVariables = getVariablesFromObject(
variables,
{[fragmentNode.name]: fragmentNode},
{[fragmentNode.name]: fragmentRef},
);
const dataIDs = getDataIDsFromObject(
{[fragmentNode.name]: fragmentNode},
{[fragmentNode.name]: fragmentRef},
);
return JSON.stringify({
dataIDs,
fragmentVariables,
});
}
static getDerivedStateFromProps(nextProps, prevState) {
return {
mirroredFragmentRefs: nextProps.fragmentRefs,
mirroredRelayContext: nextProps.relayContext,
mustResubscribe:
prevState.mirroredRelayContext !== nextProps.relayContext ||
!areEqual(
getDataIDsFromObject(fragmentNodes, prevState.mirroredFragmentRefs),
getDataIDsFromObject(fragmentNodes, nextProps.fragmentRefs),
),
};
}