-
Notifications
You must be signed in to change notification settings - Fork 47.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
927 additions
and
105 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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
92 changes: 92 additions & 0 deletions
92
packages/react-dom-bindings/src/server/ReactDOMFlightServerFormatConfig.js
This file contains 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,92 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and 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 {enableFloat} from 'shared/ReactFeatureFlags'; | ||
|
||
import {resolveDirectives} from 'react-server/src/ReactFlightDirectives'; | ||
|
||
import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals'; | ||
const ReactDOMCurrentDispatcher = ReactDOMSharedInternals.Dispatcher; | ||
|
||
const ReactDOMFlightServerDispatcher = { | ||
prefetchDNS, | ||
preconnect, | ||
preload, | ||
preinit, | ||
}; | ||
|
||
export function prepareHostDispatcher(): void { | ||
ReactDOMCurrentDispatcher.current = ReactDOMFlightServerDispatcher; | ||
} | ||
|
||
// Used to distinguish these contexts from ones used in other renderers. | ||
// E.g. this can be used to distinguish legacy renderers from this modern one. | ||
export const isPrimaryRenderer = true; | ||
|
||
let didWarnAsyncEnvironmentDev = false; | ||
|
||
export function prefetchDNS(href: string, options?: mixed) { | ||
if (enableFloat) { | ||
pushDirective('prefetchDNS', href, options); | ||
} | ||
} | ||
|
||
export function preconnect(href: string, options?: ?{crossOrigin?: string}) { | ||
if (enableFloat) { | ||
pushDirective('preconnect', href, options); | ||
} | ||
} | ||
|
||
type PreloadOptions = { | ||
as: string, | ||
crossOrigin?: string, | ||
integrity?: string, | ||
type?: string, | ||
}; | ||
|
||
export function preload(href: string, options: PreloadOptions) { | ||
if (enableFloat) { | ||
pushDirective('preload', href, options); | ||
} | ||
} | ||
|
||
type PreinitOptions = { | ||
as: string, | ||
precedence?: string, | ||
crossOrigin?: string, | ||
integrity?: string, | ||
}; | ||
export function preinit(href: string, options: PreinitOptions): void { | ||
if (enableFloat) { | ||
pushDirective('preinit', href, options); | ||
} | ||
} | ||
|
||
function pushDirective( | ||
method: 'prefetchDNS' | 'preconnect' | 'preload' | 'preinit', | ||
href: string, | ||
options: mixed, | ||
): void { | ||
const directives = resolveDirectives(); | ||
if (directives === null) { | ||
if (__DEV__) { | ||
if (!didWarnAsyncEnvironmentDev) { | ||
didWarnAsyncEnvironmentDev = true; | ||
console.error( | ||
'ReactDOM.%s(): React expected to be able to associate this call to a specific Request but cannot. It is possible that this call was invoked outside of a React component. If you are calling it from within a React component that is an async function after the first `await` then you are in an environment which does not support AsyncLocalStorage. In this kind of environment ReactDOM.%s() does not do anything when called in an async manner. Try moving this function call above the first `await` within the component or remove this call. In environments that support AsyncLocalStorage such as Node.js you can call this method anywhere in a React component even after `await` operator.', | ||
method, | ||
method, | ||
); | ||
} | ||
} | ||
return; | ||
} | ||
// @TODO need to escape | ||
directives.push(JSON.stringify({method, args: [href, options]})); | ||
} |
This file contains 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
Oops, something went wrong.