Skip to content

Commit

Permalink
Remove RelayCompat from error messages (#2663)
Browse files Browse the repository at this point in the history
Summary:
`getFragment()` was only useful to improve the error message in case someone calls `getFragment()` on a RelayModern container which doesn't have this static method. No runtime behavior actually changes by this as the method was throwing an error before and after.

Also updated some messages referencing compat mode.

Pull Request resolved: #2663

Reviewed By: jstejada

Differential Revision: D14221838

Pulled By: kassens

fbshipit-source-id: e78527e6604aec9497f5a3784835c67be24f4b30
  • Loading branch information
kassens authored and facebook-github-bot committed Feb 26, 2019
1 parent 10db8bb commit f27c7c1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 37 deletions.
25 changes: 3 additions & 22 deletions packages/react-relay/buildReactRelayContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ function buildReactRelayContainer<TBase: React$ComponentType<*>>(
if (!isRelayModernEnvironment(environment)) {
throw new Error(
'RelayModernContainer: Can only use Relay Modern component ' +
`${containerName} in a Relay Modern environment!\n` +
'When using Relay Modern and Relay Classic in the same ' +
'application, ensure components use Relay Compat to work in ' +
'both environments.\n' +
'See: http://facebook.github.io/relay/docs/relay-compat.html',
`${containerName} in a Relay Modern environment!`,
);
}
}
Expand Down Expand Up @@ -97,23 +93,8 @@ function buildReactRelayContainer<TBase: React$ComponentType<*>>(
const ForwardContainer = React.forwardRef(forwardRef);

if (__DEV__) {
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing
* errors found while preparing to upgrade to 0.89.0 */
ForwardContainer.__ComponentClass = ComponentClass;
// Classic container static methods.
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing
* errors found while preparing to upgrade to 0.89.0 */
ForwardContainer.getFragment = function getFragmentOnModernContainer() {
throw new Error(
`RelayModernContainer: ${containerName}.getFragment() was called on ` +
'a Relay Modern component by a Relay Classic or Relay Compat ' +
'component.\n' +
'When using Relay Modern and Relay Classic in the same ' +
'application, ensure components use Relay Compat to work in ' +
'both environments.\n' +
'See: http://facebook.github.io/relay/docs/relay-compat.html',
);
};
// Used by RelayModernTestUtils
(ForwardContainer: any).__ComponentClass = ComponentClass;
}

/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,7 @@ describe('Configs: NODE_DELETE', () => {
}),
).toThrowError(
'commitRelayModernMutation: expected `environment` to be an instance of ' +
'`RelayModernEnvironment`.\n' +
'When using Relay Modern and Relay Classic in the same ' +
'application, ensure mutations use Relay Compat to work in ' +
'both environments.\n' +
'See: http://facebook.github.io/relay/docs/relay-compat.html',
'`RelayModernEnvironment`.',
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ function applyRelayModernOptimisticMutation(
invariant(
isRelayModernEnvironment(environment),
'commitRelayModernMutation: expected `environment` to be an instance of ' +
'`RelayModernEnvironment`.\n' +
'When using Relay Modern and Relay Classic in the same ' +
'application, ensure mutations use Relay Compat to work in ' +
'both environments.\n' +
'See: http://facebook.github.io/relay/docs/relay-compat.html',
'`RelayModernEnvironment`.',
);
const {createOperationDescriptor, getRequest} = environment.unstable_internal;
const mutation = getRequest(config.mutation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ function commitRelayModernMutation<T>(
invariant(
isRelayModernEnvironment(environment),
'commitRelayModernMutation: expected `environment` to be an instance of ' +
'`RelayModernEnvironment`.\n' +
'When using Relay Modern and Relay Classic in the same ' +
'application, ensure mutations use Relay Compat to work in ' +
'both environments.\n' +
'See: http://facebook.github.io/relay/docs/relay-compat.html',
'`RelayModernEnvironment`.',
);
const {createOperationDescriptor, getRequest} = environment.unstable_internal;
const mutation = getRequest(config.mutation);
Expand Down

0 comments on commit f27c7c1

Please sign in to comment.