forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnsupportedBridgeProtocolDialog.js
More file actions
145 lines (133 loc) · 4.43 KB
/
UnsupportedBridgeProtocolDialog.js
File metadata and controls
145 lines (133 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import * as React from 'react';
import {Fragment, useContext, useEffect} from 'react';
import {ModalDialogContext} from './ModalDialog';
import {StoreContext} from './context';
import {currentBridgeProtocol} from 'react-devtools-shared/src/bridge';
import Button from './Button';
import ButtonIcon from './ButtonIcon';
import {copy} from 'clipboard-js';
import styles from './UnsupportedBridgeProtocolDialog.css';
import {withPermissionsCheck} from 'react-devtools-shared/src/frontend/utils/withPermissionsCheck';
import type {BridgeProtocol} from 'react-devtools-shared/src/bridge';
const DEVTOOLS_VERSION = process.env.DEVTOOLS_VERSION;
const INSTRUCTIONS_FB_URL =
'https://fb.me/devtools-unsupported-bridge-protocol';
const MODAL_DIALOG_ID = 'UnsupportedBridgeProtocolDialog';
export default function UnsupportedBridgeProtocolDialog(_: {}): null {
const {dialogs, dispatch} = useContext(ModalDialogContext);
const store = useContext(StoreContext);
const isVisible = !!dialogs.find(dialog => dialog.id === MODAL_DIALOG_ID);
useEffect(() => {
const updateDialog = () => {
if (!isVisible) {
if (store.unsupportedBridgeProtocolDetected) {
dispatch({
canBeDismissed: false,
id: MODAL_DIALOG_ID,
type: 'SHOW',
content: (
<DialogContent unsupportedBridgeProtocol={store.bridgeProtocol} />
),
});
}
} else {
if (!store.unsupportedBridgeProtocolDetected) {
dispatch({
type: 'HIDE',
id: MODAL_DIALOG_ID,
});
}
}
};
updateDialog();
store.addListener('unsupportedBridgeProtocolDetected', updateDialog);
return () => {
store.removeListener('unsupportedBridgeProtocolDetected', updateDialog);
};
}, [isVisible, store]);
return null;
}
function DialogContent({
unsupportedBridgeProtocol,
}: {
unsupportedBridgeProtocol: BridgeProtocol,
}) {
const {version, minNpmVersion, maxNpmVersion} = unsupportedBridgeProtocol;
let instructions;
if (maxNpmVersion === null) {
const upgradeInstructions = `npm i -g react-devtools@^${minNpmVersion}`;
instructions = (
<>
<p className={styles.Paragraph}>
To fix this, upgrade the DevTools NPM package:
</p>
<pre className={styles.NpmCommand}>
{upgradeInstructions}
<Button
onClick={withPermissionsCheck(
{permissions: ['clipboardWrite']},
() => copy(upgradeInstructions),
)}
title="Copy upgrade command to clipboard">
<ButtonIcon type="copy" />
</Button>
</pre>
</>
);
} else {
const downgradeInstructions = `npm i -g react-devtools@${maxNpmVersion}`;
instructions = (
<>
<p className={styles.Paragraph}>
To fix this, downgrade the DevTools NPM package:
</p>
<pre className={styles.NpmCommand}>
{downgradeInstructions}
<Button
onClick={withPermissionsCheck(
{permissions: ['clipboardWrite']},
() => copy(downgradeInstructions),
)}
title="Copy downgrade command to clipboard">
<ButtonIcon type="copy" />
</Button>
</pre>
</>
);
}
return (
<Fragment>
<div className={styles.Column}>
<div className={styles.Title}>Unsupported DevTools backend version</div>
<p className={styles.Paragraph}>
You are running <code>react-devtools</code> version{' '}
<span className={styles.Version}>{DEVTOOLS_VERSION}</span>.
</p>
<p className={styles.Paragraph}>
This requires bridge protocol{' '}
<span className={styles.Version}>
version {currentBridgeProtocol.version}
</span>
. However the current backend version uses bridge protocol{' '}
<span className={styles.Version}>version {version}</span>.
</p>
{instructions}
<p className={styles.Paragraph}>
Or{' '}
<a className={styles.Link} href={INSTRUCTIONS_FB_URL} target="_blank">
click here
</a>{' '}
for more information.
</p>
</div>
</Fragment>
);
}