Skip to content

Commit 123e7f9

Browse files
committed
build: try to test/run against different react versions
1 parent b261fc1 commit 123e7f9

File tree

10 files changed

+178
-74
lines changed

10 files changed

+178
-74
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flow-typed

.size-snapshot.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
{
22
"dist/react-render-callback.umd.js": {
3-
"bundled": 3207,
4-
"minified": 1340,
5-
"gzipped": 617
3+
"bundled": 3213,
4+
"minified": 1336,
5+
"gzipped": 616
66
},
77
"dist/react-render-callback.esm.js": {
8-
"bundled": 2490,
9-
"minified": 1390,
10-
"gzipped": 598,
8+
"bundled": 2502,
9+
"minified": 1398,
10+
"gzipped": 595,
1111
"treeshaked": {
1212
"rollup": {
13-
"code": 265,
13+
"code": 246,
1414
"import_statements": 97
1515
},
1616
"webpack": {
17-
"code": 1312
17+
"code": 1293
1818
}
1919
}
2020
},
2121
"dist/react-render-callback.cjs.js": {
22-
"bundled": 2627,
23-
"minified": 1489,
24-
"gzipped": 631
22+
"bundled": 2639,
23+
"minified": 1497,
24+
"gzipped": 628
2525
},
2626
"dist/react-render-callback.umd.min.js": {
27-
"bundled": 3240,
28-
"minified": 1326,
29-
"gzipped": 608
27+
"bundled": 3246,
28+
"minified": 1322,
29+
"gzipped": 604
3030
}
3131
}

.travis.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@ notifications:
99
node_js:
1010
- 10
1111
- 8
12-
install: npm install
12+
env:
13+
matrix:
14+
- REACT_VERSION="^16.3.0"
15+
- REACT_VERSION=">=16.0.0 <16.3.0"
16+
- REACT_VERSION="^15.4.0"
17+
- REACT_VERSION=">=15.0.0 <15.4.0"
18+
- REACT_VERSION="^0.14"
19+
- REACT_VERSION="latest"
20+
install:
21+
- npm install --no-save "react@${REACT_VERSION}"
22+
- npm install
23+
- npm ls react
1324
script:
1425
- kcd-scripts validate lint,test:cover,build-and-test
1526
after_success: kcd-scripts travis-after-success

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ View an example in [codesandbox.io](https://codesandbox.io/s/48k5p1r764?module=%
5353

5454
- :package: Super tiny (~600 bytes)
5555
- :ok_hand: Dependency free (except for [Object.assign](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) polyfill)
56-
- :electric_plug: Plug and play
56+
- :electric_plug: Just Works <sup>TM</sup>
5757
- :crystal_ball: Tree shaking friendly (ESM, no side effects)
5858
- :books: Well documented
5959
- :100: test coverage
60+
- :sunny: supports React v0.14, v15 and v16
6061
- :family: supports rendering of
6162
- [Stateless Function Components (SFC)](https://reactjs.org/docs/components-and-props.html#functional-and-class-components)
6263
with one argument (the common `props` case) aka _Render Props_ aka _Function as Child_

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"scripts": {
2020
"add-contributor": "kcd-scripts contributors add",
21-
"build": "kcd-scripts build --bundle --no-clean --size-snapshot && npm run flowgen",
21+
"build": "kcd-scripts build --bundle --no-clean --size-snapshot",
2222
"lint": "kcd-scripts lint",
2323
"test": "kcd-scripts test",
2424
"test:cover": "kcd-scripts test --coverage",
@@ -35,21 +35,22 @@
3535
},
3636
"sideEffects": false,
3737
"peerDependencies": {
38-
"react": "^0.14.0 || ^15.0.0-0 || ^16.0.0-0"
38+
"react": "^0.14 || ^15 || ^16"
3939
},
4040
"dependencies": {
4141
"@babel/runtime": "^7.0.0"
4242
},
4343
"devDependencies": {
4444
"@babel/plugin-transform-runtime": "^7.0.0",
45-
"@types/react": "^16.4.2",
45+
"@types/react": "^0.14 || ^15 || ^16",
4646
"ajv": "^6.5.3",
4747
"babel-plugin-dynamic-import-node": "^2.1.0",
4848
"flowgen": "^1.2.2",
49-
"react": "^16.4.2",
5049
"kcd-scripts": "^0.44.0",
50+
"react": "^0.14 || ^15 || ^16",
51+
"rollup-plugin-babel": "^4.0.3",
5152
"rollup-plugin-commonjs": "^9.1.0",
52-
"rollup-plugin-babel": "^4.0.3"
53+
"semver": "^5.5.1"
5354
},
5455
"eslintConfig": {
5556
"extends": "./node_modules/kcd-scripts/eslint.js"

src/internal/isReactComponent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default renderable => {
2121

2222
return (
2323
type === 'object' &&
24+
renderable.$$typeof !== undefined &&
2425
(renderable.$$typeof === REACT_PROVIDER_TYPE ||
2526
renderable.$$typeof === REACT_CONTEXT_TYPE ||
2627
renderable.$$typeof === REACT_FORWARD_REF_TYPE)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react'
2+
3+
// setup react <16.3.0
4+
// https://github.com/facebook/react/blob/master/packages/shared/ReactSymbols.js
5+
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
6+
// nor polyfill, then a plain number is used for performance.
7+
const hasSymbol = typeof Symbol === 'function' && Symbol.for
8+
9+
const REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd
10+
const REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace
11+
const REACT_FORWARD_REF_TYPE = hasSymbol
12+
? Symbol.for('react.forward_ref')
13+
: 0xead0
14+
15+
if (!React.createContext) {
16+
React.createContext = () => ({
17+
Provider: {$$typeof: REACT_PROVIDER_TYPE},
18+
Consumer: {$$typeof: REACT_CONTEXT_TYPE},
19+
})
20+
}
21+
22+
if (!React.forwardRef) {
23+
React.forwardRef = () => ({$$typeof: REACT_FORWARD_REF_TYPE})
24+
}
25+
26+
let reactSymbols
27+
28+
beforeAll(async () => {
29+
reactSymbols = await import('./reactSymbols')
30+
})
31+
32+
test('react symbols after v16.3.0', () => {
33+
expect(reactSymbols).toEqual({
34+
REACT_CONTEXT_TYPE,
35+
REACT_FORWARD_REF_TYPE,
36+
REACT_PROVIDER_TYPE,
37+
})
38+
})
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22

3-
React.createContext = undefined
4-
React.forwardRef = undefined
3+
if (React.createContext) delete React.createContext
4+
if (React.forwardRef) delete React.forwardRef
55

66
let reactSymbols
77

@@ -12,9 +12,9 @@ beforeAll(async () => {
1212
test('react symbols before v16.3.0', () => {
1313
expect(reactSymbols).toMatchInlineSnapshot(`
1414
Object {
15-
"REACT_CONTEXT_TYPE": undefined,
16-
"REACT_FORWARD_REF_TYPE": undefined,
17-
"REACT_PROVIDER_TYPE": undefined,
15+
"REACT_CONTEXT_TYPE": false,
16+
"REACT_FORWARD_REF_TYPE": false,
17+
"REACT_PROVIDER_TYPE": false,
1818
}
1919
`)
2020
})

src/internal/reactSymbols.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@ import {createContext, forwardRef} from 'react'
22

33
// React.createContext is available since v16.3.0
44
const context =
5-
/*#__PURE__*/ typeof createContext === 'function'
6-
? createContext()
7-
: {Provider: {}, Consumer: {}}
5+
/*#__PURE__*/ typeof createContext === 'function' &&
6+
/*#__PURE__*/ createContext()
87

9-
export const REACT_PROVIDER_TYPE = /*#__PURE__*/ context.Provider.$$typeof
8+
export const REACT_PROVIDER_TYPE = context && context.Provider.$$typeof
109

11-
export const REACT_CONTEXT_TYPE = /*#__PURE__*/ context.Consumer.$$typeof
10+
export const REACT_CONTEXT_TYPE = context && context.Consumer.$$typeof
1211

1312
// React.forwardRef is available since v16.3.0
1413
export const REACT_FORWARD_REF_TYPE =
15-
/*#__PURE__*/ typeof forwardRef === 'function'
16-
? forwardRef(
17-
// need to access both params otherwise react warns
18-
// but as this is never used this is no-op
19-
/* istanbul ignore next line */
20-
(props, ref) => ({props, ref}),
21-
).$$typeof
22-
: undefined
14+
/*#__PURE__*/ typeof forwardRef === 'function' &&
15+
/*#__PURE__*/ forwardRef(
16+
// need to access both params otherwise react warns
17+
// but as this is never used this is no-op
18+
/* istanbul ignore next line */
19+
(props, ref) => ({props, ref}),
20+
).$$typeof

0 commit comments

Comments
 (0)