Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Commit e10bbfa

Browse files
kthjmwooorm
authored andcommitted
Fix React detection in production
Closes GH-4. Closes GH-3.
1 parent 5afc791 commit e10bbfa

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function addAttribute(props, name, value, ctx) {
173173
* `selector`. */
174174
function react(h) {
175175
var node = h && h('div');
176-
return Boolean(node && node._store && node.key === null);
176+
return Boolean(node && node._owner === null && node.key === null);
177177
}
178178

179179
/* Check if `h` is `hyperscript`. It doesn’t accept

test.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,46 @@ test('hast-to-hyperscript', function (t) {
141141
st.end();
142142
});
143143

144-
t.test('should support `React.createElement`', function (st) {
144+
t.test('should support `React.createElement` in `development`', function (st) {
145+
var currentEnv = process.env.NODE_ENV;
146+
process.env.NODE_ENV = 'development';
147+
148+
var baseline = doc.replace(/ camel-case="on off"/, '');
149+
var actual = toH(r, hast);
150+
var expected = r(
151+
'h1',
152+
{
153+
key: 'h-1',
154+
id: 'a',
155+
className: 'b c',
156+
hidden: true,
157+
height: '2'
158+
},
159+
'bravo ',
160+
r('strong', {
161+
key: 'h-2',
162+
style: {color: 'red'},
163+
'aria-valuenow': '1',
164+
'data-some': 'yes'
165+
}, ['charlie']),
166+
' delta',
167+
r('input', {
168+
key: 'h-3',
169+
type: 'file',
170+
accept: '.jpg, .jpeg'
171+
})
172+
);
173+
174+
st.deepEqual(html(rToString(actual)), html(baseline), 'equal output');
175+
st.deepEqual(html(rToString(expected)), html(baseline), 'equal output baseline');
176+
process.env.NODE_ENV = currentEnv;
177+
st.end();
178+
});
179+
180+
t.test('should support `React.createElement` in `production`', function (st) {
181+
var currentEnv = process.env.NODE_ENV;
182+
process.env.NODE_ENV = 'production';
183+
145184
var baseline = doc.replace(/ camel-case="on off"/, '');
146185
var actual = toH(r, hast);
147186
var expected = r(
@@ -170,6 +209,7 @@ test('hast-to-hyperscript', function (t) {
170209

171210
st.deepEqual(html(rToString(actual)), html(baseline), 'equal output');
172211
st.deepEqual(html(rToString(expected)), html(baseline), 'equal output baseline');
212+
process.env.NODE_ENV = currentEnv;
173213
st.end();
174214
});
175215

0 commit comments

Comments
 (0)