Skip to content

Commit b77151e

Browse files
make sure that ReactDevToolsBackend ends up in the global scope
1 parent e68b9a6 commit b77151e

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

packages/react-devtools-core/src/standalone.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,19 @@ function startServer(
384384
const clientUseHttps = clientOptions?.useHttps ?? useHttps;
385385

386386
response.end(
387-
backendFile.toString() +
387+
// The backend UMD bundle may not assign to the global scope if the
388+
// environment leaks `exports` or `module` (e.g. bundled apps, webviews).
389+
// Wrap it so we always capture the export.
390+
`(function() {\n` +
391+
`var exports = undefined, module = undefined, define = undefined;\n` +
392+
backendFile.toString() +
388393
'\n;' +
389-
`ReactDevToolsBackend.initialize(undefined, undefined, undefined, ${componentFiltersString});` +
390-
'\n' +
391-
`ReactDevToolsBackend.connectToDevTools({port: ${clientPort}, host: '${clientHost}', useHttps: ${
394+
`var Backend = typeof ReactDevToolsBackend !== "undefined" ? ReactDevToolsBackend : self.ReactDevToolsBackend;\n` +
395+
`Backend.initialize(undefined, undefined, undefined, ${componentFiltersString});\n` +
396+
`Backend.connectToDevTools({port: ${clientPort}, host: '${clientHost}', useHttps: ${
392397
clientUseHttps ? 'true' : 'false'
393-
}${path != null ? `, path: '${path}'` : ''}});
394-
`,
398+
}${path != null ? `, path: '${path}'` : ''}});\n` +
399+
`})();\n`,
395400
);
396401
});
397402

0 commit comments

Comments
 (0)