-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Flight] Lazily parse models and allow any value to suspend (#18476)
* Lazily initialize models as they're read intead of eagerly when received This ensures that we don't spend CPU cycles processing models that we're not going to end up rendering. This model will also allow us to suspend during this initialization if data is not yet available to satisfy the model. * Refactoring carefully to ensure bundles still compile to something optimal * Remove generic from Response The root model needs to be cast at one point or another same as othe chunks. So we can parameterize the read instead of the whole Response. * Read roots from the 0 key of the map The special case to read the root isn't worth the field and code. * Store response on each Chunk Instead of storing it on the data tuple which is kind of dynamic, we store it on each Chunk. This uses more memory. Especially compared to just making initializeBlock a closure, but overall is simpler. * Rename private fields to underscores Response objects are exposed. * Encode server components as delayed references This allows us to stream in server components one after another over the wire. It also allows parallelizing their fetches and resuming only the server component instead of the whole parent block. This doesn't yet allow us to suspend deeper while waiting on this content because we don't have "lazy elements".
- Loading branch information
1 parent
59fd09c
commit e2dd308
Showing
14 changed files
with
350 additions
and
213 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
23 changes: 23 additions & 0 deletions
23
packages/react-client/src/ReactFlightClientHostConfigStream.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,23 @@ | ||
/** | ||
* 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 type {ResponseBase} from './ReactFlightClient'; | ||
import type {StringDecoder} from './ReactFlightClientHostConfig'; | ||
|
||
export type Response = ResponseBase & { | ||
_partialRow: string, | ||
_fromJSON: (key: string, value: JSONValue) => any, | ||
_stringDecoder: StringDecoder, | ||
}; | ||
|
||
export type UninitializedModel = string; | ||
|
||
export function parseModel<T>(response: Response, json: UninitializedModel): T { | ||
return JSON.parse(json, response._fromJSON); | ||
} |
Oops, something went wrong.