-
Notifications
You must be signed in to change notification settings - Fork 49k
Add Server Context deprecation warning #27424
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
Changes from 1 commit
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 |
---|---|---|
|
@@ -9,21 +9,69 @@ | |
|
||
import type {ReactServerContext} from 'shared/ReactTypes'; | ||
|
||
import {REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED} from 'shared/ReactSymbols'; | ||
import { | ||
REACT_PROVIDER_TYPE, | ||
REACT_SERVER_CONTEXT_TYPE, | ||
REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED, | ||
} from 'shared/ReactSymbols'; | ||
|
||
import ReactSharedInternals from 'shared/ReactSharedInternals'; | ||
import {createServerContext} from 'react'; | ||
|
||
const ContextRegistry = ReactSharedInternals.ContextRegistry; | ||
|
||
export function getOrCreateServerContext( | ||
globalName: string, | ||
): ReactServerContext<any> { | ||
if (!ContextRegistry[globalName]) { | ||
ContextRegistry[globalName] = createServerContext( | ||
globalName, | ||
// $FlowFixMe[incompatible-call] function signature doesn't reflect the symbol value | ||
REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED, | ||
); | ||
const context: ReactServerContext<any> = { | ||
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. why is this inlined now? 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. I think that is because we don’t want to warn when this method is called which is used internally in react 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. Yea and I plan on literally deleting the code soon so meh. |
||
$$typeof: REACT_SERVER_CONTEXT_TYPE, | ||
|
||
// As a workaround to support multiple concurrent renderers, we categorize | ||
// some renderers as primary and others as secondary. We only expect | ||
// there to be two concurrent renderers at most: React Native (primary) and | ||
// Fabric (secondary); React DOM (primary) and React ART (secondary). | ||
// Secondary renderers store their context values on separate fields. | ||
_currentValue: REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED, | ||
_currentValue2: REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED, | ||
|
||
_defaultValue: REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED, | ||
|
||
// Used to track how many concurrent renderers this context currently | ||
// supports within in a single renderer. Such as parallel server rendering. | ||
_threadCount: 0, | ||
// These are circular | ||
Provider: (null: any), | ||
Consumer: (null: any), | ||
_globalName: globalName, | ||
}; | ||
|
||
context.Provider = { | ||
$$typeof: REACT_PROVIDER_TYPE, | ||
_context: context, | ||
}; | ||
|
||
if (__DEV__) { | ||
let hasWarnedAboutUsingConsumer; | ||
context._currentRenderer = null; | ||
context._currentRenderer2 = null; | ||
Object.defineProperties( | ||
context, | ||
({ | ||
Consumer: { | ||
get() { | ||
if (!hasWarnedAboutUsingConsumer) { | ||
console.error( | ||
'Consumer pattern is not supported by ReactServerContext', | ||
); | ||
hasWarnedAboutUsingConsumer = true; | ||
} | ||
return null; | ||
}, | ||
}, | ||
}: any), | ||
); | ||
} | ||
ContextRegistry[globalName] = context; | ||
} | ||
return ContextRegistry[globalName]; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.