Cleanup legacy backend event listener if modern backend is detected
Brian Vaughn committed
Jul 19, 2019 at 09:02 UTC
0abaefb7c2f10d64d4f5ba1bf9de40dfd9727300
1 file changed
+19
-2
src/devtools/views/WarnIfLegacyBackendDetected.js
+19
-2
@@ -15,8 +15,8 @@ export default function WarnIfLegacyBackendDetected(_: {||}) {
15
// In this case the frontend should show upgrade instructions.
16
useEffect(() => {
17
// Wall.listen returns a cleanup function
18
- let unlisten = bridge.wall.listen(event => {
19
- switch (event.type) {
18
+ let unlisten = bridge.wall.listen(message => {
19
+ switch (message.type) {
20
case 'call':
21
case 'event':
22
case 'many-events':
@@ -28,6 +28,23 @@ export default function WarnIfLegacyBackendDetected(_: {||}) {
28
content: <InvalidBackendDetected />,
29
});
30
31
+ // Once we've identified the backend version, it's safe to unsubscribe.
32
+ if (typeof unlisten === 'function') {
33
+ unlisten();
34
+ unlisten = null;
35
+ }
36
+ break;
37
+ default:
38
+ break;
39
+ }
40
+
41
+ switch (message.event) {
42
+ case 'isBackendStorageAPISupported':
43
+ case 'isNativeStyleEditorSupported':
44
+ case 'operations':
45
+ case 'overrideComponentFilters':
46
+ // Any of these is sufficient to indicate a v4 backend.
47
+ // Once we've identified the backend version, it's safe to unsubscribe.
48
if (typeof unlisten === 'function') {
49
unlisten();
50
unlisten = null;