[DevTools] Fix ReactDevToolsBackend module for AMD (#35891)

## Summary

For apps that use AMD, we need to actually `require()` the
ReactDevToolsBackend and load it from the AMD module cache. This adds a
check for the case where the `ReactDevToolsBackend` isn't defined
globally, and so we load it with `require()`.


## How did you test this change?

Tested through https://github.com/facebook/react/pull/35886
This commit is contained in:
Mushaheed Kapadia
2026-02-24 10:27:59 -05:00
committed by GitHub
parent b354bbd2d2
commit bd76b456c1
2 changed files with 2 additions and 0 deletions

View File

@@ -361,6 +361,7 @@ function startServer(
response.end(
backendFile.toString() +
'\n;' +
`var ReactDevToolsBackend = typeof ReactDevToolsBackend !== "undefined" ? ReactDevToolsBackend : require("ReactDevToolsBackend");\n` +
`ReactDevToolsBackend.initialize(undefined, undefined, undefined, ${componentFiltersString});` +
'\n' +
`ReactDevToolsBackend.connectToDevTools({port: ${port}, host: '${host}', useHttps: ${

View File

@@ -44,6 +44,7 @@ module.exports = {
// This name is important; standalone references it in order to connect.
library: 'ReactDevToolsBackend',
libraryTarget: 'umd',
umdNamedDefine: true,
},
resolve: {
alias: {