-
Notifications
You must be signed in to change notification settings - Fork 49.8k
[ServerContext] Flight support for ServerContext #23244
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
87 commits
Select commit
Hold shift + click to select a range
f75b5d3
Flight side of server context
salazarm 29e80db
1 more test
salazarm 54e8812
rm unused function
salazarm e148a0a
flow+prettier
salazarm 532dfa2
flow again =)
salazarm f2868c2
duplicate ReactServerContext across packages
salazarm a861492
store default value when lazily initializing server context
salazarm fb521be
.
salazarm a7051aa
better comment
salazarm 066b206
derp... missing import
salazarm 7706ed7
rm optional chaining
salazarm 8bb4359
missed feature flag
salazarm 03f08ba
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ??
salazarm 9948c43
add warning if non ServerContext passed into useServerContext
salazarm 0bb2d55
pass context in as array of arrays
salazarm 0dc363f
make importServerContext nott pollute the global context state
salazarm 637ad8b
Merge branch 'main' into flightServerContext
salazarm be811ec
merge main
salazarm 3c8ec09
remove useServerContext
salazarm 9c7e061
dont rely on object getters in ReactServerContext and disallow JSX
salazarm 6f71944
add symbols to devtools + rename globalServerContextRegistry to just …
salazarm d74b7bd
gate test case as experimental
salazarm 4d9d014
feedback
salazarm de7f685
remove unions
salazarm 079691e
Lint
salazarm cb66687
fix oopsies (tests/lint/mismatching arguments/signatures
salazarm 0946c5d
lint again
salazarm 64c6477
replace-fork
salazarm 1f5e888
remove extraneous change
salazarm 8323eb8
rebase
salazarm 640c4a8
1 more test
salazarm c83c3cc
rm unused function
salazarm 64621f0
flow+prettier
salazarm 905d184
flow again =)
salazarm 42ca798
duplicate ReactServerContext across packages
salazarm 4457295
store default value when lazily initializing server context
salazarm a69065b
.
salazarm ef20b40
better comment
salazarm c5a58d3
derp... missing import
salazarm 6124a34
rm optional chaining
salazarm fd1465e
missed feature flag
salazarm ebe8a1e
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ??
salazarm 4e8a2d2
add warning if non ServerContext passed into useServerContext
salazarm 72dbc55
pass context in as array of arrays
salazarm 6e4ed97
make importServerContext nott pollute the global context state
salazarm c5988f2
merge main
salazarm 5397db6
remove useServerContext
salazarm 9d30d7b
dont rely on object getters in ReactServerContext and disallow JSX
salazarm 50594a2
add symbols to devtools + rename globalServerContextRegistry to just …
salazarm 43a71b2
gate test case as experimental
salazarm 69a9ccd
feedback
salazarm bc03997
remove unions
salazarm 499f20b
Lint
salazarm b5e5e47
fix oopsies (tests/lint/mismatching arguments/signatures
salazarm 90f6f08
lint again
salazarm 672712e
replace-fork
salazarm 03fb89b
remove extraneous change
salazarm db992af
rebase
salazarm 9ceb955
reinline
salazarm d0d8f5d
Merge branch 'flightServerContext' of github.com:salazarm/react into …
salazarm eafb265
rebase
salazarm 5b937ad
add back changes lost due to rebase being hard
salazarm 06b6008
emit chunk for provider
salazarm c83bc66
remove case for React provider type
salazarm 534d370
update type for SomeChunk
salazarm 8283b4b
enable flag with experimental
salazarm c596825
add missing types
salazarm 04293a0
fix flow type
salazarm 4b780b5
missing type
salazarm dc4081d
t: any
salazarm ff6269f
revert extraneous type change
salazarm f5a8b25
better type
salazarm a714680
better type
salazarm 81f798f
feedback
salazarm 72ed1cc
Merge branch 'main' of github.com:salazarm/react into flightServerCon…
salazarm 4b808b1
change import to type import
salazarm 463047c
test?
salazarm 3d16208
test?
salazarm 1c4eaf9
remove react-dom
salazarm af300fc
remove react-native-renderer from react-server-native-relay/package.json
salazarm 9333935
gate change in FiberNewContext, getComponentNameFromType, use switch …
salazarm 2d5129c
getComponentNameFromTpe: server context type gated and use displayNam…
salazarm 573d394
fallthrough
salazarm 26c5667
lint....
salazarm 83fcb8b
Merge branch 'main' into flightServerContext
salazarm 278499d
POP
salazarm b6bbe30
lint
salazarm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /** | ||
| * Copyright (c) Facebook, Inc. and its affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| * | ||
| * @flow | ||
| */ | ||
|
|
||
| import { | ||
| REACT_PROVIDER_TYPE, | ||
| REACT_SERVER_CONTEXT_TYPE, | ||
| } from 'shared/ReactSymbols'; | ||
|
|
||
| import type { | ||
| ReactServerContext, | ||
| ServerContextJSONValue, | ||
| } from 'shared/ReactTypes'; | ||
|
|
||
| import ReactSharedInternals from 'shared/ReactSharedInternals'; | ||
|
|
||
| import {enableServerContext} from 'shared/ReactFeatureFlags'; | ||
|
|
||
| const globalServerContextRegistry = | ||
| ReactSharedInternals.globalServerContextRegistry; | ||
|
|
||
| export function createServerContext<T: ServerContextJSONValue>( | ||
| globalName: string, | ||
| defaultValue: T, | ||
| ): ReactServerContext<T> { | ||
| if (!enableServerContext) { | ||
| throw new Error('Not implemented.'); | ||
| } | ||
| if (!globalServerContextRegistry[globalName]) { | ||
| globalServerContextRegistry[globalName] = _createServerContext( | ||
| globalName, | ||
| defaultValue, | ||
| ); | ||
| } | ||
| const context = globalServerContextRegistry[globalName]; | ||
| if (!context._definitionLoaded) { | ||
| context._currentValue = defaultValue; | ||
| context._currentValue2 = defaultValue; | ||
| context._definitionLoaded = true; | ||
| } else { | ||
| throw new Error(`ServerContext: ${globalName} already defined`); | ||
| } | ||
| return context; | ||
| } | ||
|
|
||
| function _createServerContext<T: ServerContextJSONValue>( | ||
| globalName: string, | ||
| defaultValue?: T, | ||
| ): ReactServerContext<T> { | ||
| const context: ReactServerContext<T> = { | ||
| $$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: (defaultValue: any), | ||
| _currentValue2: (defaultValue: any), | ||
| // Used to track how many concurrent renderers this context currently | ||
| // supports within in a single renderer. Such as parallel server rendering. | ||
| _threadCount: 0, | ||
| _definitionLoaded: false, | ||
| // These are circular | ||
| Provider: (null: any), | ||
| displayName: globalName, | ||
| }; | ||
|
|
||
| context.Provider = { | ||
| $$typeof: REACT_PROVIDER_TYPE, | ||
| _context: context, | ||
| }; | ||
|
|
||
| if (__DEV__) { | ||
| context._currentRenderer = null; | ||
| context._currentRenderer2 = null; | ||
| } | ||
| globalServerContextRegistry[globalName] = context; | ||
| return context; | ||
| } | ||
|
|
||
| // This function is called by FlightClient to create a server context sent from | ||
| // the server. Its possible that FlightClient is creating it before the | ||
| // definition is loaded on the server. We'll create it with a null default value | ||
| // if thats the case and when the definition loads it will set the correct | ||
| // default value. | ||
| export function getOrCreateServerContext(globalName: string) { | ||
| if (!globalServerContextRegistry[globalName]) { | ||
| globalServerContextRegistry[globalName] = _createServerContext( | ||
| globalName, | ||
| undefined, | ||
| ); | ||
| } | ||
| return globalServerContextRegistry[globalName]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /** | ||
| * Copyright (c) Facebook, Inc. and its affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| * | ||
| * @flow | ||
| */ | ||
|
|
||
| import { | ||
| REACT_PROVIDER_TYPE, | ||
| REACT_SERVER_CONTEXT_TYPE, | ||
| } from 'shared/ReactSymbols'; | ||
|
|
||
| import type { | ||
| ReactServerContext, | ||
| ServerContextJSONValue, | ||
| } from 'shared/ReactTypes'; | ||
|
|
||
| import {enableServerContext} from 'shared/ReactFeatureFlags'; | ||
| import ReactSharedInternals from 'shared/ReactSharedInternals'; | ||
|
|
||
| const globalServerContextRegistry = | ||
| ReactSharedInternals.globalServerContextRegistry; | ||
|
|
||
| export function createServerContext<T: ServerContextJSONValue>( | ||
| globalName: string, | ||
| defaultValue: T, | ||
| ): ReactServerContext<T> { | ||
| if (!enableServerContext) { | ||
| throw new Error('Not implemented.'); | ||
| } | ||
| if (!globalServerContextRegistry[globalName]) { | ||
| globalServerContextRegistry[globalName] = _createServerContext( | ||
| globalName, | ||
| defaultValue, | ||
| ); | ||
| } | ||
| const context = globalServerContextRegistry[globalName]; | ||
| if (!context._definitionLoaded) { | ||
| context._currentValue = defaultValue; | ||
| context._currentValue2 = defaultValue; | ||
| context._definitionLoaded = true; | ||
| } else { | ||
| throw new Error(`ServerContext: ${globalName} already defined`); | ||
| } | ||
| return context; | ||
| } | ||
|
|
||
| function _createServerContext<T: ServerContextJSONValue>( | ||
| globalName: string, | ||
| defaultValue?: T, | ||
| ): ReactServerContext<T> { | ||
| const context: ReactServerContext<T> = { | ||
| $$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: (defaultValue: any), | ||
| _currentValue2: (defaultValue: any), | ||
| // Used to track how many concurrent renderers this context currently | ||
| // supports within in a single renderer. Such as parallel server rendering. | ||
| _threadCount: 0, | ||
| _definitionLoaded: false, | ||
| // These are circular | ||
| Provider: (null: any), | ||
| displayName: globalName, | ||
| }; | ||
|
|
||
| context.Provider = { | ||
| $$typeof: REACT_PROVIDER_TYPE, | ||
| _context: context, | ||
| }; | ||
|
|
||
| if (__DEV__) { | ||
| context._currentRenderer = null; | ||
| context._currentRenderer2 = null; | ||
| } | ||
| globalServerContextRegistry[globalName] = context; | ||
| return context; | ||
| } | ||
|
|
||
| // This function is called by FlightClient to create a server context sent from | ||
| // the server. Its possible that FlightClient is creating it before the | ||
| // definition is loaded on the server. We'll create it with a null default value | ||
| // if thats the case and when the definition loads it will set the correct | ||
| // default value. | ||
| export function getOrCreateServerContext(globalName: string) { | ||
| if (!globalServerContextRegistry[globalName]) { | ||
| globalServerContextRegistry[globalName] = _createServerContext( | ||
| globalName, | ||
| undefined, | ||
| ); | ||
| } | ||
| return globalServerContextRegistry[globalName]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import type {ReactServerContext} from 'shared/ReactTypes'; | ||
|
|
||
| export const globalServerContextRegistry: { | ||
| [globalName: string]: ReactServerContext<any>, | ||
| } = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.