-
Notifications
You must be signed in to change notification settings - Fork 47.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect React Native v3 backend and show warning
- Loading branch information
Brian Vaughn
committed
Jul 18, 2019
1 parent
9fb753b
commit 249a2e0
Showing
7 changed files
with
99 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.Command { | ||
background-color: var(--color-dimmest); | ||
padding: 0.25rem 0.5rem; | ||
display: block; | ||
border-radius: 0.125rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// @flow | ||
|
||
import React, { Fragment, useContext, useEffect } from 'react'; | ||
import { BridgeContext } from './context'; | ||
import { ModalDialogContext } from './ModalDialog'; | ||
|
||
import styles from './WarnIfLegacyBackendDetected.css'; | ||
|
||
export default function WarnIfLegacyBackendDetected(_: {||}) { | ||
const bridge = useContext(BridgeContext); | ||
const { dispatch } = useContext(ModalDialogContext); | ||
|
||
// Detect pairing with legacy v3 backend. | ||
// We do this by listening to a message that it broadcasts but the v4 backend doesn't. | ||
// In this case the frontend should show upgrade instructions. | ||
useEffect(() => { | ||
// Wall.listen returns a cleanup function | ||
let unlisten = bridge.wall.listen(event => { | ||
switch (event.type) { | ||
case 'call': | ||
case 'event': | ||
case 'many-events': | ||
// Any of these types indicate the v3 backend. | ||
dispatch({ | ||
canBeDismissed: false, | ||
type: 'SHOW', | ||
title: | ||
'React DevTools v4 is incompatible with this version of React', | ||
content: <InvalidBackendDetected />, | ||
}); | ||
|
||
if (typeof unlisten === 'function') { | ||
unlisten(); | ||
unlisten = null; | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
}); | ||
|
||
return () => { | ||
if (typeof unlisten === 'function') { | ||
unlisten(); | ||
unlisten = null; | ||
} | ||
}; | ||
}, [bridge, dispatch]); | ||
|
||
return null; | ||
} | ||
|
||
function InvalidBackendDetected(_: {||}) { | ||
return ( | ||
<Fragment> | ||
<p>Either upgrade React or install React DevTools v3:</p> | ||
<code className={styles.Command}>npm install -d react-devtools@^3</code> | ||
</Fragment> | ||
); | ||
} |