|
| 1 | +/** |
| 2 | + * Whether or not the runtime environment supports Symbol.for. Although all |
| 3 | + * supported versions of Node.js (see package engines field) support Symbol, |
| 4 | + * the preload function may be also be used in the browser. |
| 5 | + * @kind constant |
| 6 | + * @name hasSymbol |
| 7 | + * @type {boolean} |
| 8 | + * @see [React source](https://github.com/facebook/react/blob/v16.6.0/packages/shared/ReactSymbols.js#L12). |
| 9 | + * @ignore |
| 10 | + */ |
| 11 | +const hasSymbol = typeof Symbol === 'function' && Symbol.for |
| 12 | + |
| 13 | +/** |
| 14 | + * Symbol for React context consumer components. The bundle impact is too big to |
| 15 | + * import it the propper way from [`react-is`](https://npm.im/react-is). Also |
| 16 | + * [babel/babel#7998](https://github.com/babel/babel/issues/7998) would cause a |
| 17 | + * CJS runtime error. |
| 18 | + * @kind constant |
| 19 | + * @name REACT_CONTEXT_TYPE |
| 20 | + * @see [React source](https://github.com/facebook/react/blob/v16.6.0/packages/shared/ReactSymbols.js#L32). |
| 21 | + * @ignore |
| 22 | + */ |
| 23 | +const REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace |
| 24 | + |
1 | 25 | /**
|
2 | 26 | * Recursively preloads [`Query`]{@link Query} components that have the
|
3 | 27 | * `loadOnMount` prop in a React element tree. Useful for server side rendering
|
@@ -64,15 +88,16 @@ export function preload(element) {
|
64 | 88 | // The element is not a childless string or number and…
|
65 | 89 | element.type &&
|
66 | 90 | // …It’s a context consumer or a functional/class component…
|
67 |
| - (element.type.Consumer || typeof element.type === 'function') |
| 91 | + (element.type.$$typeof === REACT_CONTEXT_TYPE || |
| 92 | + typeof element.type === 'function') |
68 | 93 | ) {
|
69 | 94 | // Determine the component props.
|
70 | 95 | const props = { ...element.type.defaultProps, ...element.props }
|
71 | 96 |
|
72 |
| - if (element.type.Consumer) |
| 97 | + if (element.type.$$typeof === REACT_CONTEXT_TYPE) |
73 | 98 | // Context consumer element.
|
74 | 99 | recurse(
|
75 |
| - element.props.children(element.type.currentValue), |
| 100 | + element.props.children(element.type._context.currentValue), |
76 | 101 | legacyContext
|
77 | 102 | )
|
78 | 103 | else if (
|
|
0 commit comments