-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serializer: Fix Invariant error related to hooks #15873
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was mostly just to get the ball rolling on one option which is monkey patching the If |
||
/** | ||
* 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 ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moderator note there was some spam commenting on this issue. I reported the user to github and blocked them from this repo