Skip to content

Commit 1d8cde0

Browse files
committed
[Flight] Support Blobs from Server to Client (#28755)
We currently support Blobs when passing from Client to Server so this adds it in the other direction for parity - when `enableFlightBinary` is enabled. We intentionally only support the `Blob` type to pass-through, not subtype `File`. That's because passing additional meta data like filename might be an accidental leak. You can still pass a `File` through but it'll appear as a `Blob` on the other side. It's also not possible to create a faithful File subclass in all environments without it actually being backed by a file. This implementation isn't great but at least it works. It creates a few indirections. This is because we need to be able to asynchronously emit the buffers but we have to "block" the parent object from resolving while it's loading. Ideally, we should be able to create the Blob on the client early and then stream in it lazily. Because the Blob API doesn't guarantee that the data is available synchronously. Unfortunately, the native APIs doesn't have this. We could implement custom versions of all the data read APIs but then the blobs still wouldn't work with native APIs. So we just have to wait until Blob accepts a stream in the constructor. We should be able to stream each chunk early in the protocol though even though we can't unblock the parent until they've all loaded. I didn't do this yet mostly because of code structure and I'm lazy. DiffTrain build for [cbb6f2b](cbb6f2b)
1 parent 75004cd commit 1d8cde0

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f33a6b69c6cb406ea0cc51d07bc4d3fd2d8d8744
1+
cbb6f2b5461cdce282c7e47b9c68a0897d393383

compiled/facebook-www/ReactFlightDOMClient-dev.modern.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,10 @@ if (__DEV__) {
835835
return new Set(_data);
836836
}
837837

838+
case "B": {
839+
return undefined;
840+
}
841+
838842
case "I": {
839843
// $Infinity
840844
return Infinity;
@@ -887,9 +891,9 @@ if (__DEV__) {
887891

888892
default: {
889893
// We assume that anything else is a reference ID.
890-
var _id6 = parseInt(value.slice(1), 16);
894+
var _id7 = parseInt(value.slice(1), 16);
891895

892-
var _chunk2 = getChunk(response, _id6);
896+
var _chunk2 = getChunk(response, _id7);
893897

894898
switch (_chunk2.status) {
895899
case RESOLVED_MODEL:

compiled/facebook-www/ReactFlightDOMClient-prod.modern.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ function parseModelString(response, parentObject, key, value) {
294294
(response = getOutlinedModel(response, parentObject)),
295295
new Set(response)
296296
);
297+
case "B":
298+
return;
297299
case "I":
298300
return Infinity;
299301
case "-":

0 commit comments

Comments
 (0)