-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
1 parent
1580a43
commit e0dec33
Showing
13 changed files
with
330 additions
and
17 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
41 changes: 41 additions & 0 deletions
41
packages/react-client/src/ReactFlightTemporaryReferences.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,41 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
interface Reference {} | ||
|
||
export opaque type TemporaryReferenceSet = Array<Reference>; | ||
|
||
export function createTemporaryReferenceSet(): TemporaryReferenceSet { | ||
return []; | ||
} | ||
|
||
export function writeTemporaryReference( | ||
set: TemporaryReferenceSet, | ||
object: Reference, | ||
): number { | ||
// We always create a new entry regardless if we've already written the same | ||
// object. This ensures that we always generate a deterministic encoding of | ||
// each slot in the reply for cacheability. | ||
const newId = set.length; | ||
set.push(object); | ||
return newId; | ||
} | ||
|
||
export function readTemporaryReference( | ||
set: TemporaryReferenceSet, | ||
id: number, | ||
): Reference { | ||
if (id < 0 || id >= set.length) { | ||
throw new Error( | ||
"The RSC response contained a reference that doesn't exist in the temporary reference set. " + | ||
'Always pass the matching set that was used to create the reply when parsing its response.', | ||
); | ||
} | ||
return set[id]; | ||
} |
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
Oops, something went wrong.