From c77aadb6637476cbf58faa2153583b82461504b8 Mon Sep 17 00:00:00 2001 From: Darren Ethier Date: Tue, 28 May 2019 21:12:08 -0400 Subject: [PATCH] initial poc but ugly (and likely not usable) --- packages/element/src/serialize.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/element/src/serialize.js b/packages/element/src/serialize.js index 5c2c2a8011d2a..9c46107b9a4d6 100644 --- a/packages/element/src/serialize.js +++ b/packages/element/src/serialize.js @@ -35,7 +35,9 @@ import { startsWith, kebabCase, isPlainObject, + noop, } from 'lodash'; +import { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } from 'react'; /** * WordPress dependencies @@ -54,6 +56,20 @@ import RawHTML from './raw-html'; const { Provider, Consumer } = createContext(); +const Dispatcher = { + readContext: noop, + useContext: noop, + useMemo: noop, + useReducer: () => [], + useRef: () => ( { current: '' } ), + useState: () => [], + useLayoutEffect: noop, + useCallback: noop, + useImperativeHandle: noop, + useEffect: noop, + useDebugValue: noop, +}; + /** * Valid attribute types. * @@ -396,8 +412,14 @@ export function renderElement( element, context, legacyContext = {} ) { if ( type.prototype && typeof type.prototype.render === 'function' ) { return renderComponent( type, props, context, legacyContext ); } - - return renderElement( type( props, legacyContext ), context, legacyContext ); + const prevDispatcher = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher; + __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current = Dispatcher; + const value = renderElement( type( props, legacyContext ), + context, + legacyContext + ); + __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher = prevDispatcher; + return value; } switch ( type && type.$$typeof ) {