Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DevTools Bug] Unsupported Bridge operation "0" #23307

Closed
gitrthanki1 opened this issue Feb 16, 2022 · 25 comments
Closed

[DevTools Bug] Unsupported Bridge operation "0" #23307

gitrthanki1 opened this issue Feb 16, 2022 · 25 comments
Assignees
Labels
Component: Developer Tools Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug

Comments

@gitrthanki1
Copy link

Website or app

local app development

Repro steps

just install react devtools and downgrade to 4.11.0

How often does this bug happen?

Every time

DevTools package (automated)

react-devtools-core

DevTools version (automated)

4.23.0-e28a0db22

Error message (automated)

Unsupported Bridge operation "0"

Error call stack (automated)

at /Users/softwaremac/Desktop/Users/JigneshJani/RNProjects/WifiSwitch/WifiSwitchV2_29_5/node_modules/react-devtools/node_modules/react-devtools-core/dist/standalone.js:53:333837
    at c.emit (/Users/softwaremac/Desktop/Users/JigneshJani/RNProjects/WifiSwitch/WifiSwitchV2_29_5/node_modules/react-devtools/node_modules/react-devtools-core/dist/standalone.js:53:277732)
    at /Users/softwaremac/Desktop/Users/JigneshJani/RNProjects/WifiSwitch/WifiSwitchV2_29_5/node_modules/react-devtools/node_modules/react-devtools-core/dist/standalone.js:53:279273
    at /Users/softwaremac/Desktop/Users/JigneshJani/RNProjects/WifiSwitch/WifiSwitchV2_29_5/node_modules/react-devtools/node_modules/react-devtools-core/dist/standalone.js:53:659742
    at Array.forEach (<anonymous>)
    at A.e.onmessage (/Users/softwaremac/Desktop/Users/JigneshJani/RNProjects/WifiSwitch/WifiSwitchV2_29_5/node_modules/react-devtools/node_modules/react-devtools-core/dist/standalone.js:53:659726)
    at A.t (/Users/softwaremac/Desktop/Users/JigneshJani/RNProjects/WifiSwitch/WifiSwitchV2_29_5/node_modules/react-devtools/node_modules/react-devtools-core/dist/standalone.js:44:3009)
    at A.emit (events.js:315:20)
    at e.exports.L (/Users/softwaremac/Desktop/Users/JigneshJani/RNProjects/WifiSwitch/WifiSwitchV2_29_5/node_modules/react-devtools/node_modules/react-devtools-core/dist/standalone.js:8:13567)
    at e.exports.emit (events.js:315:20)

Error component stack (automated)

No response

GitHub query string (automated)

https://api.github.com/search/issues?q=Unsupported Bridge operation  in:title is:issue is:open is:public label:"Component: Developer Tools" repo:facebook/react
@gitrthanki1 gitrthanki1 added Component: Developer Tools Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug labels Feb 16, 2022
@Mike2l8
Copy link

Mike2l8 commented Feb 17, 2022

Wtf

@sanjeevyadavIT
Copy link

sanjeevyadavIT commented Feb 18, 2022

Facing same issue
Screenshot 2022-02-18 at 10 20 25 AM

The error was thrown at file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5441:339974
    at kr.emit (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5441:281413)
    at file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5441:283045
    at file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5441:688182
    at Array.forEach (<anonymous>)
    at A.oe.onmessage (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5441:688165)
    at A.t (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5432:3330)
    at A.emit (events.js:315:20)
    at oe.exports.L (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5396:14736)
    at oe.exports.emit (events.js:315:20)
    at oe.exports.dataMessage (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5396:21208)
    at oe.exports.getData (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5396:20405)
    at oe.exports.startLoop (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5396:17712)
    at oe.exports._write (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5396:17002)
    at doWrite (_stream_writable.js:403:12)
    at writeOrBuffer (_stream_writable.js:387:5)

I even tried toggling the "Use globally installed DevTools" and I have devtools installed globally but it didnt work

@MuhammedKpln
Copy link

Same issue here as well.

@lunaruan
Copy link
Contributor

Hi, thanks everyone for commenting! Are any of you experiencing this issue with the most recent release of DevTools? If so, could you provide a codesandbox or a github repro? Unfortunately, we're not able to debug this issue without proper repro steps. Thanks!

@kyle-ssg
Copy link

kyle-ssg commented Feb 19, 2022

I can confirm replicating this on a vanilla react-native app using flipper (where I believe this issue was created from), the issue also persists on 4.22 as well as 4.23, however using ❯ npm i -g [email protected] sorts the issue for me

image

image

The error was thrown at file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5441:339974
    at kr.emit (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5441:281413)
    at file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5441:283045
    at file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5441:688182
    at Array.forEach (<anonymous>)
    at A.oe.onmessage (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5441:688165)
    at A.t (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5432:3330)
    at A.emit (events.js:315:20)
    at oe.exports.L (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5396:14736)
    at oe.exports.emit (events.js:315:20)
    at oe.exports.dataMessage (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5396:21208)
    at oe.exports.getData (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5396:20405)
    at oe.exports.startLoop (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5396:17712)
    at oe.exports._write (file:///Applications/Flipper.app/Contents/Resources/app.asar/bundle.js:5396:17002)
    at doWrite (_stream_writable.js:403:12)
    at writeOrBuffer (_stream_writable.js:387:5)

@lunaruan
Copy link
Contributor

Hey! I just created a vanilla react native app using create-react-native app and tested React DevTools, and I couldn't repro the error. Could you give me an exact repro?

@DrOverbuild
Copy link

I ran into the same issue on a new React Native 0.67.3 app generated with react-native init

Clicking dismiss on the Unsupported Bridge operation "0" message removes that message but then I am presented with this error:

Screen Shot 2022-02-25 at 11 58 30 AM

I checked which version of react-devtools-core that the Metro server is using:

$ npm explain react-devtools-core
  [email protected]
  node_modules/react-native/node_modules/react-devtools-core
    react-devtools-core@"4.19.1" from [email protected]
  ...

So React Native uses react-devtools-core 4.19.1, not too far behind the latest. So it should be compatible right?

Well by downgrading to use the exact version that React Native uses, it is now working for me. So I guess 4.19.1 and 4.23.0 are not compatible

npm remove -g react-devtools
npm install -g [email protected]

@bvaughn
Copy link
Contributor

bvaughn commented Mar 2, 2022

So React Native uses react-devtools-core 4.19.1, not too far behind the latest. So it should be compatible right?

No. This is why the dialog suggests downgrading the frontend.

We know this is not ideal, but the architecture of react-devtools and react-native has been around for a long time (predating those of us now working on the tooling side). For the browser extensions (most common use case) or even packages like react-devtools-inline – the frontend and backend are shipped together. For React Native, a backend version is embedded into the app (in DEV mode) so any mismatches between frontend and backend will break things. This is why there's a protocol check and a dialog like the one shown above.

Well by downgrading to use the exact version that React Native uses, it is now working for me. So I guess 4.19.1 and 4.23.0 are not compatible

That's correct.

@DrOverbuild
Copy link

The dialog suggests downgrading to a version prior to v4.11.0, but because the backend is running 4.19.1, following the directions in the dialog does not work. We are presented with a similar message, but instead the dialog suggests upgrading to ^4.13.0.

Screen Shot 2022-03-02 at 1 27 13 PM

With the given semver notation, version 4.23.0 satisfies ^4.13.0, and that's what NPM installs.

It looks like the backend of 4.19.1 (presumably using bridge protocol version 1) communicates an incorrect bridge protocol version. Either that or the frontend of 4.23.0, which expects version 2, reads an incorrect bridge protocol version from the backend. Ether way, the dialog suggests a misleading downgrade command.

At any rate, the main point is if you're getting either Unsupported Bridge operation "0" or Unsupported DevTools backend version, check the backend version you're using (which, with React Native, it's currently 4.19.1) and make sure you have that exact version of the frontend.

@bvaughn
Copy link
Contributor

bvaughn commented Mar 3, 2022

The dialog's suggestion is based on which version of the backend React Native has embedded. If the frontend version you are currently using requires a newer protocol, you will be prompted to downgrade (to match). If the frontend version requires an older protocol version, you will be required to upgrade (to match).

At least, that is how it is supposed to work. Given this issue, it sounds like some combination(s) of backend and frontend version aren't working as designed.

@DrOverbuild Any chance you could give me a list of exactly which versions (backend and frontend) you used that showed that series of dialogs? I'd like to repro and dig into where things went wrong.

@DrOverbuild
Copy link

With not being able to respond due to the lockdown last week, I had some extra time to investigate the issue.

@DrOverbuild Any chance you could give me a list of exactly which versions (backend and frontend) you used that showed that series of dialogs? I'd like to repro and dig into where things went wrong.

To answer your question, the only backend I've tried is 4.19.1, bundled with React Native.

  • Frontend v4.10.3 suggests to upgrade to ^4.13.0. It sees the correct bridge protocol version from the backend.
  • Frontend versions up to 4.21.0 work (as that is the last version supporting bridge protocol v1).
  • Frontend versions after 4.22.1 will suggest to downgrade to <4.11.0.

Looking at source code I see the front end assumes bridge protocol version 0 if it doesn't get a response within 10 seconds (because old versions of DevTools don't know about bridge protocol versioning). This timeout is further confirmed by the fact that I'm getting that downgrade message only after 10 seconds of staring at a blank inspector.

However, the manner through which I get the RN app to connect to devtools matters. If the app is already running and I open the debug menu in the RN app, devtools will timeout. If I terminate the app and run it again, devtools will timeout. But if I just reload the app, devtools does not timeout and shows that the backend is using bridge protocol 1.

I want to say this is more an issue with react-devtools-core in React Native than with the frontend.

@bvaughn
Copy link
Contributor

bvaughn commented Mar 10, 2022

Thank you for the extra context!

  • Frontend versions after 4.22.1 will suggest to downgrade to <4.11.0.

This seems broken. I'm guessing the timeout is firing when it shouldn't, maybe b'c something isn't forwarding the protocol check message (or not forwarding it fast enough?)

@DrOverbuild
Copy link

Ok I downloaded this entire repo and set up a dev environment so I could debug what's going on here.

We're getting Unsupported Bridge operation "0" due to the incompatibility with version 1 and 2 of the bridge protocol. That's expected.

When that happens, Store.onBridgeOperations throws an error that gets bubbled up the call stack above the event emitter. I can't quite tell how the error gets handled above that, but my guess is that it's causing the bridge to stop listening for events?

I added a console.log here, and this is the output when connecting with an unsupported back end version:

Received message from backend: overrideComponentFilters
Received message from backend: isBackendStorageAPISupported
Received message from backend: isSynchronousXHRSupported
Received message from backend: operations
[React DevTools] Error calling listener {event: "operations", payload: Array(2580)}
    ...
Uncaught Error: Unsupported Bridge operation "0"
    ...

The bridge receives no message after processing the operations message. There's no bridgeProtocol message, so the timeout is fired.

After commenting out the throw statement here we see bridgeProtocol is sent in some cases after the first operations message:

Received message from backend: overrideComponentFilters
Received message from backend: isBackendStorageAPISupported
Received message from backend: isSynchronousXHRSupported
Received message from backend: operations
Received message from backend: isNativeStyleEditorSupported
Received message from backend: profilingStatus
Received message from backend: bridgeProtocol

Again I didn't have enough time this afternoon to investigate how errors are handled above the event emitter. Are you intentionally ignoring incoming bridge messages after an error like this happens? Either way I think the root of this problem is incomplete error handling or simply timing of the bridge messages.

@bvaughn
Copy link
Contributor

bvaughn commented Mar 11, 2022

This is helpful! Thank you.

So the repro steps basically sound like...

  • An app with DevTools backend version 4.19.1
  • DevTools frontend version 4.22.1

Is that right? Let me see if I can repro too.


Edit 1 – I can repro.

@DrOverbuild
Copy link

Yes it's happening with DevTools frontend versions 4.22.1 and up.

As far as the backend goes, I'm only able to reproduce this in React Native.

I couldn't reproduce it in a web app. But maybe I'm not setting it up correctly? I tried adding DevTools core to a create-react-app template, and calling connectToDevTools() before importing react and react-dom, but I see that the frontend never actually gets any operations messages. Instead, the backend, in the React app, throws an error saying that hook.sub is not a function.

@bvaughn
Copy link
Contributor

bvaughn commented Mar 11, 2022

I couldn't reproduce it in a web app.

Right, that makes sense, because the backend and frontend are bundled along with each other in the case of the web extension and inline packages. Even with the standalone, the webpage loads the backend script via an HTTP server the frontend runs.

React Native is the odd one out.

@bvaughn
Copy link
Contributor

bvaughn commented Mar 11, 2022

As a workaround for anyone reading this, you could use an approach like Resolutions to work around the backend version mismatch, e.g.

  "resolutions": {
    "react-native/react-devtools-core": "4.24.0"
  },

I used a similar resolution in my test React Native project to force downgrade the backend to 4.19.1.

@bvaughn
Copy link
Contributor

bvaughn commented Mar 11, 2022

Okay, after digging into this– I can repro it. I'm not sure there's a great workaround or "fix" for it though. The underlying issue (explained in #21326) still needs to be handled.

Maybe React Native could do a better job of prompting/matching backend and frontend versions during installation? I'm not sure how React DevTools (the frontend UI) could do this other than via some protocol version check like we are already doing. (Although if anyone has ideas I'd love to talk about them.)

In hindsight, I should have made the very first parameter in the operations array a protocol version number. Then the frontend could treat messages different based on their known protocol. But it's too late to make this change and so here we are.

@bvaughn
Copy link
Contributor

bvaughn commented Mar 14, 2022

Looking at the history of the Bridge protocol stuff, we basically have the following changes:

  • Protocol changed from 0 to 1: 4.10.1 -> 4.11.0
  • Protocol changed from 1 to 2: 4.21.0 -> 4.22.0

The source revisions for the above versions are:

Exporting and comparing these revisions...

# Export
git archive -o ~/Desktop/DevTools/4.10.1.zip f160547f47cb271bff09c639a6dae8f1b169bc14
git archive -o ~/Desktop/DevTools/4.11.0.zip d4cae99f2a59e0380871134960d29ec5ce2c4fd9
git archive -o ~/Desktop/DevTools/4.21.0.zip 6c7ef3fce5547da5db3d400ccf95a5023f8891f4
git archive -o ~/Desktop/DevTools/4.22.0.zip 0229baee21e8e6ecef04d4d76c41af84dfcca8bc

# Extract...

# Diff:
diff \
  ./4.10.1/packages/react-devtools-shared/src/devtools/store.js \
  ./4.11.0/packages/react-devtools-shared/src/devtools/store.js \
  > 4.11.diff

diff \
  ./4.11.0/packages/react-devtools-shared/src/devtools/store.js \
  ./4.21.0/packages/react-devtools-shared/src/devtools/store.js \
  > 4.21.diff

diff \
  ./4.21.0/packages/react-devtools-shared/src/devtools/store.js \
  ./4.22.0/packages/react-devtools-shared/src/devtools/store.js \
  > 4.22.diff

Looking at the store diffs, I see the following changes between protocol changes::

  • 0 to 1: Added TREE_OPERATION_REMOVE_ROOT and TREE_OPERATION_UPDATE_ERRORS_OR_WARNINGS messages. I think, maybe, this isn't technically a breaking change since both operations are new.
  • 1 to 2: Added two extra bits to the TREE_OPERATION_ADD message for new root nodes. These bits specified strict mode compatibility and owner metadata properties.

If I had thought to design the operations array up front to include its protocol version as the first bit, then we could easily support backwards compatability in cases like this. Really bad oversight on my part, in hindsight. As it is now, we could try to do this (if we already have the protocol version) but there would be cases we can't handle (e.g. the backend is too old to report its protocol and the frontend times out).

Maybe we could queue up operations until we know (or infer) the backend version? I'm not sure how hard this would be to implement in practice, especially when considering cases like reload and profile. Probably hard.

I'm not sure there's really a way to fix it at this point. If I could go back, unpublish and overwrite each of the older revisions to add this info, maybe...but NPM doesn't support that kind of an operation.

bvaughn pushed a commit that referenced this issue Mar 15, 2022
… for old protocol operations format (#24093)

Rationale: The only case where the unsupported dialog really matters is React Naive. That's the case where the frontend and backend versions are most likely to mismatch. In React Native, the backend is likely to send the bridge protocol version before sending operations– since the agent does this proactively during initialization.

I've tested the React Native starter app– after forcefully downgrading the backend version to 4.19.1 (see #23307 (comment)) and verified that this change "fixes" things. Not only does DevTools no longer throw an error that causes the UI to be hidden– it works (meaning that the Components tree can be inspected and interacted with).
@bvaughn
Copy link
Contributor

bvaughn commented Mar 15, 2022

Bug fix has been released as version 4.24.1 (#24100). You should be able to fix this issue by upgrading the frontend (the UI you run) to the latest NPM release.

@bvaughn bvaughn closed this as completed Mar 15, 2022
@usrbowe
Copy link

usrbowe commented Mar 16, 2022

@bvaughn can I just check for Flipper.
If we bump the React Devtools to 4.24.1: facebook/flipper#3542

Does it mean, we can only use the latest 4.24.1 React Devtools in Flipper, with a force yarn resolution of react-native/react-devtools-core: 4.24.1?

Wonder if we could have some other workaround to solve the issue, where Flipper might need to support wider range of React Native apps (ideally also without this forced resolution)

Update:
Tested with React Native 0.63, which uses react-devtools-core@^4.6.0 and it works well with 4.24.1. Does not require to use the resolution.

@bvaughn
Copy link
Contributor

bvaughn commented Mar 16, 2022

@usrbowe Bumping the version of the React DevTools (frontend) used in Flipper sounds like a good idea. 4.24.1 is more "compatible" with older backend versions.

facebook-github-bot pushed a commit to facebook/flipper that referenced this issue Mar 30, 2022
Summary:
Related to this issue: facebook/react#23307

## Changelog

bump react-devtools-core to 4.24.1

Pull Request resolved: #3542

Test Plan: // bvaughn

Reviewed By: passy

Differential Revision: D35211366

Pulled By: mweststrate

fbshipit-source-id: 890d18e87ba07e140c1c49857d02410767c6c17d
zhengjitf pushed a commit to zhengjitf/react that referenced this issue Apr 15, 2022
… for old protocol operations format (facebook#24093)

Rationale: The only case where the unsupported dialog really matters is React Naive. That's the case where the frontend and backend versions are most likely to mismatch. In React Native, the backend is likely to send the bridge protocol version before sending operations– since the agent does this proactively during initialization.

I've tested the React Native starter app– after forcefully downgrading the backend version to 4.19.1 (see facebook#23307 (comment)) and verified that this change "fixes" things. Not only does DevTools no longer throw an error that causes the UI to be hidden– it works (meaning that the Components tree can be inspected and interacted with).
@1280103995
Copy link

b3da4ac-feab-49a1-966b-a9b677a47d15

@Sakura-echos
Copy link

image
any one help?

@roykoper
Copy link

image any one help?

I had the same issue, downgrading to 12.1 worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Developer Tools Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug
Projects
None yet
Development

No branches or pull requests

13 participants