react: Cannot use addons.Perf or addons.ReactTransitionGroup in AMD environment with 15.4.1

I use react-with-addons in a RequireJS enviroment. If I try to use React.addons.Perf, I get a ReferenceError: ReactDOM is not defined from https://github.com/facebook/react/blob/15-dev/src/umd/shims/ReactAddonsDOMDependenciesUMDShim.js#L26. This is a regression from 15.3.x.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 43 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Should be fixed via #8686 and released in 15.4.2 (out soon).

It might even be enough to apply this patch:

diff --git a/react.js b/react.js
index 545bec4..a4ad999 100644
--- a/react.js
+++ b/react.js
@@ -424,21 +424,21 @@ module.exports = React;
 
 'use strict';
 
-exports.getReactDOM = function () {
-  return ReactDOM;
+var getReactDOM = exports.getReactDOM = function () {
+  return typeof ReactDOM !== 'undefined' ? ReactDOM : require('react-dom');
 };
 
 exports.getReactInstanceMap = function () {
-  return ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactInstanceMap;
+  return getReactDOM().__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactInstanceMap;
 };
 
 if ("development" !== 'production') {
   exports.getReactPerf = function () {
-    return ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactPerf;
+    return getReactDOM().__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactPerf;
   };
 
   exports.getReactTestUtils = function () {
-    return ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactTestUtils;
+    return getReactDOM().__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactTestUtils;
   };
 }
 },{}],7:[function(_dereq_,module,exports){

The change would probably have to be made in https://github.com/facebook/react/blob/master/src/umd/shims/ReactAddonsDOMDependenciesUMDShim.js

I’m also using RequireJS and while 15.4.1 fixed the ability to use ReactDOM, I am unable to use React.addons.TestUtils.renderIntoDocument() for probably the same reasons as above.

renderIntoDocument makes use of ReactAddonsDOMDependencies.getReactTestUtils() which looks for the same undefined ReactDOM variable that ReactPerf and other addons are looking for I believe.

Thanks for getting the 15.4.1 fix out so quickly, by the way.

@gre

The whole concept of “addons” that reach into internals is a mess IMO.

I think React Native has its own ReactPerf copy now but I’m not sure if it’s exposed. You can probably get it with require('react-native/lib/ReactPerf'); or maybe just require('ReactPerf') (not sure how Haste works in RN projects).

We should probably expose it on renderers since it’s copied now. Like ReactDOM.Perf and ReactNative.Perf or something.