Fix IE8
Ben Alpert committed
Jun 9, 2015 at 18:44 UTC
13a8758fc8e860fae1d3abfddb833c40dfb6e160
1 file changed
+43
-35
src/renderers/dom/shared/ReactDefaultInjection.js
+43
-35
@@ -40,6 +40,13 @@ var SVGDOMPropertyConfig = require('SVGDOMPropertyConfig');
40
41
var warning = require('warning');
42
43
+var canDefineProperty = false;
44
+try {
45
+ Object.defineProperty({}, 'test', {get: function() {}});
46
+ canDefineProperty = true;
47
+} catch (e) {
48
+}
49
+
50
var deprecatedDOMMethods = [
51
'isMounted', 'replaceProps', 'replaceState', 'setProps', 'setState',
52
'forceUpdate',
@@ -68,49 +75,50 @@ function autoGenerateWrapperClass(type) {
75
null, // key
76
null, // ref
77
internalInstance._currentElement._owner, // owner
71
- this._internalProps
78
+ this._internalProps || this.props
79
);
80
},
81
});
82
76
- Object.defineProperty(wrapperClass.prototype, 'props', {
77
- enumerable: true,
78
- set: function(props) {
79
- this._internalProps = props;
80
- },
81
- get: function() {
82
- if (__DEV__) {
83
- warning(
84
- false,
85
- 'ReactDOMComponent.props: Do not access .props of a DOM component ' +
86
- 'directly; instead, recreate the props as `render` did originally ' +
87
- 'or use React.findDOMNode and read the DOM properties/attributes ' +
88
- 'directly.%s',
89
- getDeclarationErrorAddendum(this)
90
- );
91
- }
92
- return this._internalProps;
93
- },
94
- });
95
-
96
- deprecatedDOMMethods.forEach(function(method) {
97
- var old = wrapperClass.prototype[method];
98
- Object.defineProperty(wrapperClass.prototype, method, {
99
- enumerable: true,
100
- get: function() {
101
- if (__DEV__) {
83
+ if (__DEV__) {
84
+ if (canDefineProperty) {
85
+ Object.defineProperty(wrapperClass.prototype, 'props', {
86
+ enumerable: true,
87
+ set: function(props) {
88
+ this._internalProps = props;
89
+ },
90
+ get: function() {
91
warning(
92
false,
104
- 'ReactDOMComponent.%s(): Do not access .%s() of a DOM component.%s',
105
- method,
106
- method,
93
+ 'ReactDOMComponent.props: Do not access .props of a DOM ' +
94
+ 'component directly; instead, recreate the props as `render` ' +
95
+ 'did originally or use React.findDOMNode and read the DOM ' +
96
+ 'properties/attributes directly.%s',
97
getDeclarationErrorAddendum(this)
98
);
109
- }
110
- return old;
111
- },
112
- });
113
- });
99
+ return this._internalProps;
100
+ },
101
+ });
102
+
103
+ deprecatedDOMMethods.forEach(function(method) {
104
+ var old = wrapperClass.prototype[method];
105
+ Object.defineProperty(wrapperClass.prototype, method, {
106
+ enumerable: true,
107
+ get: function() {
108
+ warning(
109
+ false,
110
+ 'ReactDOMComponent.%s(): Do not access .%s() of a DOM ' +
111
+ 'component.%s',
112
+ method,
113
+ method,
114
+ getDeclarationErrorAddendum(this)
115
+ );
116
+ return old;
117
+ },
118
+ });
119
+ });
120
+ }
121
+ }
122
123
return wrapperClass;
124
}