Skip to content

Commit 6d7fbf4

Browse files
committed
When Float was first developed the internal implementation and external interface were the same. This is problematic for a few reasons. One, the public interface is typed but it is also untrusted and we should not assume that it is actually respected. Two, the internal implementations can get called from places other than the the public interface and having to construct an options argument that ends up being destructured to process the request is computationally wasteful and may limit JIT optimizations to some degree. Lastly, the wire format was not as compressed as it could be and it was untyped.
This refactor aims to address that by separating the public interface from the internal implementations so we can solve these challenges and also make it easier to change Float in the future The internal dispatcher method preinit is now preinitStyle and preinitScript. The internal dispatcher method preinitModule is now preinitModuleScript in anticipation of different implementations for other module types in the future The wire format is explicitly typed and only includes options if they are actually used omitting undefined and nulls. Some function arguments are not options even if they are optional. For instance precedence can be null/undefined because we deafult it to 'default' however we don't cosnider this an option because it is not something we transparently apply as props to the underlying instance. Fixes a problem with keying images in flight wehre srcset and sizes were not being taken into account. Moves argument validation into the ReactDOMFloat file where it is shared with all runtimes that expose these methods
1 parent 41f0e9d commit 6d7fbf4

File tree

14 files changed

+971
-977
lines changed

14 files changed

+971
-977
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import type {
1717
StringDecoder,
1818
} from './ReactFlightClientConfig';
1919

20-
import type {HintModel} from 'react-server/src/ReactFlightServerConfig';
20+
import type {
21+
HintCode,
22+
HintModel,
23+
} from 'react-server/src/ReactFlightServerConfig';
2124

2225
import type {CallServerCallback} from './ReactFlightReplyClient';
2326

@@ -915,12 +918,12 @@ function resolvePostponeDev(
915918
}
916919
}
917920

918-
function resolveHint(
921+
function resolveHint<Code: HintCode>(
919922
response: Response,
920-
code: string,
923+
code: Code,
921924
model: UninitializedModel,
922925
): void {
923-
const hintModel: HintModel = parseModel(response, model);
926+
const hintModel: HintModel<Code> = parseModel(response, model);
924927
dispatchHint(code, hintModel);
925928
}
926929

@@ -1044,7 +1047,7 @@ function processFullRow(
10441047
return;
10451048
}
10461049
case 72 /* "H" */: {
1047-
const code = row[0];
1050+
const code: HintCode = (row[0]: any);
10481051
resolveHint(response, code, row.slice(1));
10491052
return;
10501053
}

0 commit comments

Comments
 (0)