Skip to content

Commit 9815e9b

Browse files
committed
Inline react-is symbols to remove peer dependency
1 parent 40a41f6 commit 9815e9b

File tree

4 files changed

+74
-34
lines changed

4 files changed

+74
-34
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@
7272
"lint-staged": "^10.5.1",
7373
"npm-run-all": "^4.1.5",
7474
"prettier": "^2.1.2",
75-
"react": "^17.0.1",
76-
"react-dom": "^17.0.1",
77-
"react-is": "^17.0.1",
75+
"react": "^16.13.1",
76+
"react-dom": "^16.13.1",
7877
"rollup": "^2.33.1",
7978
"rollup-plugin-babel": "^4.4.0",
8079
"rollup-plugin-replace": "^2.2.0",

src/element.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { Children, type Node, type Element, type ComponentType } from 'react'
44
import type { AbstractContext, AbstractElement } from './types'
5-
import * as ReactIs from 'react-is'
65

76
import {
87
type ReactSymbol,
@@ -74,8 +73,7 @@ const toArray: (node?: Node) => Array<ScalarNode | AbstractElement> =
7473
/** Checks whether the `node` is an AbstractElement */
7574
const isAbstractElement = (
7675
node: ScalarNode | AbstractElement
77-
): boolean %checks =>
78-
node !== null && typeof node === 'object'
76+
): boolean %checks => node !== null && typeof node === 'object'
7977

8078
/** Returns a flat AbstractElement array for a given AbstractElement node */
8179
export const getChildrenArray = (node?: Node): AbstractElement[] => {

src/symbols.js

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
11
// @flow
22

33
import type { Node } from 'react'
4-
import * as is from 'react-is'
4+
5+
let Element = 0xeac7
6+
let Portal = 0xeaca
7+
let Fragment = 0xeacb
8+
let StrictMode = 0xeacc
9+
let Profiler = 0xead2
10+
let ContextProvider = 0xeacd
11+
let ContextConsumer = 0xeace
12+
let ConcurrentMode = 0xeacf
13+
let ForwardRef = 0xead0
14+
let Suspense = 0xead1
15+
let Memo = 0xead3
16+
let Lazy = 0xead4
17+
18+
if (typeof Symbol === 'function' && Symbol.for) {
19+
const symbolFor = Symbol.for
20+
Element = symbolFor('react.element')
21+
Portal = symbolFor('react.portal')
22+
Fragment = symbolFor('react.fragment')
23+
StrictMode = symbolFor('react.strict_mode')
24+
Profiler = symbolFor('react.profiler')
25+
ContextProvider = symbolFor('react.provider')
26+
ContextConsumer = symbolFor('react.context')
27+
ConcurrentMode = Symbol.for('react.concurrent_mode')
28+
ForwardRef = symbolFor('react.forward_ref')
29+
Suspense = symbolFor('react.suspense')
30+
Memo = symbolFor('react.memo')
31+
Lazy = symbolFor('react.lazy')
32+
}
533

634
/** Literal types representing the ReactSymbol values. These values do not actually match the values from react-is! */
735
export type ReactSymbol =
@@ -18,16 +46,15 @@ export type ReactSymbol =
1846
| 'react.memo' /* 0xead3 | Symbol(react.memo) */
1947
| 'react.lazy' /* 0xead4 | Symbol(react.lazy) */
2048

21-
export const REACT_ELEMENT_TYPE: 'react.element' = is.Element
22-
export const REACT_PORTAL_TYPE: 'react.portal' = is.Portal
23-
export const REACT_FRAGMENT_TYPE: 'react.fragment' = is.Fragment
24-
export const REACT_STRICT_MODE_TYPE: 'react.strict_mode' = is.StrictMode
25-
export const REACT_PROFILER_TYPE: 'react.profiler' = is.Profiler
26-
export const REACT_PROVIDER_TYPE: 'react.provider' = is.ContextProvider
27-
export const REACT_CONTEXT_TYPE: 'react.context' = is.ContextConsumer
28-
export const REACT_CONCURRENT_MODE_TYPE: 'react.concurrent_mode' =
29-
is.ConcurrentMode
30-
export const REACT_FORWARD_REF_TYPE: 'react.forward_ref' = is.ForwardRef
31-
export const REACT_SUSPENSE_TYPE: 'react.suspense' = is.Suspense
32-
export const REACT_MEMO_TYPE: 'react.memo' = is.Memo
33-
export const REACT_LAZY_TYPE: 'react.lazy' = is.Lazy
49+
export const REACT_ELEMENT_TYPE: 'react.element' = (Element: any)
50+
export const REACT_PORTAL_TYPE: 'react.portal' = (Portal: any)
51+
export const REACT_FRAGMENT_TYPE: 'react.fragment' = (Fragment: any)
52+
export const REACT_STRICT_MODE_TYPE: 'react.strict_mode' = (StrictMode: any)
53+
export const REACT_PROFILER_TYPE: 'react.profiler' = (Profiler: any)
54+
export const REACT_PROVIDER_TYPE: 'react.provider' = (ContextProvider: any)
55+
export const REACT_CONTEXT_TYPE: 'react.context' = (ContextConsumer: any)
56+
export const REACT_CONCURRENT_MODE_TYPE: 'react.concurrent_mode' = (ConcurrentMode: any)
57+
export const REACT_FORWARD_REF_TYPE: 'react.forward_ref' = (ForwardRef: any)
58+
export const REACT_SUSPENSE_TYPE: 'react.suspense' = (Suspense: any)
59+
export const REACT_MEMO_TYPE: 'react.memo' = (Memo: any)
60+
export const REACT_LAZY_TYPE: 'react.lazy' = (Lazy: any)

yarn.lock

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,7 +3656,7 @@ log-update@^4.0.0:
36563656
slice-ansi "^4.0.0"
36573657
wrap-ansi "^6.2.0"
36583658

3659-
loose-envify@^1.1.0:
3659+
loose-envify@^1.1.0, loose-envify@^1.4.0:
36603660
version "1.4.0"
36613661
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
36623662
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
@@ -4171,6 +4171,15 @@ prompts@^2.0.1:
41714171
kleur "^3.0.3"
41724172
sisteransi "^1.0.4"
41734173

4174+
prop-types@^15.6.2:
4175+
version "15.7.2"
4176+
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
4177+
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
4178+
dependencies:
4179+
loose-envify "^1.4.0"
4180+
object-assign "^4.1.1"
4181+
react-is "^16.8.1"
4182+
41744183
psl@^1.1.28:
41754184
version "1.8.0"
41764185
resolved "https://registry.yarnpkg.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24"
@@ -4201,27 +4210,34 @@ randombytes@^2.1.0:
42014210
dependencies:
42024211
safe-buffer "^5.1.0"
42034212

4204-
react-dom@^17.0.1:
4205-
version "17.0.1"
4206-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.1.tgz#1de2560474ec9f0e334285662ede52dbc5426fc6"
4207-
integrity sha512-6eV150oJZ9U2t9svnsspTMrWNyHc6chX0KzDeAOXftRa8bNeOKTTfCJ7KorIwenkHd2xqVTBTCZd79yk/lx/Ug==
4213+
react-dom@^16.13.1:
4214+
version "16.14.0"
4215+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.14.0.tgz#7ad838ec29a777fb3c75c3a190f661cf92ab8b89"
4216+
integrity sha512-1gCeQXDLoIqMgqD3IO2Ah9bnf0w9kzhwN5q4FGnHZ67hBm9yePzB5JJAIQCc8x3pFnNlwFq4RidZggNAAkzWWw==
42084217
dependencies:
42094218
loose-envify "^1.1.0"
42104219
object-assign "^4.1.1"
4211-
scheduler "^0.20.1"
4220+
prop-types "^15.6.2"
4221+
scheduler "^0.19.1"
4222+
4223+
react-is@^16.8.1:
4224+
version "16.13.1"
4225+
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
4226+
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
42124227

42134228
react-is@^17.0.1:
42144229
version "17.0.1"
42154230
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.1.tgz#5b3531bd76a645a4c9fb6e693ed36419e3301339"
42164231
integrity sha512-NAnt2iGDXohE5LI7uBnLnqvLQMtzhkiAOLXTmv+qnF9Ky7xAPcX8Up/xWIhxvLVGJvuLiNc4xQLtuqDRzb4fSA==
42174232

4218-
react@^17.0.1:
4219-
version "17.0.1"
4220-
resolved "https://registry.yarnpkg.com/react/-/react-17.0.1.tgz#6e0600416bd57574e3f86d92edba3d9008726127"
4221-
integrity sha512-lG9c9UuMHdcAexXtigOZLX8exLWkW0Ku29qPRU8uhF2R9BN96dLCt0psvzPLlHc5OWkgymP3qwTRgbnw5BKx3w==
4233+
react@^16.13.1:
4234+
version "16.14.0"
4235+
resolved "https://registry.yarnpkg.com/react/-/react-16.14.0.tgz#94d776ddd0aaa37da3eda8fc5b6b18a4c9a3114d"
4236+
integrity sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==
42224237
dependencies:
42234238
loose-envify "^1.1.0"
42244239
object-assign "^4.1.1"
4240+
prop-types "^15.6.2"
42254241

42264242
read-pkg-up@^7.0.1:
42274243
version "7.0.1"
@@ -4551,10 +4567,10 @@ saxes@^5.0.0:
45514567
dependencies:
45524568
xmlchars "^2.2.0"
45534569

4554-
scheduler@^0.20.1:
4555-
version "0.20.1"
4556-
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.1.tgz#da0b907e24026b01181ecbc75efdc7f27b5a000c"
4557-
integrity sha512-LKTe+2xNJBNxu/QhHvDR14wUXHRQbVY5ZOYpOGWRzhydZUqrLb2JBvLPY7cAqFmqrWuDED0Mjk7013SZiOz6Bw==
4570+
scheduler@^0.19.1:
4571+
version "0.19.1"
4572+
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.19.1.tgz#4f3e2ed2c1a7d65681f4c854fa8c5a1ccb40f196"
4573+
integrity sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==
45584574
dependencies:
45594575
loose-envify "^1.1.0"
45604576
object-assign "^4.1.1"

0 commit comments

Comments
 (0)