Skip to content

Commit c81358a

Browse files
committed
feat(ViewportProvider): warn in case different versions of are detected in the same tree
1 parent 8346010 commit c81358a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/ViewportProvider.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,21 @@ export default class ViewportProvider extends React.PureComponent<
252252
version: '__VERSION__',
253253
};
254254

255-
renderChildren = (props: { hasRootProviderAsParent: boolean }) => {
255+
renderChildren = (props: {
256+
hasRootProviderAsParent: boolean;
257+
version: string;
258+
}) => {
256259
if (props.hasRootProviderAsParent) {
260+
if (
261+
process.env.NODE_ENV !== 'production' &&
262+
props.version !== '__VERSION__'
263+
) {
264+
console.warn(
265+
`react-viewport-utils: Two different versions of the react-viewport-utils library are used in the same react tree. This can lead to unexpected results as the versions might not be compatible.
266+
The <ViewportProvider> of version ${props.version} is currently used, another <ViewportProvider> of version __VERSION__ was detected but is ignored.
267+
This is most probably due to some dependencies that use different versions of the react-viewport-utils library. You can check if an update is possible.`,
268+
);
269+
}
257270
return this.props.children;
258271
}
259272
return (

0 commit comments

Comments
 (0)