-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Cannot use addons.Perf or addons.ReactTransitionGroup in AMD environment with 15.4.1 #8392
Comments
I am leaving this open because need to confirm the fix actually fixes this issue as well. |
No, this is about 15.4.1. |
Oh, I didn't realize 15.4.1 was already out, my bad. |
No, but it worked with 15.3.2, so it's also related to the change in packaging. |
Why is Perf depending on react-dom, it used to work in react-native context, is that no longer the case? |
The whole concept of "addons" that reach into internals is a mess IMO. I think React Native has its own We should probably expose it on renderers since it's copied now. Like |
|
I'm also using RequireJS and while 15.4.1 fixed the ability to use ReactDOM, I am unable to use renderIntoDocument makes use of Thanks for getting the 15.4.1 fix out so quickly, by the way. |
It would really help if somebody could experiment with the bundle like in #8301 (comment) and try to figure out a fix before we get a chance to look into this. |
Adding this require line in ReactAddonsDOMDependenciesUMDShim.js seems to fix it for me: But I don't know if that's the correct way to do it. Gist here: |
This would break for single-file bundles as far as I can tell. |
@hsubox76: what do you mean by "seems to fix it for me"? Have you tried to build the UMD distribution including this change? |
That change would include all of --- react-with-addons 2016-11-24 10:16:41.355197371 +0100
+++ react.js 2016-11-24 10:25:56.111594068 +0100
@@ -1,7 +1,7 @@
/**
* React (with addons) v15.4.1
*/
-(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.React = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
+(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define(["require"],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.React = f()}})(function(require){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
@@ -424,21 +424,21 @@
'use strict';
-exports.getReactDOM = function () {
- return ReactDOM;
+var getReactDOM = exports.getReactDOM = function () {
+ return 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){ Maybe we need to pass an accessor function into the UMD callback or something like that. |
Yes, the accessor pattern might work. It's pretty ugly though and I haven't adapted the CommonJS part. How would you require ReactDOM in CommonJS? --- react-with-addons 2016-11-24 10:16:41.355197371 +0100
+++ react.js 2016-11-24 10:42:01.372836180 +0100
@@ -1,7 +1,7 @@
/**
* React (with addons) v15.4.1
*/
-(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.React = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
+(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define(["require"],function(require){return f(function(){return require("react-dom")})})}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.React = f(function(){return ReactDOM})}})(function(ReactDOMAccessor){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
@@ -424,21 +424,21 @@
'use strict';
-exports.getReactDOM = function () {
- return ReactDOM;
+var getReactDOM = exports.getReactDOM = function () {
+ return ReactDOMAccessor();
};
exports.getReactInstanceMap = function () {
- return ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactInstanceMap;
+ return ReactDOMAccessor().__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 ReactDOMAccessor().__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 ReactDOMAccessor().__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactTestUtils;
};
}
},{}],7:[function(_dereq_,module,exports){ |
I think that the cleanest solution would be to build the addons as a separate file. They can depend on |
Yea, that’s what I would do too but we can’t change this before 16. |
Reverting the restructuring that led to these issues until then is not an option I guess? |
Unfortunately no, it’s crucial for our direction forward. |
But not necessarily in 15.x, right? |
At this point it's going to be too expensive for the ecosystem to revert. Many packages that relied on internal APIs (which is bad by itself) already broke once, we can't break them again. It is also technically very hard to revert now. We publicly asked for feedback on the release for a month, and this issue was not reported. I understand it is frustrating but this ship has sailed. If you'd like to help us fix that, please do. It is not obvious to me how to fix it (I tried a few times). Your stance on not submitting a PR because you refuse to sign the CLA isn't very helpful either. |
Neither is blaming your users for not finding or fixing issues in your project. But this isn't getting us anywhere. |
I apologize if any of my comments made it look like I was blaming the users. That was not my intention. Yes it’s bad that we broke this, and it’s our fault. That said we are not in a position to revert this now, so we need to figure out a way to fix this forward. We have been trying to fix it but have not found a solution that wouldn’t break something else yet. We welcome yours and anyone else’s help in this. Thanks! |
Can you share some details? Did you try something similar to my approach or was it something else entirely? |
It was something similar but I had issues with webpack if I recall correctly. I’ll give it another try later today and push my branch somewhere. |
I tried the first patch that I mentioned: |
Btw, I also tried to build something upon the information in http://requirejs.org/docs/api.html#circular, but didn't get far. The problem is that you cannot assign |
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 |
Sorry I haven’t had time to jump on it yet.
The best test case is probably |
I checked Browser and AMD with RequireJS manually. |
We don't really have any integration tests for the builds in different environments (yea, it’s not good—again, contributions are welcome). |
Here's a CodePen with my modified react-with-addons bundle (including the patch from #8392 (comment)): |
RequireJS : http://codepen.io/jochenberger/pen/dOQeqw |
I fixed the codepens to use |
The fix in #8392 (comment) doesn't seem to work during build time:
|
I started some work in #8686 but I can't get figure out how to make circular dependencies work in statically analyzable AMD environment (SystemJS Builder in particular, possibly r.js is affected too). Any help welcome. |
Can you please check if the fix in #8686 works for your case? |
Should be fixed via #8686 and released in 15.4.2 (out soon). |
Sorry, I'm late. FWIW, I just tried with current master and it works fine. Thanks! |
Can also confirm that react-with-addons works again on master in my RequireJS setup. Thanks @gaearon! |
Should be fixed after updating all React packages to 15.4.2. |
Verified: 15.4.2 from NPM is working on our RequireJS build. Thanks again! |
I use
react-with-addons
in a RequireJS enviroment. If I try to useReact.addons.Perf
, I get aReferenceError: 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.
The text was updated successfully, but these errors were encountered: