Skip to content

Commit ad5971f

Browse files
authored
fix[devtools]: no-op unsupported backend bridge events (#35296)
Follow-up to #34641. Similar to #35293, #35294. React DevTools backend can be used in non-DOM environments, so we have to feature-check some DOM APIs. For now I am just no-oping newly added commands for Native, we should revisit this decision once we would roll out Suspense panel there, if needed. I am not sure if scrolling will be required as much as it is needed on Web. `isReactNativeEnvironment()` check is kinda clowny, but we've been relying on it for quite some time already.
1 parent 378973b commit ad5971f

File tree

1 file changed

+26
-7
lines changed
  • packages/react-devtools-shared/src/backend/views/Highlighter

1 file changed

+26
-7
lines changed

packages/react-devtools-shared/src/backend/views/Highlighter/index.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import Agent from 'react-devtools-shared/src/backend/agent';
1111
import {hideOverlay, showOverlay} from './Highlighter';
12+
import {isReactNativeEnvironment} from 'react-devtools-shared/src/backend/utils';
1213

1314
import type {HostInstance} from 'react-devtools-shared/src/backend/types';
1415
import type {BackendBridge} from 'react-devtools-shared/src/bridge';
@@ -49,6 +50,11 @@ export default function setupHighlighter(
4950
right: number,
5051
bottom: number,
5152
}) {
53+
if (isReactNativeEnvironment()) {
54+
// Not implemented.
55+
return;
56+
}
57+
5258
if (
5359
left === Math.round(window.scrollX) &&
5460
top === Math.round(window.scrollY)
@@ -65,6 +71,11 @@ export default function setupHighlighter(
6571

6672
let scrollTimer = null;
6773
function sendScroll() {
74+
if (isReactNativeEnvironment()) {
75+
// Not implemented.
76+
return;
77+
}
78+
6879
if (scrollTimer) {
6980
clearTimeout(scrollTimer);
7081
scrollTimer = null;
@@ -85,14 +96,17 @@ export default function setupHighlighter(
8596
applyingScroll = false;
8697
}
8798

88-
document.addEventListener('scroll', () => {
89-
if (!scrollTimer) {
90-
// Periodically synchronize the scroll while scrolling.
91-
scrollTimer = setTimeout(sendScroll, 400);
92-
}
93-
});
99+
// $FlowFixMe[method-unbinding]
100+
if (document && typeof document.addEventListener === 'function') {
101+
document.addEventListener('scroll', () => {
102+
if (!scrollTimer) {
103+
// Periodically synchronize the scroll while scrolling.
104+
scrollTimer = setTimeout(sendScroll, 400);
105+
}
106+
});
94107

95-
document.addEventListener('scrollend', scrollEnd);
108+
document.addEventListener('scrollend', scrollEnd);
109+
}
96110

97111
function startInspectingHost(onlySuspenseNodes: boolean) {
98112
inspectOnlySuspenseNodes = onlySuspenseNodes;
@@ -319,6 +333,11 @@ export default function setupHighlighter(
319333
// with the scrollIntoView option.
320334
hideOverlay(agent);
321335

336+
if (isReactNativeEnvironment()) {
337+
// Not implemented.
338+
return;
339+
}
340+
322341
if (scrollDelayTimer) {
323342
clearTimeout(scrollDelayTimer);
324343
scrollDelayTimer = null;

0 commit comments

Comments
 (0)