Skip to content

Commit 5e42791

Browse files
authored
[noop] Typecheck react-noop-renderer against host config and renderer API (#35944)
1 parent ee4699f commit 5e42791

21 files changed

Lines changed: 782 additions & 65 deletions

‎packages/react-client/flight.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@
77
* @flow
88
*/
99

10+
importtypeof*asFlightClientAPIfrom'./src/ReactFlightClient';
11+
importtypeof*asHostConfigfrom'./src/ReactFlightClientConfig';
12+
1013
export*from'./src/ReactFlightClient';
14+
15+
// At build time, this module is wrapped as a factory function ($$$reconciler).
16+
// Consumers pass a host config object and get back the Flight client API.
17+
declareexportdefault(hostConfig: HostConfig)=>FlightClientAPI;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
// This is a host config that's used for the internal `react-noop-renderer` package.
11+
//
12+
// Its API lets you pass the host config as an argument.
13+
// However, inside the `react-server` we treat host config as a module.
14+
// This file is a shim between two worlds.
15+
//
16+
// It works because the `react-server` bundle is wrapped in something like:
17+
//
18+
// module.exports = function ($$$config) {
19+
// /* renderer code */
20+
// }
21+
//
22+
// So `$$$config` looks like a global variable, but it's
23+
// really an argument to a top-level wrapping function.
24+
25+
declareconst $$$config: $FlowFixMe;
26+
27+
exportopaquetypeModuleLoading=mixed;
28+
exportopaquetypeServerConsumerModuleMap=mixed;
29+
exportopaquetypeServerManifest=mixed;
30+
exportopaquetypeServerReferenceId=string;
31+
exportopaquetypeClientReferenceMetadata=mixed;
32+
exportopaquetypeClientReference<T>=mixed;// eslint-disable-line no-unused-vars
33+
exportconstresolveClientReference=$$$config.resolveClientReference;
34+
exportconstresolveServerReference=$$$config.resolveServerReference;
35+
exportconstpreloadModule=$$$config.preloadModule;
36+
exportconstrequireModule=$$$config.requireModule;
37+
exportconstgetModuleDebugInfo=$$$config.getModuleDebugInfo;
38+
exportconstdispatchHint=$$$config.dispatchHint;
39+
exportconstprepareDestinationForModule=
40+
$$$config.prepareDestinationForModule;
41+
exportconstusedWithSSR=true;
42+
43+
exportopaquetypeSource=mixed;
44+
45+
exportopaquetypeStringDecoder=mixed;
46+
47+
exportconstcreateStringDecoder=$$$config.createStringDecoder;
48+
exportconstreadPartialStringChunk=$$$config.readPartialStringChunk;
49+
exportconstreadFinalStringChunk=$$$config.readFinalStringChunk;
50+
51+
exportconstbindToConsole=$$$config.bindToConsole;
52+
53+
exportconstrendererVersion=$$$config.rendererVersion;
54+
exportconstrendererPackageName=$$$config.rendererPackageName;
55+
56+
exportconstcheckEvalAvailabilityOnceDev=
57+
$$$config.checkEvalAvailabilityOnceDev;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
exporttypeHostContext=Object;
11+
12+
exporttypeTextInstance={
13+
text: string,
14+
id: number,
15+
parent: number,
16+
hidden: boolean,
17+
context: HostContext,
18+
};
19+
20+
exporttypeInstance={
21+
type: string,
22+
id: number,
23+
parent: number,
24+
children: Array<Instance|TextInstance>,
25+
text: string|null,
26+
prop: any,
27+
hidden: boolean,
28+
context: HostContext,
29+
};
30+
31+
exporttypePublicInstance=Instance;
32+
33+
exporttypeTransitionStatus=mixed;

‎packages/react-noop-renderer/src/ReactNoop.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const {
5353
getRoot,
5454
// TODO: Remove this after callers migrate to alternatives.
5555
unstable_runWithPriority,
56+
// $FlowFixMe[signature-verification-failure]
5657
}=createReactNoop(
5758
ReactFiberReconciler,// reconciler
5859
true,// useMutation

‎packages/react-noop-renderer/src/ReactNoopFlightClient.js‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* environment.
1515
*/
1616

17+
importtype{Thenable}from'shared/ReactTypes';
1718
importtype{FindSourceMapURLCallback}from'react-client/flight';
1819

1920
import{readModule}from'react-noop-renderer/flight-modules';
@@ -25,6 +26,7 @@ type Source = Array<Uint8Array>;
2526
constdecoderOptions={stream: true};
2627

2728
const{createResponse, createStreamState, processBinaryChunk, getRoot, close}=
29+
// $FlowFixMe[prop-missing]
2830
ReactFlightClient({
2931
createStringDecoder(){
3032
returnnewTextDecoder();
@@ -44,6 +46,7 @@ const {createResponse, createStreamState, processBinaryChunk, getRoot, close} =
4446
returnreadModule(idx);
4547
},
4648
bindToConsole(methodName,args,badgeName){
49+
// $FlowFixMe[incompatible-call]
4750
returnFunction.prototype.bind.apply(
4851
// eslint-disable-next-line react-internal/no-production-logging
4952
console[methodName],
@@ -61,8 +64,10 @@ type ReadOptions = {|
6164

6265
functionread<T>(source: Source, options: ReadOptions): Thenable<T>{
6366
constresponse=createResponse(
67+
// $FlowFixMe[incompatible-call]
6468
source,
6569
null,
70+
// $FlowFixMe[incompatible-call]
6671
null,
6772
undefined,
6873
undefined,
@@ -73,12 +78,19 @@ function read<T>(source: Source, options: ReadOptions): Thenable<T> {
7378
true,
7479
undefined,
7580
__DEV__&&options!==undefined&&options.debugChannel!==undefined
76-
? options.debugChannel.onMessage
81+
? // $FlowFixMe[incompatible-call]
82+
options.debugChannel.onMessage
7783
: undefined,
7884
);
7985
conststreamState=createStreamState(response,source);
8086
for(leti=0;i<source.length;i++){
81-
processBinaryChunk(response,streamState,source[i],0);
87+
processBinaryChunk(
88+
response,
89+
streamState,
90+
source[i],
91+
// $FlowFixMe[extra-arg]
92+
0,
93+
);
8294
}
8395
if (options !== undefined &&options.close){
8496
close(response);

‎packages/react-noop-renderer/src/ReactNoopFlightServer.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import {saveModule} from 'react-noop-renderer/flight-modules';
2020

2121
importReactFlightServerfrom'react-server/flight';
2222

23-
typeDestination=Array<Uint8Array>;
23+
typeDestination=Array<Uint8Array|string>;
2424

2525
consttextEncoder=newTextEncoder();
2626

27+
// $FlowFixMe[prop-missing]
2728
constReactNoopFlightServer=ReactFlightServer({
2829
scheduleMicrotask(callback: ()=>void){
2930
callback();
@@ -81,13 +82,15 @@ function render(model: ReactClientValue, options?: Options): Destination {
8182
constbundlerConfig=undefined;
8283
constrequest=ReactNoopFlightServer.createRequest(
8384
model,
85+
// $FlowFixMe[incompatible-call]
8486
bundlerConfig,
8587
options ? options.onError : undefined,
8688
options ? options.identifierPrefix : undefined,
8789
undefined,
8890
options ? options.startTime : undefined,
8991
__DEV__&&options ? options.environmentName : undefined,
9092
__DEV__&&options ? options.filterStackFrame : undefined,
93+
// $FlowFixMe[incompatible-call]
9194
__DEV__&&options&&options.debugChannel!==undefined,
9295
);
9396
constsignal=options ? options.signal : undefined;
@@ -108,7 +111,11 @@ function render(model: ReactClientValue, options?: Options): Destination {
108111
};
109112
}
110113
ReactNoopFlightServer.startWork(request);
111-
ReactNoopFlightServer.startFlowing(request,destination);
114+
ReactNoopFlightServer.startFlowing(
115+
request,
116+
// $FlowFixMe[incompatible-call]
117+
destination,
118+
);
112119
returndestination;
113120
}
114121

‎packages/react-noop-renderer/src/ReactNoopPersistent.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const {
5555
// TODO: Remove this once callers migrate to alternatives.
5656
// This should only be used by React internals.
5757
unstable_runWithPriority,
58+
// $FlowFixMe[signature-verification-failure]
5859
}=createReactNoop(
5960
ReactFiberReconciler,// reconciler
6061
false,// useMutation

‎packages/react-noop-renderer/src/ReactNoopServer.js‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ type SuspenseInstance = {
4040
};
4141

4242
typePlaceholder={
43-
parent: Instance|SuspenseInstance,
43+
parent: Instance|Segment|SuspenseInstance,
4444
index: number,
4545
};
4646

4747
typeSegment={
48-
children: null|Instance|TextInstance|SuspenseInstance,
48+
children: Array<Instance|TextInstance|SuspenseInstance>,
4949
};
5050

5151
typeDestination={
@@ -79,6 +79,7 @@ function write(destination: Destination, buffer: Uint8Array): void {
7979
stack.push(instance);
8080
}
8181

82+
// $FlowFixMe[prop-missing]
8283
constReactNoopServer=ReactFizzServer({
8384
scheduleMicrotask(callback: ()=>void){
8485
callback();
@@ -175,6 +176,7 @@ const ReactNoopServer = ReactFizzServer({
175176
destination: Destination,
176177
renderState: RenderState,
177178
id: number,
179+
// $FlowFixMe[incompatible-return]
178180
): boolean{
179181
constparent=destination.stack[destination.stack.length-1];
180182
destination.placeholders.set(id,{
@@ -258,7 +260,7 @@ const ReactNoopServer = ReactFizzServer({
258260
formatContext: null,
259261
id: number,
260262
): boolean{
261-
constsegment={
263+
constsegment: Segment={
262264
children: [],
263265
};
264266
destination.segments.set(id,segment);
@@ -314,6 +316,7 @@ const ReactNoopServer = ReactFizzServer({
314316
renderState: RenderState,
315317
boundary: SuspenseInstance,
316318
): boolean{
319+
// $FlowFixMe[prop-missing]
317320
boundary.status='client-render';
318321
returntrue;
319322
},
@@ -357,6 +360,7 @@ type Options = {
357360
};
358361

359362
functionrender(children: React$Element<any>,options?: Options): Destination{
363+
// $FlowFixMe[prop-missing]
360364
constdestination: Destination={
361365
root: null,
362366
placeholders: newMap(),
@@ -368,15 +372,19 @@ function render(children: React$Element<any>, options?: Options): Destination {
368372
};
369373
constrequest=ReactNoopServer.createRequest(
370374
children,
375+
// $FlowFixMe[incompatible-call]
371376
null,
377+
// $FlowFixMe[incompatible-call]
372378
null,
379+
// $FlowFixMe[incompatible-call]
373380
null,
374381
options ? options.progressiveChunkSize : undefined,
375382
options ? options.onError : undefined,
376383
options ? options.onAllReady : undefined,
377384
options ? options.onShellReady : undefined,
378385
);
379386
ReactNoopServer.startWork(request);
387+
// $FlowFixMe[incompatible-call]
380388
ReactNoopServer.startFlowing(request,destination);
381389
returndestination;
382390
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
[noop] Typecheck `react-noop-renderer` against host config and render… · react/react@5e42791 · GitHub
Skip to content

Commit 5e42791

Browse files
authored
[noop] Typecheck react-noop-renderer against host config and renderer API (#35944)
1 parent ee4699f commit 5e42791

21 files changed

Lines changed: 782 additions & 65 deletions

‎packages/react-client/flight.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@
77
* @flow
88
*/
99

10+
importtypeof*asFlightClientAPIfrom'./src/ReactFlightClient';
11+
importtypeof*asHostConfigfrom'./src/ReactFlightClientConfig';
12+
1013
export*from'./src/ReactFlightClient';
14+
15+
// At build time, this module is wrapped as a factory function ($$$reconciler).
16+
// Consumers pass a host config object and get back the Flight client API.
17+
declareexportdefault(hostConfig: HostConfig)=>FlightClientAPI;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
// This is a host config that's used for the internal `react-noop-renderer` package.
11+
//
12+
// Its API lets you pass the host config as an argument.
13+
// However, inside the `react-server` we treat host config as a module.
14+
// This file is a shim between two worlds.
15+
//
16+
// It works because the `react-server` bundle is wrapped in something like:
17+
//
18+
// module.exports = function ($$$config) {
19+
// /* renderer code */
20+
// }
21+
//
22+
// So `$$$config` looks like a global variable, but it's
23+
// really an argument to a top-level wrapping function.
24+
25+
declareconst $$$config: $FlowFixMe;
26+
27+
exportopaquetypeModuleLoading=mixed;
28+
exportopaquetypeServerConsumerModuleMap=mixed;
29+
exportopaquetypeServerManifest=mixed;
30+
exportopaquetypeServerReferenceId=string;
31+
exportopaquetypeClientReferenceMetadata=mixed;
32+
exportopaquetypeClientReference<T>=mixed;// eslint-disable-line no-unused-vars
33+
exportconstresolveClientReference=$$$config.resolveClientReference;
34+
exportconstresolveServerReference=$$$config.resolveServerReference;
35+
exportconstpreloadModule=$$$config.preloadModule;
36+
exportconstrequireModule=$$$config.requireModule;
37+
exportconstgetModuleDebugInfo=$$$config.getModuleDebugInfo;
38+
exportconstdispatchHint=$$$config.dispatchHint;
39+
exportconstprepareDestinationForModule=
40+
$$$config.prepareDestinationForModule;
41+
exportconstusedWithSSR=true;
42+
43+
exportopaquetypeSource=mixed;
44+
45+
exportopaquetypeStringDecoder=mixed;
46+
47+
exportconstcreateStringDecoder=$$$config.createStringDecoder;
48+
exportconstreadPartialStringChunk=$$$config.readPartialStringChunk;
49+
exportconstreadFinalStringChunk=$$$config.readFinalStringChunk;
50+
51+
exportconstbindToConsole=$$$config.bindToConsole;
52+
53+
exportconstrendererVersion=$$$config.rendererVersion;
54+
exportconstrendererPackageName=$$$config.rendererPackageName;
55+
56+
exportconstcheckEvalAvailabilityOnceDev=
57+
$$$config.checkEvalAvailabilityOnceDev;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
exporttypeHostContext=Object;
11+
12+
exporttypeTextInstance={
13+
text: string,
14+
id: number,
15+
parent: number,
16+
hidden: boolean,
17+
context: HostContext,
18+
};
19+
20+
exporttypeInstance={
21+
type: string,
22+
id: number,
23+
parent: number,
24+
children: Array<Instance|TextInstance>,
25+
text: string|null,
26+
prop: any,
27+
hidden: boolean,
28+
context: HostContext,
29+
};
30+
31+
exporttypePublicInstance=Instance;
32+
33+
exporttypeTransitionStatus=mixed;

‎packages/react-noop-renderer/src/ReactNoop.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const {
5353
getRoot,
5454
// TODO: Remove this after callers migrate to alternatives.
5555
unstable_runWithPriority,
56+
// $FlowFixMe[signature-verification-failure]
5657
}=createReactNoop(
5758
ReactFiberReconciler,// reconciler
5859
true,// useMutation

‎packages/react-noop-renderer/src/ReactNoopFlightClient.js‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* environment.
1515
*/
1616

17+
importtype{Thenable}from'shared/ReactTypes';
1718
importtype{FindSourceMapURLCallback}from'react-client/flight';
1819

1920
import{readModule}from'react-noop-renderer/flight-modules';
@@ -25,6 +26,7 @@ type Source = Array<Uint8Array>;
2526
constdecoderOptions={stream: true};
2627

2728
const{createResponse, createStreamState, processBinaryChunk, getRoot, close}=
29+
// $FlowFixMe[prop-missing]
2830
ReactFlightClient({
2931
createStringDecoder(){
3032
returnnewTextDecoder();
@@ -44,6 +46,7 @@ const {createResponse, createStreamState, processBinaryChunk, getRoot, close} =
4446
returnreadModule(idx);
4547
},
4648
bindToConsole(methodName,args,badgeName){
49+
// $FlowFixMe[incompatible-call]
4750
returnFunction.prototype.bind.apply(
4851
// eslint-disable-next-line react-internal/no-production-logging
4952
console[methodName],
@@ -61,8 +64,10 @@ type ReadOptions = {|
6164

6265
functionread<T>(source: Source, options: ReadOptions): Thenable<T>{
6366
constresponse=createResponse(
67+
// $FlowFixMe[incompatible-call]
6468
source,
6569
null,
70+
// $FlowFixMe[incompatible-call]
6671
null,
6772
undefined,
6873
undefined,
@@ -73,12 +78,19 @@ function read<T>(source: Source, options: ReadOptions): Thenable<T> {
7378
true,
7479
undefined,
7580
__DEV__&&options!==undefined&&options.debugChannel!==undefined
76-
? options.debugChannel.onMessage
81+
? // $FlowFixMe[incompatible-call]
82+
options.debugChannel.onMessage
7783
: undefined,
7884
);
7985
conststreamState=createStreamState(response,source);
8086
for(leti=0;i<source.length;i++){
81-
processBinaryChunk(response,streamState,source[i],0);
87+
processBinaryChunk(
88+
response,
89+
streamState,
90+
source[i],
91+
// $FlowFixMe[extra-arg]
92+
0,
93+
);
8294
}
8395
if (options !== undefined &&options.close){
8496
close(response);

‎packages/react-noop-renderer/src/ReactNoopFlightServer.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import {saveModule} from 'react-noop-renderer/flight-modules';
2020

2121
importReactFlightServerfrom'react-server/flight';
2222

23-
typeDestination=Array<Uint8Array>;
23+
typeDestination=Array<Uint8Array|string>;
2424

2525
consttextEncoder=newTextEncoder();
2626

27+
// $FlowFixMe[prop-missing]
2728
constReactNoopFlightServer=ReactFlightServer({
2829
scheduleMicrotask(callback: ()=>void){
2930
callback();
@@ -81,13 +82,15 @@ function render(model: ReactClientValue, options?: Options): Destination {
8182
constbundlerConfig=undefined;
8283
constrequest=ReactNoopFlightServer.createRequest(
8384
model,
85+
// $FlowFixMe[incompatible-call]
8486
bundlerConfig,
8587
options ? options.onError : undefined,
8688
options ? options.identifierPrefix : undefined,
8789
undefined,
8890
options ? options.startTime : undefined,
8991
__DEV__&&options ? options.environmentName : undefined,
9092
__DEV__&&options ? options.filterStackFrame : undefined,
93+
// $FlowFixMe[incompatible-call]
9194
__DEV__&&options&&options.debugChannel!==undefined,
9295
);
9396
constsignal=options ? options.signal : undefined;
@@ -108,7 +111,11 @@ function render(model: ReactClientValue, options?: Options): Destination {
108111
};
109112
}
110113
ReactNoopFlightServer.startWork(request);
111-
ReactNoopFlightServer.startFlowing(request,destination);
114+
ReactNoopFlightServer.startFlowing(
115+
request,
116+
// $FlowFixMe[incompatible-call]
117+
destination,
118+
);
112119
returndestination;
113120
}
114121

‎packages/react-noop-renderer/src/ReactNoopPersistent.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const {
5555
// TODO: Remove this once callers migrate to alternatives.
5656
// This should only be used by React internals.
5757
unstable_runWithPriority,
58+
// $FlowFixMe[signature-verification-failure]
5859
}=createReactNoop(
5960
ReactFiberReconciler,// reconciler
6061
false,// useMutation

‎packages/react-noop-renderer/src/ReactNoopServer.js‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ type SuspenseInstance = {
4040
};
4141

4242
typePlaceholder={
43-
parent: Instance|SuspenseInstance,
43+
parent: Instance|Segment|SuspenseInstance,
4444
index: number,
4545
};
4646

4747
typeSegment={
48-
children: null|Instance|TextInstance|SuspenseInstance,
48+
children: Array<Instance|TextInstance|SuspenseInstance>,
4949
};
5050

5151
typeDestination={
@@ -79,6 +79,7 @@ function write(destination: Destination, buffer: Uint8Array): void {
7979
stack.push(instance);
8080
}
8181

82+
// $FlowFixMe[prop-missing]
8283
constReactNoopServer=ReactFizzServer({
8384
scheduleMicrotask(callback: ()=>void){
8485
callback();
@@ -175,6 +176,7 @@ const ReactNoopServer = ReactFizzServer({
175176
destination: Destination,
176177
renderState: RenderState,
177178
id: number,
179+
// $FlowFixMe[incompatible-return]
178180
): boolean{
179181
constparent=destination.stack[destination.stack.length-1];
180182
destination.placeholders.set(id,{
@@ -258,7 +260,7 @@ const ReactNoopServer = ReactFizzServer({
258260
formatContext: null,
259261
id: number,
260262
): boolean{
261-
constsegment={
263+
constsegment: Segment={
262264
children: [],
263265
};
264266
destination.segments.set(id,segment);
@@ -314,6 +316,7 @@ const ReactNoopServer = ReactFizzServer({
314316
renderState: RenderState,
315317
boundary: SuspenseInstance,
316318
): boolean{
319+
// $FlowFixMe[prop-missing]
317320
boundary.status='client-render';
318321
returntrue;
319322
},
@@ -357,6 +360,7 @@ type Options = {
357360
};
358361

359362
functionrender(children: React$Element<any>,options?: Options): Destination{
363+
// $FlowFixMe[prop-missing]
360364
constdestination: Destination={
361365
root: null,
362366
placeholders: newMap(),
@@ -368,15 +372,19 @@ function render(children: React$Element<any>, options?: Options): Destination {
368372
};
369373
constrequest=ReactNoopServer.createRequest(
370374
children,
375+
// $FlowFixMe[incompatible-call]
371376
null,
377+
// $FlowFixMe[incompatible-call]
372378
null,
379+
// $FlowFixMe[incompatible-call]
373380
null,
374381
options ? options.progressiveChunkSize : undefined,
375382
options ? options.onError : undefined,
376383
options ? options.onAllReady : undefined,
377384
options ? options.onShellReady : undefined,
378385
);
379386
ReactNoopServer.startWork(request);
387+
// $FlowFixMe[incompatible-call]
380388
ReactNoopServer.startFlowing(request,destination);
381389
returndestination;
382390
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [noop] Typecheck `react-noop-renderer` against host config and render… · react/react@5e42791 · GitHub
Skip to content

Commit 5e42791

Browse files
authored
[noop] Typecheck react-noop-renderer against host config and renderer API (#35944)
1 parent ee4699f commit 5e42791

21 files changed

Lines changed: 782 additions & 65 deletions

‎packages/react-client/flight.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@
77
* @flow
88
*/
99

10+
importtypeof*asFlightClientAPIfrom'./src/ReactFlightClient';
11+
importtypeof*asHostConfigfrom'./src/ReactFlightClientConfig';
12+
1013
export*from'./src/ReactFlightClient';
14+
15+
// At build time, this module is wrapped as a factory function ($$$reconciler).
16+
// Consumers pass a host config object and get back the Flight client API.
17+
declareexportdefault(hostConfig: HostConfig)=>FlightClientAPI;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
// This is a host config that's used for the internal `react-noop-renderer` package.
11+
//
12+
// Its API lets you pass the host config as an argument.
13+
// However, inside the `react-server` we treat host config as a module.
14+
// This file is a shim between two worlds.
15+
//
16+
// It works because the `react-server` bundle is wrapped in something like:
17+
//
18+
// module.exports = function ($$$config) {
19+
// /* renderer code */
20+
// }
21+
//
22+
// So `$$$config` looks like a global variable, but it's
23+
// really an argument to a top-level wrapping function.
24+
25+
declareconst $$$config: $FlowFixMe;
26+
27+
exportopaquetypeModuleLoading=mixed;
28+
exportopaquetypeServerConsumerModuleMap=mixed;
29+
exportopaquetypeServerManifest=mixed;
30+
exportopaquetypeServerReferenceId=string;
31+
exportopaquetypeClientReferenceMetadata=mixed;
32+
exportopaquetypeClientReference<T>=mixed;// eslint-disable-line no-unused-vars
33+
exportconstresolveClientReference=$$$config.resolveClientReference;
34+
exportconstresolveServerReference=$$$config.resolveServerReference;
35+
exportconstpreloadModule=$$$config.preloadModule;
36+
exportconstrequireModule=$$$config.requireModule;
37+
exportconstgetModuleDebugInfo=$$$config.getModuleDebugInfo;
38+
exportconstdispatchHint=$$$config.dispatchHint;
39+
exportconstprepareDestinationForModule=
40+
$$$config.prepareDestinationForModule;
41+
exportconstusedWithSSR=true;
42+
43+
exportopaquetypeSource=mixed;
44+
45+
exportopaquetypeStringDecoder=mixed;
46+
47+
exportconstcreateStringDecoder=$$$config.createStringDecoder;
48+
exportconstreadPartialStringChunk=$$$config.readPartialStringChunk;
49+
exportconstreadFinalStringChunk=$$$config.readFinalStringChunk;
50+
51+
exportconstbindToConsole=$$$config.bindToConsole;
52+
53+
exportconstrendererVersion=$$$config.rendererVersion;
54+
exportconstrendererPackageName=$$$config.rendererPackageName;
55+
56+
exportconstcheckEvalAvailabilityOnceDev=
57+
$$$config.checkEvalAvailabilityOnceDev;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
exporttypeHostContext=Object;
11+
12+
exporttypeTextInstance={
13+
text: string,
14+
id: number,
15+
parent: number,
16+
hidden: boolean,
17+
context: HostContext,
18+
};
19+
20+
exporttypeInstance={
21+
type: string,
22+
id: number,
23+
parent: number,
24+
children: Array<Instance|TextInstance>,
25+
text: string|null,
26+
prop: any,
27+
hidden: boolean,
28+
context: HostContext,
29+
};
30+
31+
exporttypePublicInstance=Instance;
32+
33+
exporttypeTransitionStatus=mixed;

‎packages/react-noop-renderer/src/ReactNoop.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const {
5353
getRoot,
5454
// TODO: Remove this after callers migrate to alternatives.
5555
unstable_runWithPriority,
56+
// $FlowFixMe[signature-verification-failure]
5657
}=createReactNoop(
5758
ReactFiberReconciler,// reconciler
5859
true,// useMutation

‎packages/react-noop-renderer/src/ReactNoopFlightClient.js‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* environment.
1515
*/
1616

17+
importtype{Thenable}from'shared/ReactTypes';
1718
importtype{FindSourceMapURLCallback}from'react-client/flight';
1819

1920
import{readModule}from'react-noop-renderer/flight-modules';
@@ -25,6 +26,7 @@ type Source = Array<Uint8Array>;
2526
constdecoderOptions={stream: true};
2627

2728
const{createResponse, createStreamState, processBinaryChunk, getRoot, close}=
29+
// $FlowFixMe[prop-missing]
2830
ReactFlightClient({
2931
createStringDecoder(){
3032
returnnewTextDecoder();
@@ -44,6 +46,7 @@ const {createResponse, createStreamState, processBinaryChunk, getRoot, close} =
4446
returnreadModule(idx);
4547
},
4648
bindToConsole(methodName,args,badgeName){
49+
// $FlowFixMe[incompatible-call]
4750
returnFunction.prototype.bind.apply(
4851
// eslint-disable-next-line react-internal/no-production-logging
4952
console[methodName],
@@ -61,8 +64,10 @@ type ReadOptions = {|
6164

6265
functionread<T>(source: Source, options: ReadOptions): Thenable<T>{
6366
constresponse=createResponse(
67+
// $FlowFixMe[incompatible-call]
6468
source,
6569
null,
70+
// $FlowFixMe[incompatible-call]
6671
null,
6772
undefined,
6873
undefined,
@@ -73,12 +78,19 @@ function read<T>(source: Source, options: ReadOptions): Thenable<T> {
7378
true,
7479
undefined,
7580
__DEV__&&options!==undefined&&options.debugChannel!==undefined
76-
? options.debugChannel.onMessage
81+
? // $FlowFixMe[incompatible-call]
82+
options.debugChannel.onMessage
7783
: undefined,
7884
);
7985
conststreamState=createStreamState(response,source);
8086
for(leti=0;i<source.length;i++){
81-
processBinaryChunk(response,streamState,source[i],0);
87+
processBinaryChunk(
88+
response,
89+
streamState,
90+
source[i],
91+
// $FlowFixMe[extra-arg]
92+
0,
93+
);
8294
}
8395
if (options !== undefined &&options.close){
8496
close(response);

‎packages/react-noop-renderer/src/ReactNoopFlightServer.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import {saveModule} from 'react-noop-renderer/flight-modules';
2020

2121
importReactFlightServerfrom'react-server/flight';
2222

23-
typeDestination=Array<Uint8Array>;
23+
typeDestination=Array<Uint8Array|string>;
2424

2525
consttextEncoder=newTextEncoder();
2626

27+
// $FlowFixMe[prop-missing]
2728
constReactNoopFlightServer=ReactFlightServer({
2829
scheduleMicrotask(callback: ()=>void){
2930
callback();
@@ -81,13 +82,15 @@ function render(model: ReactClientValue, options?: Options): Destination {
8182
constbundlerConfig=undefined;
8283
constrequest=ReactNoopFlightServer.createRequest(
8384
model,
85+
// $FlowFixMe[incompatible-call]
8486
bundlerConfig,
8587
options ? options.onError : undefined,
8688
options ? options.identifierPrefix : undefined,
8789
undefined,
8890
options ? options.startTime : undefined,
8991
__DEV__&&options ? options.environmentName : undefined,
9092
__DEV__&&options ? options.filterStackFrame : undefined,
93+
// $FlowFixMe[incompatible-call]
9194
__DEV__&&options&&options.debugChannel!==undefined,
9295
);
9396
constsignal=options ? options.signal : undefined;
@@ -108,7 +111,11 @@ function render(model: ReactClientValue, options?: Options): Destination {
108111
};
109112
}
110113
ReactNoopFlightServer.startWork(request);
111-
ReactNoopFlightServer.startFlowing(request,destination);
114+
ReactNoopFlightServer.startFlowing(
115+
request,
116+
// $FlowFixMe[incompatible-call]
117+
destination,
118+
);
112119
returndestination;
113120
}
114121

‎packages/react-noop-renderer/src/ReactNoopPersistent.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const {
5555
// TODO: Remove this once callers migrate to alternatives.
5656
// This should only be used by React internals.
5757
unstable_runWithPriority,
58+
// $FlowFixMe[signature-verification-failure]
5859
}=createReactNoop(
5960
ReactFiberReconciler,// reconciler
6061
false,// useMutation

‎packages/react-noop-renderer/src/ReactNoopServer.js‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ type SuspenseInstance = {
4040
};
4141

4242
typePlaceholder={
43-
parent: Instance|SuspenseInstance,
43+
parent: Instance|Segment|SuspenseInstance,
4444
index: number,
4545
};
4646

4747
typeSegment={
48-
children: null|Instance|TextInstance|SuspenseInstance,
48+
children: Array<Instance|TextInstance|SuspenseInstance>,
4949
};
5050

5151
typeDestination={
@@ -79,6 +79,7 @@ function write(destination: Destination, buffer: Uint8Array): void {
7979
stack.push(instance);
8080
}
8181

82+
// $FlowFixMe[prop-missing]
8283
constReactNoopServer=ReactFizzServer({
8384
scheduleMicrotask(callback: ()=>void){
8485
callback();
@@ -175,6 +176,7 @@ const ReactNoopServer = ReactFizzServer({
175176
destination: Destination,
176177
renderState: RenderState,
177178
id: number,
179+
// $FlowFixMe[incompatible-return]
178180
): boolean{
179181
constparent=destination.stack[destination.stack.length-1];
180182
destination.placeholders.set(id,{
@@ -258,7 +260,7 @@ const ReactNoopServer = ReactFizzServer({
258260
formatContext: null,
259261
id: number,
260262
): boolean{
261-
constsegment={
263+
constsegment: Segment={
262264
children: [],
263265
};
264266
destination.segments.set(id,segment);
@@ -314,6 +316,7 @@ const ReactNoopServer = ReactFizzServer({
314316
renderState: RenderState,
315317
boundary: SuspenseInstance,
316318
): boolean{
319+
// $FlowFixMe[prop-missing]
317320
boundary.status='client-render';
318321
returntrue;
319322
},
@@ -357,6 +360,7 @@ type Options = {
357360
};
358361

359362
functionrender(children: React$Element<any>,options?: Options): Destination{
363+
// $FlowFixMe[prop-missing]
360364
constdestination: Destination={
361365
root: null,
362366
placeholders: newMap(),
@@ -368,15 +372,19 @@ function render(children: React$Element<any>, options?: Options): Destination {
368372
};
369373
constrequest=ReactNoopServer.createRequest(
370374
children,
375+
// $FlowFixMe[incompatible-call]
371376
null,
377+
// $FlowFixMe[incompatible-call]
372378
null,
379+
// $FlowFixMe[incompatible-call]
373380
null,
374381
options ? options.progressiveChunkSize : undefined,
375382
options ? options.onError : undefined,
376383
options ? options.onAllReady : undefined,
377384
options ? options.onShellReady : undefined,
378385
);
379386
ReactNoopServer.startWork(request);
387+
// $FlowFixMe[incompatible-call]
380388
ReactNoopServer.startFlowing(request,destination);
381389
returndestination;
382390
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [noop] Typecheck `react-noop-renderer` against host config and render… · react/react@5e42791 · GitHub
Skip to content

Commit 5e42791

Browse files
authored
[noop] Typecheck react-noop-renderer against host config and renderer API (#35944)
1 parent ee4699f commit 5e42791

21 files changed

Lines changed: 782 additions & 65 deletions

‎packages/react-client/flight.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@
77
* @flow
88
*/
99

10+
importtypeof*asFlightClientAPIfrom'./src/ReactFlightClient';
11+
importtypeof*asHostConfigfrom'./src/ReactFlightClientConfig';
12+
1013
export*from'./src/ReactFlightClient';
14+
15+
// At build time, this module is wrapped as a factory function ($$$reconciler).
16+
// Consumers pass a host config object and get back the Flight client API.
17+
declareexportdefault(hostConfig: HostConfig)=>FlightClientAPI;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
// This is a host config that's used for the internal `react-noop-renderer` package.
11+
//
12+
// Its API lets you pass the host config as an argument.
13+
// However, inside the `react-server` we treat host config as a module.
14+
// This file is a shim between two worlds.
15+
//
16+
// It works because the `react-server` bundle is wrapped in something like:
17+
//
18+
// module.exports = function ($$$config) {
19+
// /* renderer code */
20+
// }
21+
//
22+
// So `$$$config` looks like a global variable, but it's
23+
// really an argument to a top-level wrapping function.
24+
25+
declareconst $$$config: $FlowFixMe;
26+
27+
exportopaquetypeModuleLoading=mixed;
28+
exportopaquetypeServerConsumerModuleMap=mixed;
29+
exportopaquetypeServerManifest=mixed;
30+
exportopaquetypeServerReferenceId=string;
31+
exportopaquetypeClientReferenceMetadata=mixed;
32+
exportopaquetypeClientReference<T>=mixed;// eslint-disable-line no-unused-vars
33+
exportconstresolveClientReference=$$$config.resolveClientReference;
34+
exportconstresolveServerReference=$$$config.resolveServerReference;
35+
exportconstpreloadModule=$$$config.preloadModule;
36+
exportconstrequireModule=$$$config.requireModule;
37+
exportconstgetModuleDebugInfo=$$$config.getModuleDebugInfo;
38+
exportconstdispatchHint=$$$config.dispatchHint;
39+
exportconstprepareDestinationForModule=
40+
$$$config.prepareDestinationForModule;
41+
exportconstusedWithSSR=true;
42+
43+
exportopaquetypeSource=mixed;
44+
45+
exportopaquetypeStringDecoder=mixed;
46+
47+
exportconstcreateStringDecoder=$$$config.createStringDecoder;
48+
exportconstreadPartialStringChunk=$$$config.readPartialStringChunk;
49+
exportconstreadFinalStringChunk=$$$config.readFinalStringChunk;
50+
51+
exportconstbindToConsole=$$$config.bindToConsole;
52+
53+
exportconstrendererVersion=$$$config.rendererVersion;
54+
exportconstrendererPackageName=$$$config.rendererPackageName;
55+
56+
exportconstcheckEvalAvailabilityOnceDev=
57+
$$$config.checkEvalAvailabilityOnceDev;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
exporttypeHostContext=Object;
11+
12+
exporttypeTextInstance={
13+
text: string,
14+
id: number,
15+
parent: number,
16+
hidden: boolean,
17+
context: HostContext,
18+
};
19+
20+
exporttypeInstance={
21+
type: string,
22+
id: number,
23+
parent: number,
24+
children: Array<Instance|TextInstance>,
25+
text: string|null,
26+
prop: any,
27+
hidden: boolean,
28+
context: HostContext,
29+
};
30+
31+
exporttypePublicInstance=Instance;
32+
33+
exporttypeTransitionStatus=mixed;

‎packages/react-noop-renderer/src/ReactNoop.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const {
5353
getRoot,
5454
// TODO: Remove this after callers migrate to alternatives.
5555
unstable_runWithPriority,
56+
// $FlowFixMe[signature-verification-failure]
5657
}=createReactNoop(
5758
ReactFiberReconciler,// reconciler
5859
true,// useMutation

‎packages/react-noop-renderer/src/ReactNoopFlightClient.js‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* environment.
1515
*/
1616

17+
importtype{Thenable}from'shared/ReactTypes';
1718
importtype{FindSourceMapURLCallback}from'react-client/flight';
1819

1920
import{readModule}from'react-noop-renderer/flight-modules';
@@ -25,6 +26,7 @@ type Source = Array<Uint8Array>;
2526
constdecoderOptions={stream: true};
2627

2728
const{createResponse, createStreamState, processBinaryChunk, getRoot, close}=
29+
// $FlowFixMe[prop-missing]
2830
ReactFlightClient({
2931
createStringDecoder(){
3032
returnnewTextDecoder();
@@ -44,6 +46,7 @@ const {createResponse, createStreamState, processBinaryChunk, getRoot, close} =
4446
returnreadModule(idx);
4547
},
4648
bindToConsole(methodName,args,badgeName){
49+
// $FlowFixMe[incompatible-call]
4750
returnFunction.prototype.bind.apply(
4851
// eslint-disable-next-line react-internal/no-production-logging
4952
console[methodName],
@@ -61,8 +64,10 @@ type ReadOptions = {|
6164

6265
functionread<T>(source: Source, options: ReadOptions): Thenable<T>{
6366
constresponse=createResponse(
67+
// $FlowFixMe[incompatible-call]
6468
source,
6569
null,
70+
// $FlowFixMe[incompatible-call]
6671
null,
6772
undefined,
6873
undefined,
@@ -73,12 +78,19 @@ function read<T>(source: Source, options: ReadOptions): Thenable<T> {
7378
true,
7479
undefined,
7580
__DEV__&&options!==undefined&&options.debugChannel!==undefined
76-
? options.debugChannel.onMessage
81+
? // $FlowFixMe[incompatible-call]
82+
options.debugChannel.onMessage
7783
: undefined,
7884
);
7985
conststreamState=createStreamState(response,source);
8086
for(leti=0;i<source.length;i++){
81-
processBinaryChunk(response,streamState,source[i],0);
87+
processBinaryChunk(
88+
response,
89+
streamState,
90+
source[i],
91+
// $FlowFixMe[extra-arg]
92+
0,
93+
);
8294
}
8395
if (options !== undefined &&options.close){
8496
close(response);

‎packages/react-noop-renderer/src/ReactNoopFlightServer.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import {saveModule} from 'react-noop-renderer/flight-modules';
2020

2121
importReactFlightServerfrom'react-server/flight';
2222

23-
typeDestination=Array<Uint8Array>;
23+
typeDestination=Array<Uint8Array|string>;
2424

2525
consttextEncoder=newTextEncoder();
2626

27+
// $FlowFixMe[prop-missing]
2728
constReactNoopFlightServer=ReactFlightServer({
2829
scheduleMicrotask(callback: ()=>void){
2930
callback();
@@ -81,13 +82,15 @@ function render(model: ReactClientValue, options?: Options): Destination {
8182
constbundlerConfig=undefined;
8283
constrequest=ReactNoopFlightServer.createRequest(
8384
model,
85+
// $FlowFixMe[incompatible-call]
8486
bundlerConfig,
8587
options ? options.onError : undefined,
8688
options ? options.identifierPrefix : undefined,
8789
undefined,
8890
options ? options.startTime : undefined,
8991
__DEV__&&options ? options.environmentName : undefined,
9092
__DEV__&&options ? options.filterStackFrame : undefined,
93+
// $FlowFixMe[incompatible-call]
9194
__DEV__&&options&&options.debugChannel!==undefined,
9295
);
9396
constsignal=options ? options.signal : undefined;
@@ -108,7 +111,11 @@ function render(model: ReactClientValue, options?: Options): Destination {
108111
};
109112
}
110113
ReactNoopFlightServer.startWork(request);
111-
ReactNoopFlightServer.startFlowing(request,destination);
114+
ReactNoopFlightServer.startFlowing(
115+
request,
116+
// $FlowFixMe[incompatible-call]
117+
destination,
118+
);
112119
returndestination;
113120
}
114121

‎packages/react-noop-renderer/src/ReactNoopPersistent.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const {
5555
// TODO: Remove this once callers migrate to alternatives.
5656
// This should only be used by React internals.
5757
unstable_runWithPriority,
58+
// $FlowFixMe[signature-verification-failure]
5859
}=createReactNoop(
5960
ReactFiberReconciler,// reconciler
6061
false,// useMutation

‎packages/react-noop-renderer/src/ReactNoopServer.js‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ type SuspenseInstance = {
4040
};
4141

4242
typePlaceholder={
43-
parent: Instance|SuspenseInstance,
43+
parent: Instance|Segment|SuspenseInstance,
4444
index: number,
4545
};
4646

4747
typeSegment={
48-
children: null|Instance|TextInstance|SuspenseInstance,
48+
children: Array<Instance|TextInstance|SuspenseInstance>,
4949
};
5050

5151
typeDestination={
@@ -79,6 +79,7 @@ function write(destination: Destination, buffer: Uint8Array): void {
7979
stack.push(instance);
8080
}
8181

82+
// $FlowFixMe[prop-missing]
8283
constReactNoopServer=ReactFizzServer({
8384
scheduleMicrotask(callback: ()=>void){
8485
callback();
@@ -175,6 +176,7 @@ const ReactNoopServer = ReactFizzServer({
175176
destination: Destination,
176177
renderState: RenderState,
177178
id: number,
179+
// $FlowFixMe[incompatible-return]
178180
): boolean{
179181
constparent=destination.stack[destination.stack.length-1];
180182
destination.placeholders.set(id,{
@@ -258,7 +260,7 @@ const ReactNoopServer = ReactFizzServer({
258260
formatContext: null,
259261
id: number,
260262
): boolean{
261-
constsegment={
263+
constsegment: Segment={
262264
children: [],
263265
};
264266
destination.segments.set(id,segment);
@@ -314,6 +316,7 @@ const ReactNoopServer = ReactFizzServer({
314316
renderState: RenderState,
315317
boundary: SuspenseInstance,
316318
): boolean{
319+
// $FlowFixMe[prop-missing]
317320
boundary.status='client-render';
318321
returntrue;
319322
},
@@ -357,6 +360,7 @@ type Options = {
357360
};
358361

359362
functionrender(children: React$Element<any>,options?: Options): Destination{
363+
// $FlowFixMe[prop-missing]
360364
constdestination: Destination={
361365
root: null,
362366
placeholders: newMap(),
@@ -368,15 +372,19 @@ function render(children: React$Element<any>, options?: Options): Destination {
368372
};
369373
constrequest=ReactNoopServer.createRequest(
370374
children,
375+
// $FlowFixMe[incompatible-call]
371376
null,
377+
// $FlowFixMe[incompatible-call]
372378
null,
379+
// $FlowFixMe[incompatible-call]
373380
null,
374381
options ? options.progressiveChunkSize : undefined,
375382
options ? options.onError : undefined,
376383
options ? options.onAllReady : undefined,
377384
options ? options.onShellReady : undefined,
378385
);
379386
ReactNoopServer.startWork(request);
387+
// $FlowFixMe[incompatible-call]
380388
ReactNoopServer.startFlowing(request,destination);
381389
returndestination;
382390
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' [noop] Typecheck `react-noop-renderer` against host config and render… · react/react@5e42791 · GitHub
Skip to content

Commit 5e42791

Browse files
authored
[noop] Typecheck react-noop-renderer against host config and renderer API (#35944)
1 parent ee4699f commit 5e42791

21 files changed

Lines changed: 782 additions & 65 deletions

‎packages/react-client/flight.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@
77
* @flow
88
*/
99

10+
importtypeof*asFlightClientAPIfrom'./src/ReactFlightClient';
11+
importtypeof*asHostConfigfrom'./src/ReactFlightClientConfig';
12+
1013
export*from'./src/ReactFlightClient';
14+
15+
// At build time, this module is wrapped as a factory function ($$$reconciler).
16+
// Consumers pass a host config object and get back the Flight client API.
17+
declareexportdefault(hostConfig: HostConfig)=>FlightClientAPI;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
// This is a host config that's used for the internal `react-noop-renderer` package.
11+
//
12+
// Its API lets you pass the host config as an argument.
13+
// However, inside the `react-server` we treat host config as a module.
14+
// This file is a shim between two worlds.
15+
//
16+
// It works because the `react-server` bundle is wrapped in something like:
17+
//
18+
// module.exports = function ($$$config) {
19+
// /* renderer code */
20+
// }
21+
//
22+
// So `$$$config` looks like a global variable, but it's
23+
// really an argument to a top-level wrapping function.
24+
25+
declareconst $$$config: $FlowFixMe;
26+
27+
exportopaquetypeModuleLoading=mixed;
28+
exportopaquetypeServerConsumerModuleMap=mixed;
29+
exportopaquetypeServerManifest=mixed;
30+
exportopaquetypeServerReferenceId=string;
31+
exportopaquetypeClientReferenceMetadata=mixed;
32+
exportopaquetypeClientReference<T>=mixed;// eslint-disable-line no-unused-vars
33+
exportconstresolveClientReference=$$$config.resolveClientReference;
34+
exportconstresolveServerReference=$$$config.resolveServerReference;
35+
exportconstpreloadModule=$$$config.preloadModule;
36+
exportconstrequireModule=$$$config.requireModule;
37+
exportconstgetModuleDebugInfo=$$$config.getModuleDebugInfo;
38+
exportconstdispatchHint=$$$config.dispatchHint;
39+
exportconstprepareDestinationForModule=
40+
$$$config.prepareDestinationForModule;
41+
exportconstusedWithSSR=true;
42+
43+
exportopaquetypeSource=mixed;
44+
45+
exportopaquetypeStringDecoder=mixed;
46+
47+
exportconstcreateStringDecoder=$$$config.createStringDecoder;
48+
exportconstreadPartialStringChunk=$$$config.readPartialStringChunk;
49+
exportconstreadFinalStringChunk=$$$config.readFinalStringChunk;
50+
51+
exportconstbindToConsole=$$$config.bindToConsole;
52+
53+
exportconstrendererVersion=$$$config.rendererVersion;
54+
exportconstrendererPackageName=$$$config.rendererPackageName;
55+
56+
exportconstcheckEvalAvailabilityOnceDev=
57+
$$$config.checkEvalAvailabilityOnceDev;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
exporttypeHostContext=Object;
11+
12+
exporttypeTextInstance={
13+
text: string,
14+
id: number,
15+
parent: number,
16+
hidden: boolean,
17+
context: HostContext,
18+
};
19+
20+
exporttypeInstance={
21+
type: string,
22+
id: number,
23+
parent: number,
24+
children: Array<Instance|TextInstance>,
25+
text: string|null,
26+
prop: any,
27+
hidden: boolean,
28+
context: HostContext,
29+
};
30+
31+
exporttypePublicInstance=Instance;
32+
33+
exporttypeTransitionStatus=mixed;

‎packages/react-noop-renderer/src/ReactNoop.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const {
5353
getRoot,
5454
// TODO: Remove this after callers migrate to alternatives.
5555
unstable_runWithPriority,
56+
// $FlowFixMe[signature-verification-failure]
5657
}=createReactNoop(
5758
ReactFiberReconciler,// reconciler
5859
true,// useMutation

‎packages/react-noop-renderer/src/ReactNoopFlightClient.js‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* environment.
1515
*/
1616

17+
importtype{Thenable}from'shared/ReactTypes';
1718
importtype{FindSourceMapURLCallback}from'react-client/flight';
1819

1920
import{readModule}from'react-noop-renderer/flight-modules';
@@ -25,6 +26,7 @@ type Source = Array<Uint8Array>;
2526
constdecoderOptions={stream: true};
2627

2728
const{createResponse, createStreamState, processBinaryChunk, getRoot, close}=
29+
// $FlowFixMe[prop-missing]
2830
ReactFlightClient({
2931
createStringDecoder(){
3032
returnnewTextDecoder();
@@ -44,6 +46,7 @@ const {createResponse, createStreamState, processBinaryChunk, getRoot, close} =
4446
returnreadModule(idx);
4547
},
4648
bindToConsole(methodName,args,badgeName){
49+
// $FlowFixMe[incompatible-call]
4750
returnFunction.prototype.bind.apply(
4851
// eslint-disable-next-line react-internal/no-production-logging
4952
console[methodName],
@@ -61,8 +64,10 @@ type ReadOptions = {|
6164

6265
functionread<T>(source: Source, options: ReadOptions): Thenable<T>{
6366
constresponse=createResponse(
67+
// $FlowFixMe[incompatible-call]
6468
source,
6569
null,
70+
// $FlowFixMe[incompatible-call]
6671
null,
6772
undefined,
6873
undefined,
@@ -73,12 +78,19 @@ function read<T>(source: Source, options: ReadOptions): Thenable<T> {
7378
true,
7479
undefined,
7580
__DEV__&&options!==undefined&&options.debugChannel!==undefined
76-
? options.debugChannel.onMessage
81+
? // $FlowFixMe[incompatible-call]
82+
options.debugChannel.onMessage
7783
: undefined,
7884
);
7985
conststreamState=createStreamState(response,source);
8086
for(leti=0;i<source.length;i++){
81-
processBinaryChunk(response,streamState,source[i],0);
87+
processBinaryChunk(
88+
response,
89+
streamState,
90+
source[i],
91+
// $FlowFixMe[extra-arg]
92+
0,
93+
);
8294
}
8395
if (options !== undefined &&options.close){
8496
close(response);

‎packages/react-noop-renderer/src/ReactNoopFlightServer.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import {saveModule} from 'react-noop-renderer/flight-modules';
2020

2121
importReactFlightServerfrom'react-server/flight';
2222

23-
typeDestination=Array<Uint8Array>;
23+
typeDestination=Array<Uint8Array|string>;
2424

2525
consttextEncoder=newTextEncoder();
2626

27+
// $FlowFixMe[prop-missing]
2728
constReactNoopFlightServer=ReactFlightServer({
2829
scheduleMicrotask(callback: ()=>void){
2930
callback();
@@ -81,13 +82,15 @@ function render(model: ReactClientValue, options?: Options): Destination {
8182
constbundlerConfig=undefined;
8283
constrequest=ReactNoopFlightServer.createRequest(
8384
model,
85+
// $FlowFixMe[incompatible-call]
8486
bundlerConfig,
8587
options ? options.onError : undefined,
8688
options ? options.identifierPrefix : undefined,
8789
undefined,
8890
options ? options.startTime : undefined,
8991
__DEV__&&options ? options.environmentName : undefined,
9092
__DEV__&&options ? options.filterStackFrame : undefined,
93+
// $FlowFixMe[incompatible-call]
9194
__DEV__&&options&&options.debugChannel!==undefined,
9295
);
9396
constsignal=options ? options.signal : undefined;
@@ -108,7 +111,11 @@ function render(model: ReactClientValue, options?: Options): Destination {
108111
};
109112
}
110113
ReactNoopFlightServer.startWork(request);
111-
ReactNoopFlightServer.startFlowing(request,destination);
114+
ReactNoopFlightServer.startFlowing(
115+
request,
116+
// $FlowFixMe[incompatible-call]
117+
destination,
118+
);
112119
returndestination;
113120
}
114121

‎packages/react-noop-renderer/src/ReactNoopPersistent.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const {
5555
// TODO: Remove this once callers migrate to alternatives.
5656
// This should only be used by React internals.
5757
unstable_runWithPriority,
58+
// $FlowFixMe[signature-verification-failure]
5859
}=createReactNoop(
5960
ReactFiberReconciler,// reconciler
6061
false,// useMutation

‎packages/react-noop-renderer/src/ReactNoopServer.js‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ type SuspenseInstance = {
4040
};
4141

4242
typePlaceholder={
43-
parent: Instance|SuspenseInstance,
43+
parent: Instance|Segment|SuspenseInstance,
4444
index: number,
4545
};
4646

4747
typeSegment={
48-
children: null|Instance|TextInstance|SuspenseInstance,
48+
children: Array<Instance|TextInstance|SuspenseInstance>,
4949
};
5050

5151
typeDestination={
@@ -79,6 +79,7 @@ function write(destination: Destination, buffer: Uint8Array): void {
7979
stack.push(instance);
8080
}
8181

82+
// $FlowFixMe[prop-missing]
8283
constReactNoopServer=ReactFizzServer({
8384
scheduleMicrotask(callback: ()=>void){
8485
callback();
@@ -175,6 +176,7 @@ const ReactNoopServer = ReactFizzServer({
175176
destination: Destination,
176177
renderState: RenderState,
177178
id: number,
179+
// $FlowFixMe[incompatible-return]
178180
): boolean{
179181
constparent=destination.stack[destination.stack.length-1];
180182
destination.placeholders.set(id,{
@@ -258,7 +260,7 @@ const ReactNoopServer = ReactFizzServer({
258260
formatContext: null,
259261
id: number,
260262
): boolean{
261-
constsegment={
263+
constsegment: Segment={
262264
children: [],
263265
};
264266
destination.segments.set(id,segment);
@@ -314,6 +316,7 @@ const ReactNoopServer = ReactFizzServer({
314316
renderState: RenderState,
315317
boundary: SuspenseInstance,
316318
): boolean{
319+
// $FlowFixMe[prop-missing]
317320
boundary.status='client-render';
318321
returntrue;
319322
},
@@ -357,6 +360,7 @@ type Options = {
357360
};
358361

359362
functionrender(children: React$Element<any>,options?: Options): Destination{
363+
// $FlowFixMe[prop-missing]
360364
constdestination: Destination={
361365
root: null,
362366
placeholders: newMap(),
@@ -368,15 +372,19 @@ function render(children: React$Element<any>, options?: Options): Destination {
368372
};
369373
constrequest=ReactNoopServer.createRequest(
370374
children,
375+
// $FlowFixMe[incompatible-call]
371376
null,
377+
// $FlowFixMe[incompatible-call]
372378
null,
379+
// $FlowFixMe[incompatible-call]
373380
null,
374381
options ? options.progressiveChunkSize : undefined,
375382
options ? options.onError : undefined,
376383
options ? options.onAllReady : undefined,
377384
options ? options.onShellReady : undefined,
378385
);
379386
ReactNoopServer.startWork(request);
387+
// $FlowFixMe[incompatible-call]
380388
ReactNoopServer.startFlowing(request,destination);
381389
returndestination;
382390
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [noop] Typecheck `react-noop-renderer` against host config and render… · react/react@5e42791 · GitHub
Skip to content

Commit 5e42791

Browse files
authored
[noop] Typecheck react-noop-renderer against host config and renderer API (#35944)
1 parent ee4699f commit 5e42791

21 files changed

Lines changed: 782 additions & 65 deletions

‎packages/react-client/flight.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@
77
* @flow
88
*/
99

10+
importtypeof*asFlightClientAPIfrom'./src/ReactFlightClient';
11+
importtypeof*asHostConfigfrom'./src/ReactFlightClientConfig';
12+
1013
export*from'./src/ReactFlightClient';
14+
15+
// At build time, this module is wrapped as a factory function ($$$reconciler).
16+
// Consumers pass a host config object and get back the Flight client API.
17+
declareexportdefault(hostConfig: HostConfig)=>FlightClientAPI;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
// This is a host config that's used for the internal `react-noop-renderer` package.
11+
//
12+
// Its API lets you pass the host config as an argument.
13+
// However, inside the `react-server` we treat host config as a module.
14+
// This file is a shim between two worlds.
15+
//
16+
// It works because the `react-server` bundle is wrapped in something like:
17+
//
18+
// module.exports = function ($$$config) {
19+
// /* renderer code */
20+
// }
21+
//
22+
// So `$$$config` looks like a global variable, but it's
23+
// really an argument to a top-level wrapping function.
24+
25+
declareconst $$$config: $FlowFixMe;
26+
27+
exportopaquetypeModuleLoading=mixed;
28+
exportopaquetypeServerConsumerModuleMap=mixed;
29+
exportopaquetypeServerManifest=mixed;
30+
exportopaquetypeServerReferenceId=string;
31+
exportopaquetypeClientReferenceMetadata=mixed;
32+
exportopaquetypeClientReference<T>=mixed;// eslint-disable-line no-unused-vars
33+
exportconstresolveClientReference=$$$config.resolveClientReference;
34+
exportconstresolveServerReference=$$$config.resolveServerReference;
35+
exportconstpreloadModule=$$$config.preloadModule;
36+
exportconstrequireModule=$$$config.requireModule;
37+
exportconstgetModuleDebugInfo=$$$config.getModuleDebugInfo;
38+
exportconstdispatchHint=$$$config.dispatchHint;
39+
exportconstprepareDestinationForModule=
40+
$$$config.prepareDestinationForModule;
41+
exportconstusedWithSSR=true;
42+
43+
exportopaquetypeSource=mixed;
44+
45+
exportopaquetypeStringDecoder=mixed;
46+
47+
exportconstcreateStringDecoder=$$$config.createStringDecoder;
48+
exportconstreadPartialStringChunk=$$$config.readPartialStringChunk;
49+
exportconstreadFinalStringChunk=$$$config.readFinalStringChunk;
50+
51+
exportconstbindToConsole=$$$config.bindToConsole;
52+
53+
exportconstrendererVersion=$$$config.rendererVersion;
54+
exportconstrendererPackageName=$$$config.rendererPackageName;
55+
56+
exportconstcheckEvalAvailabilityOnceDev=
57+
$$$config.checkEvalAvailabilityOnceDev;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
exporttypeHostContext=Object;
11+
12+
exporttypeTextInstance={
13+
text: string,
14+
id: number,
15+
parent: number,
16+
hidden: boolean,
17+
context: HostContext,
18+
};
19+
20+
exporttypeInstance={
21+
type: string,
22+
id: number,
23+
parent: number,
24+
children: Array<Instance|TextInstance>,
25+
text: string|null,
26+
prop: any,
27+
hidden: boolean,
28+
context: HostContext,
29+
};
30+
31+
exporttypePublicInstance=Instance;
32+
33+
exporttypeTransitionStatus=mixed;

‎packages/react-noop-renderer/src/ReactNoop.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const {
5353
getRoot,
5454
// TODO: Remove this after callers migrate to alternatives.
5555
unstable_runWithPriority,
56+
// $FlowFixMe[signature-verification-failure]
5657
}=createReactNoop(
5758
ReactFiberReconciler,// reconciler
5859
true,// useMutation

‎packages/react-noop-renderer/src/ReactNoopFlightClient.js‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* environment.
1515
*/
1616

17+
importtype{Thenable}from'shared/ReactTypes';
1718
importtype{FindSourceMapURLCallback}from'react-client/flight';
1819

1920
import{readModule}from'react-noop-renderer/flight-modules';
@@ -25,6 +26,7 @@ type Source = Array<Uint8Array>;
2526
constdecoderOptions={stream: true};
2627

2728
const{createResponse, createStreamState, processBinaryChunk, getRoot, close}=
29+
// $FlowFixMe[prop-missing]
2830
ReactFlightClient({
2931
createStringDecoder(){
3032
returnnewTextDecoder();
@@ -44,6 +46,7 @@ const {createResponse, createStreamState, processBinaryChunk, getRoot, close} =
4446
returnreadModule(idx);
4547
},
4648
bindToConsole(methodName,args,badgeName){
49+
// $FlowFixMe[incompatible-call]
4750
returnFunction.prototype.bind.apply(
4851
// eslint-disable-next-line react-internal/no-production-logging
4952
console[methodName],
@@ -61,8 +64,10 @@ type ReadOptions = {|
6164

6265
functionread<T>(source: Source, options: ReadOptions): Thenable<T>{
6366
constresponse=createResponse(
67+
// $FlowFixMe[incompatible-call]
6468
source,
6569
null,
70+
// $FlowFixMe[incompatible-call]
6671
null,
6772
undefined,
6873
undefined,
@@ -73,12 +78,19 @@ function read<T>(source: Source, options: ReadOptions): Thenable<T> {
7378
true,
7479
undefined,
7580
__DEV__&&options!==undefined&&options.debugChannel!==undefined
76-
? options.debugChannel.onMessage
81+
? // $FlowFixMe[incompatible-call]
82+
options.debugChannel.onMessage
7783
: undefined,
7884
);
7985
conststreamState=createStreamState(response,source);
8086
for(leti=0;i<source.length;i++){
81-
processBinaryChunk(response,streamState,source[i],0);
87+
processBinaryChunk(
88+
response,
89+
streamState,
90+
source[i],
91+
// $FlowFixMe[extra-arg]
92+
0,
93+
);
8294
}
8395
if (options !== undefined &&options.close){
8496
close(response);

‎packages/react-noop-renderer/src/ReactNoopFlightServer.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import {saveModule} from 'react-noop-renderer/flight-modules';
2020

2121
importReactFlightServerfrom'react-server/flight';
2222

23-
typeDestination=Array<Uint8Array>;
23+
typeDestination=Array<Uint8Array|string>;
2424

2525
consttextEncoder=newTextEncoder();
2626

27+
// $FlowFixMe[prop-missing]
2728
constReactNoopFlightServer=ReactFlightServer({
2829
scheduleMicrotask(callback: ()=>void){
2930
callback();
@@ -81,13 +82,15 @@ function render(model: ReactClientValue, options?: Options): Destination {
8182
constbundlerConfig=undefined;
8283
constrequest=ReactNoopFlightServer.createRequest(
8384
model,
85+
// $FlowFixMe[incompatible-call]
8486
bundlerConfig,
8587
options ? options.onError : undefined,
8688
options ? options.identifierPrefix : undefined,
8789
undefined,
8890
options ? options.startTime : undefined,
8991
__DEV__&&options ? options.environmentName : undefined,
9092
__DEV__&&options ? options.filterStackFrame : undefined,
93+
// $FlowFixMe[incompatible-call]
9194
__DEV__&&options&&options.debugChannel!==undefined,
9295
);
9396
constsignal=options ? options.signal : undefined;
@@ -108,7 +111,11 @@ function render(model: ReactClientValue, options?: Options): Destination {
108111
};
109112
}
110113
ReactNoopFlightServer.startWork(request);
111-
ReactNoopFlightServer.startFlowing(request,destination);
114+
ReactNoopFlightServer.startFlowing(
115+
request,
116+
// $FlowFixMe[incompatible-call]
117+
destination,
118+
);
112119
returndestination;
113120
}
114121

‎packages/react-noop-renderer/src/ReactNoopPersistent.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const {
5555
// TODO: Remove this once callers migrate to alternatives.
5656
// This should only be used by React internals.
5757
unstable_runWithPriority,
58+
// $FlowFixMe[signature-verification-failure]
5859
}=createReactNoop(
5960
ReactFiberReconciler,// reconciler
6061
false,// useMutation

‎packages/react-noop-renderer/src/ReactNoopServer.js‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ type SuspenseInstance = {
4040
};
4141

4242
typePlaceholder={
43-
parent: Instance|SuspenseInstance,
43+
parent: Instance|Segment|SuspenseInstance,
4444
index: number,
4545
};
4646

4747
typeSegment={
48-
children: null|Instance|TextInstance|SuspenseInstance,
48+
children: Array<Instance|TextInstance|SuspenseInstance>,
4949
};
5050

5151
typeDestination={
@@ -79,6 +79,7 @@ function write(destination: Destination, buffer: Uint8Array): void {
7979
stack.push(instance);
8080
}
8181

82+
// $FlowFixMe[prop-missing]
8283
constReactNoopServer=ReactFizzServer({
8384
scheduleMicrotask(callback: ()=>void){
8485
callback();
@@ -175,6 +176,7 @@ const ReactNoopServer = ReactFizzServer({
175176
destination: Destination,
176177
renderState: RenderState,
177178
id: number,
179+
// $FlowFixMe[incompatible-return]
178180
): boolean{
179181
constparent=destination.stack[destination.stack.length-1];
180182
destination.placeholders.set(id,{
@@ -258,7 +260,7 @@ const ReactNoopServer = ReactFizzServer({
258260
formatContext: null,
259261
id: number,
260262
): boolean{
261-
constsegment={
263+
constsegment: Segment={
262264
children: [],
263265
};
264266
destination.segments.set(id,segment);
@@ -314,6 +316,7 @@ const ReactNoopServer = ReactFizzServer({
314316
renderState: RenderState,
315317
boundary: SuspenseInstance,
316318
): boolean{
319+
// $FlowFixMe[prop-missing]
317320
boundary.status='client-render';
318321
returntrue;
319322
},
@@ -357,6 +360,7 @@ type Options = {
357360
};
358361

359362
functionrender(children: React$Element<any>,options?: Options): Destination{
363+
// $FlowFixMe[prop-missing]
360364
constdestination: Destination={
361365
root: null,
362366
placeholders: newMap(),
@@ -368,15 +372,19 @@ function render(children: React$Element<any>, options?: Options): Destination {
368372
};
369373
constrequest=ReactNoopServer.createRequest(
370374
children,
375+
// $FlowFixMe[incompatible-call]
371376
null,
377+
// $FlowFixMe[incompatible-call]
372378
null,
379+
// $FlowFixMe[incompatible-call]
373380
null,
374381
options ? options.progressiveChunkSize : undefined,
375382
options ? options.onError : undefined,
376383
options ? options.onAllReady : undefined,
377384
options ? options.onShellReady : undefined,
378385
);
379386
ReactNoopServer.startWork(request);
387+
// $FlowFixMe[incompatible-call]
380388
ReactNoopServer.startFlowing(request,destination);
381389
returndestination;
382390
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [noop] Typecheck `react-noop-renderer` against host config and render… · react/react@5e42791 · GitHub
Skip to content

Commit 5e42791

Browse files
authored
[noop] Typecheck react-noop-renderer against host config and renderer API (#35944)
1 parent ee4699f commit 5e42791

21 files changed

Lines changed: 782 additions & 65 deletions

‎packages/react-client/flight.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@
77
* @flow
88
*/
99

10+
importtypeof*asFlightClientAPIfrom'./src/ReactFlightClient';
11+
importtypeof*asHostConfigfrom'./src/ReactFlightClientConfig';
12+
1013
export*from'./src/ReactFlightClient';
14+
15+
// At build time, this module is wrapped as a factory function ($$$reconciler).
16+
// Consumers pass a host config object and get back the Flight client API.
17+
declareexportdefault(hostConfig: HostConfig)=>FlightClientAPI;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
// This is a host config that's used for the internal `react-noop-renderer` package.
11+
//
12+
// Its API lets you pass the host config as an argument.
13+
// However, inside the `react-server` we treat host config as a module.
14+
// This file is a shim between two worlds.
15+
//
16+
// It works because the `react-server` bundle is wrapped in something like:
17+
//
18+
// module.exports = function ($$$config) {
19+
// /* renderer code */
20+
// }
21+
//
22+
// So `$$$config` looks like a global variable, but it's
23+
// really an argument to a top-level wrapping function.
24+
25+
declareconst $$$config: $FlowFixMe;
26+
27+
exportopaquetypeModuleLoading=mixed;
28+
exportopaquetypeServerConsumerModuleMap=mixed;
29+
exportopaquetypeServerManifest=mixed;
30+
exportopaquetypeServerReferenceId=string;
31+
exportopaquetypeClientReferenceMetadata=mixed;
32+
exportopaquetypeClientReference<T>=mixed;// eslint-disable-line no-unused-vars
33+
exportconstresolveClientReference=$$$config.resolveClientReference;
34+
exportconstresolveServerReference=$$$config.resolveServerReference;
35+
exportconstpreloadModule=$$$config.preloadModule;
36+
exportconstrequireModule=$$$config.requireModule;
37+
exportconstgetModuleDebugInfo=$$$config.getModuleDebugInfo;
38+
exportconstdispatchHint=$$$config.dispatchHint;
39+
exportconstprepareDestinationForModule=
40+
$$$config.prepareDestinationForModule;
41+
exportconstusedWithSSR=true;
42+
43+
exportopaquetypeSource=mixed;
44+
45+
exportopaquetypeStringDecoder=mixed;
46+
47+
exportconstcreateStringDecoder=$$$config.createStringDecoder;
48+
exportconstreadPartialStringChunk=$$$config.readPartialStringChunk;
49+
exportconstreadFinalStringChunk=$$$config.readFinalStringChunk;
50+
51+
exportconstbindToConsole=$$$config.bindToConsole;
52+
53+
exportconstrendererVersion=$$$config.rendererVersion;
54+
exportconstrendererPackageName=$$$config.rendererPackageName;
55+
56+
exportconstcheckEvalAvailabilityOnceDev=
57+
$$$config.checkEvalAvailabilityOnceDev;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
exporttypeHostContext=Object;
11+
12+
exporttypeTextInstance={
13+
text: string,
14+
id: number,
15+
parent: number,
16+
hidden: boolean,
17+
context: HostContext,
18+
};
19+
20+
exporttypeInstance={
21+
type: string,
22+
id: number,
23+
parent: number,
24+
children: Array<Instance|TextInstance>,
25+
text: string|null,
26+
prop: any,
27+
hidden: boolean,
28+
context: HostContext,
29+
};
30+
31+
exporttypePublicInstance=Instance;
32+
33+
exporttypeTransitionStatus=mixed;

‎packages/react-noop-renderer/src/ReactNoop.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const {
5353
getRoot,
5454
// TODO: Remove this after callers migrate to alternatives.
5555
unstable_runWithPriority,
56+
// $FlowFixMe[signature-verification-failure]
5657
}=createReactNoop(
5758
ReactFiberReconciler,// reconciler
5859
true,// useMutation

‎packages/react-noop-renderer/src/ReactNoopFlightClient.js‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* environment.
1515
*/
1616

17+
importtype{Thenable}from'shared/ReactTypes';
1718
importtype{FindSourceMapURLCallback}from'react-client/flight';
1819

1920
import{readModule}from'react-noop-renderer/flight-modules';
@@ -25,6 +26,7 @@ type Source = Array<Uint8Array>;
2526
constdecoderOptions={stream: true};
2627

2728
const{createResponse, createStreamState, processBinaryChunk, getRoot, close}=
29+
// $FlowFixMe[prop-missing]
2830
ReactFlightClient({
2931
createStringDecoder(){
3032
returnnewTextDecoder();
@@ -44,6 +46,7 @@ const {createResponse, createStreamState, processBinaryChunk, getRoot, close} =
4446
returnreadModule(idx);
4547
},
4648
bindToConsole(methodName,args,badgeName){
49+
// $FlowFixMe[incompatible-call]
4750
returnFunction.prototype.bind.apply(
4851
// eslint-disable-next-line react-internal/no-production-logging
4952
console[methodName],
@@ -61,8 +64,10 @@ type ReadOptions = {|
6164

6265
functionread<T>(source: Source, options: ReadOptions): Thenable<T>{
6366
constresponse=createResponse(
67+
// $FlowFixMe[incompatible-call]
6468
source,
6569
null,
70+
// $FlowFixMe[incompatible-call]
6671
null,
6772
undefined,
6873
undefined,
@@ -73,12 +78,19 @@ function read<T>(source: Source, options: ReadOptions): Thenable<T> {
7378
true,
7479
undefined,
7580
__DEV__&&options!==undefined&&options.debugChannel!==undefined
76-
? options.debugChannel.onMessage
81+
? // $FlowFixMe[incompatible-call]
82+
options.debugChannel.onMessage
7783
: undefined,
7884
);
7985
conststreamState=createStreamState(response,source);
8086
for(leti=0;i<source.length;i++){
81-
processBinaryChunk(response,streamState,source[i],0);
87+
processBinaryChunk(
88+
response,
89+
streamState,
90+
source[i],
91+
// $FlowFixMe[extra-arg]
92+
0,
93+
);
8294
}
8395
if (options !== undefined &&options.close){
8496
close(response);

‎packages/react-noop-renderer/src/ReactNoopFlightServer.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import {saveModule} from 'react-noop-renderer/flight-modules';
2020

2121
importReactFlightServerfrom'react-server/flight';
2222

23-
typeDestination=Array<Uint8Array>;
23+
typeDestination=Array<Uint8Array|string>;
2424

2525
consttextEncoder=newTextEncoder();
2626

27+
// $FlowFixMe[prop-missing]
2728
constReactNoopFlightServer=ReactFlightServer({
2829
scheduleMicrotask(callback: ()=>void){
2930
callback();
@@ -81,13 +82,15 @@ function render(model: ReactClientValue, options?: Options): Destination {
8182
constbundlerConfig=undefined;
8283
constrequest=ReactNoopFlightServer.createRequest(
8384
model,
85+
// $FlowFixMe[incompatible-call]
8486
bundlerConfig,
8587
options ? options.onError : undefined,
8688
options ? options.identifierPrefix : undefined,
8789
undefined,
8890
options ? options.startTime : undefined,
8991
__DEV__&&options ? options.environmentName : undefined,
9092
__DEV__&&options ? options.filterStackFrame : undefined,
93+
// $FlowFixMe[incompatible-call]
9194
__DEV__&&options&&options.debugChannel!==undefined,
9295
);
9396
constsignal=options ? options.signal : undefined;
@@ -108,7 +111,11 @@ function render(model: ReactClientValue, options?: Options): Destination {
108111
};
109112
}
110113
ReactNoopFlightServer.startWork(request);
111-
ReactNoopFlightServer.startFlowing(request,destination);
114+
ReactNoopFlightServer.startFlowing(
115+
request,
116+
// $FlowFixMe[incompatible-call]
117+
destination,
118+
);
112119
returndestination;
113120
}
114121

‎packages/react-noop-renderer/src/ReactNoopPersistent.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const {
5555
// TODO: Remove this once callers migrate to alternatives.
5656
// This should only be used by React internals.
5757
unstable_runWithPriority,
58+
// $FlowFixMe[signature-verification-failure]
5859
}=createReactNoop(
5960
ReactFiberReconciler,// reconciler
6061
false,// useMutation

‎packages/react-noop-renderer/src/ReactNoopServer.js‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ type SuspenseInstance = {
4040
};
4141

4242
typePlaceholder={
43-
parent: Instance|SuspenseInstance,
43+
parent: Instance|Segment|SuspenseInstance,
4444
index: number,
4545
};
4646

4747
typeSegment={
48-
children: null|Instance|TextInstance|SuspenseInstance,
48+
children: Array<Instance|TextInstance|SuspenseInstance>,
4949
};
5050

5151
typeDestination={
@@ -79,6 +79,7 @@ function write(destination: Destination, buffer: Uint8Array): void {
7979
stack.push(instance);
8080
}
8181

82+
// $FlowFixMe[prop-missing]
8283
constReactNoopServer=ReactFizzServer({
8384
scheduleMicrotask(callback: ()=>void){
8485
callback();
@@ -175,6 +176,7 @@ const ReactNoopServer = ReactFizzServer({
175176
destination: Destination,
176177
renderState: RenderState,
177178
id: number,
179+
// $FlowFixMe[incompatible-return]
178180
): boolean{
179181
constparent=destination.stack[destination.stack.length-1];
180182
destination.placeholders.set(id,{
@@ -258,7 +260,7 @@ const ReactNoopServer = ReactFizzServer({
258260
formatContext: null,
259261
id: number,
260262
): boolean{
261-
constsegment={
263+
constsegment: Segment={
262264
children: [],
263265
};
264266
destination.segments.set(id,segment);
@@ -314,6 +316,7 @@ const ReactNoopServer = ReactFizzServer({
314316
renderState: RenderState,
315317
boundary: SuspenseInstance,
316318
): boolean{
319+
// $FlowFixMe[prop-missing]
317320
boundary.status='client-render';
318321
returntrue;
319322
},
@@ -357,6 +360,7 @@ type Options = {
357360
};
358361

359362
functionrender(children: React$Element<any>,options?: Options): Destination{
363+
// $FlowFixMe[prop-missing]
360364
constdestination: Destination={
361365
root: null,
362366
placeholders: newMap(),
@@ -368,15 +372,19 @@ function render(children: React$Element<any>, options?: Options): Destination {
368372
};
369373
constrequest=ReactNoopServer.createRequest(
370374
children,
375+
// $FlowFixMe[incompatible-call]
371376
null,
377+
// $FlowFixMe[incompatible-call]
372378
null,
379+
// $FlowFixMe[incompatible-call]
373380
null,
374381
options ? options.progressiveChunkSize : undefined,
375382
options ? options.onError : undefined,
376383
options ? options.onAllReady : undefined,
377384
options ? options.onShellReady : undefined,
378385
);
379386
ReactNoopServer.startWork(request);
387+
// $FlowFixMe[incompatible-call]
380388
ReactNoopServer.startFlowing(request,destination);
381389
returndestination;
382390
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); [noop] Typecheck `react-noop-renderer` against host config and render… · react/react@5e42791 · GitHub
Skip to content

Commit 5e42791

Browse files
authored
[noop] Typecheck react-noop-renderer against host config and renderer API (#35944)
1 parent ee4699f commit 5e42791

21 files changed

Lines changed: 782 additions & 65 deletions

‎packages/react-client/flight.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@
77
* @flow
88
*/
99

10+
importtypeof*asFlightClientAPIfrom'./src/ReactFlightClient';
11+
importtypeof*asHostConfigfrom'./src/ReactFlightClientConfig';
12+
1013
export*from'./src/ReactFlightClient';
14+
15+
// At build time, this module is wrapped as a factory function ($$$reconciler).
16+
// Consumers pass a host config object and get back the Flight client API.
17+
declareexportdefault(hostConfig: HostConfig)=>FlightClientAPI;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
// This is a host config that's used for the internal `react-noop-renderer` package.
11+
//
12+
// Its API lets you pass the host config as an argument.
13+
// However, inside the `react-server` we treat host config as a module.
14+
// This file is a shim between two worlds.
15+
//
16+
// It works because the `react-server` bundle is wrapped in something like:
17+
//
18+
// module.exports = function ($$$config) {
19+
// /* renderer code */
20+
// }
21+
//
22+
// So `$$$config` looks like a global variable, but it's
23+
// really an argument to a top-level wrapping function.
24+
25+
declareconst $$$config: $FlowFixMe;
26+
27+
exportopaquetypeModuleLoading=mixed;
28+
exportopaquetypeServerConsumerModuleMap=mixed;
29+
exportopaquetypeServerManifest=mixed;
30+
exportopaquetypeServerReferenceId=string;
31+
exportopaquetypeClientReferenceMetadata=mixed;
32+
exportopaquetypeClientReference<T>=mixed;// eslint-disable-line no-unused-vars
33+
exportconstresolveClientReference=$$$config.resolveClientReference;
34+
exportconstresolveServerReference=$$$config.resolveServerReference;
35+
exportconstpreloadModule=$$$config.preloadModule;
36+
exportconstrequireModule=$$$config.requireModule;
37+
exportconstgetModuleDebugInfo=$$$config.getModuleDebugInfo;
38+
exportconstdispatchHint=$$$config.dispatchHint;
39+
exportconstprepareDestinationForModule=
40+
$$$config.prepareDestinationForModule;
41+
exportconstusedWithSSR=true;
42+
43+
exportopaquetypeSource=mixed;
44+
45+
exportopaquetypeStringDecoder=mixed;
46+
47+
exportconstcreateStringDecoder=$$$config.createStringDecoder;
48+
exportconstreadPartialStringChunk=$$$config.readPartialStringChunk;
49+
exportconstreadFinalStringChunk=$$$config.readFinalStringChunk;
50+
51+
exportconstbindToConsole=$$$config.bindToConsole;
52+
53+
exportconstrendererVersion=$$$config.rendererVersion;
54+
exportconstrendererPackageName=$$$config.rendererPackageName;
55+
56+
exportconstcheckEvalAvailabilityOnceDev=
57+
$$$config.checkEvalAvailabilityOnceDev;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
exporttypeHostContext=Object;
11+
12+
exporttypeTextInstance={
13+
text: string,
14+
id: number,
15+
parent: number,
16+
hidden: boolean,
17+
context: HostContext,
18+
};
19+
20+
exporttypeInstance={
21+
type: string,
22+
id: number,
23+
parent: number,
24+
children: Array<Instance|TextInstance>,
25+
text: string|null,
26+
prop: any,
27+
hidden: boolean,
28+
context: HostContext,
29+
};
30+
31+
exporttypePublicInstance=Instance;
32+
33+
exporttypeTransitionStatus=mixed;

‎packages/react-noop-renderer/src/ReactNoop.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const {
5353
getRoot,
5454
// TODO: Remove this after callers migrate to alternatives.
5555
unstable_runWithPriority,
56+
// $FlowFixMe[signature-verification-failure]
5657
}=createReactNoop(
5758
ReactFiberReconciler,// reconciler
5859
true,// useMutation

‎packages/react-noop-renderer/src/ReactNoopFlightClient.js‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* environment.
1515
*/
1616

17+
importtype{Thenable}from'shared/ReactTypes';
1718
importtype{FindSourceMapURLCallback}from'react-client/flight';
1819

1920
import{readModule}from'react-noop-renderer/flight-modules';
@@ -25,6 +26,7 @@ type Source = Array<Uint8Array>;
2526
constdecoderOptions={stream: true};
2627

2728
const{createResponse, createStreamState, processBinaryChunk, getRoot, close}=
29+
// $FlowFixMe[prop-missing]
2830
ReactFlightClient({
2931
createStringDecoder(){
3032
returnnewTextDecoder();
@@ -44,6 +46,7 @@ const {createResponse, createStreamState, processBinaryChunk, getRoot, close} =
4446
returnreadModule(idx);
4547
},
4648
bindToConsole(methodName,args,badgeName){
49+
// $FlowFixMe[incompatible-call]
4750
returnFunction.prototype.bind.apply(
4851
// eslint-disable-next-line react-internal/no-production-logging
4952
console[methodName],
@@ -61,8 +64,10 @@ type ReadOptions = {|
6164

6265
functionread<T>(source: Source, options: ReadOptions): Thenable<T>{
6366
constresponse=createResponse(
67+
// $FlowFixMe[incompatible-call]
6468
source,
6569
null,
70+
// $FlowFixMe[incompatible-call]
6671
null,
6772
undefined,
6873
undefined,
@@ -73,12 +78,19 @@ function read<T>(source: Source, options: ReadOptions): Thenable<T> {
7378
true,
7479
undefined,
7580
__DEV__&&options!==undefined&&options.debugChannel!==undefined
76-
? options.debugChannel.onMessage
81+
? // $FlowFixMe[incompatible-call]
82+
options.debugChannel.onMessage
7783
: undefined,
7884
);
7985
conststreamState=createStreamState(response,source);
8086
for(leti=0;i<source.length;i++){
81-
processBinaryChunk(response,streamState,source[i],0);
87+
processBinaryChunk(
88+
response,
89+
streamState,
90+
source[i],
91+
// $FlowFixMe[extra-arg]
92+
0,
93+
);
8294
}
8395
if (options !== undefined &&options.close){
8496
close(response);

‎packages/react-noop-renderer/src/ReactNoopFlightServer.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import {saveModule} from 'react-noop-renderer/flight-modules';
2020

2121
importReactFlightServerfrom'react-server/flight';
2222

23-
typeDestination=Array<Uint8Array>;
23+
typeDestination=Array<Uint8Array|string>;
2424

2525
consttextEncoder=newTextEncoder();
2626

27+
// $FlowFixMe[prop-missing]
2728
constReactNoopFlightServer=ReactFlightServer({
2829
scheduleMicrotask(callback: ()=>void){
2930
callback();
@@ -81,13 +82,15 @@ function render(model: ReactClientValue, options?: Options): Destination {
8182
constbundlerConfig=undefined;
8283
constrequest=ReactNoopFlightServer.createRequest(
8384
model,
85+
// $FlowFixMe[incompatible-call]
8486
bundlerConfig,
8587
options ? options.onError : undefined,
8688
options ? options.identifierPrefix : undefined,
8789
undefined,
8890
options ? options.startTime : undefined,
8991
__DEV__&&options ? options.environmentName : undefined,
9092
__DEV__&&options ? options.filterStackFrame : undefined,
93+
// $FlowFixMe[incompatible-call]
9194
__DEV__&&options&&options.debugChannel!==undefined,
9295
);
9396
constsignal=options ? options.signal : undefined;
@@ -108,7 +111,11 @@ function render(model: ReactClientValue, options?: Options): Destination {
108111
};
109112
}
110113
ReactNoopFlightServer.startWork(request);
111-
ReactNoopFlightServer.startFlowing(request,destination);
114+
ReactNoopFlightServer.startFlowing(
115+
request,
116+
// $FlowFixMe[incompatible-call]
117+
destination,
118+
);
112119
returndestination;
113120
}
114121

‎packages/react-noop-renderer/src/ReactNoopPersistent.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const {
5555
// TODO: Remove this once callers migrate to alternatives.
5656
// This should only be used by React internals.
5757
unstable_runWithPriority,
58+
// $FlowFixMe[signature-verification-failure]
5859
}=createReactNoop(
5960
ReactFiberReconciler,// reconciler
6061
false,// useMutation

‎packages/react-noop-renderer/src/ReactNoopServer.js‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ type SuspenseInstance = {
4040
};
4141

4242
typePlaceholder={
43-
parent: Instance|SuspenseInstance,
43+
parent: Instance|Segment|SuspenseInstance,
4444
index: number,
4545
};
4646

4747
typeSegment={
48-
children: null|Instance|TextInstance|SuspenseInstance,
48+
children: Array<Instance|TextInstance|SuspenseInstance>,
4949
};
5050

5151
typeDestination={
@@ -79,6 +79,7 @@ function write(destination: Destination, buffer: Uint8Array): void {
7979
stack.push(instance);
8080
}
8181

82+
// $FlowFixMe[prop-missing]
8283
constReactNoopServer=ReactFizzServer({
8384
scheduleMicrotask(callback: ()=>void){
8485
callback();
@@ -175,6 +176,7 @@ const ReactNoopServer = ReactFizzServer({
175176
destination: Destination,
176177
renderState: RenderState,
177178
id: number,
179+
// $FlowFixMe[incompatible-return]
178180
): boolean{
179181
constparent=destination.stack[destination.stack.length-1];
180182
destination.placeholders.set(id,{
@@ -258,7 +260,7 @@ const ReactNoopServer = ReactFizzServer({
258260
formatContext: null,
259261
id: number,
260262
): boolean{
261-
constsegment={
263+
constsegment: Segment={
262264
children: [],
263265
};
264266
destination.segments.set(id,segment);
@@ -314,6 +316,7 @@ const ReactNoopServer = ReactFizzServer({
314316
renderState: RenderState,
315317
boundary: SuspenseInstance,
316318
): boolean{
319+
// $FlowFixMe[prop-missing]
317320
boundary.status='client-render';
318321
returntrue;
319322
},
@@ -357,6 +360,7 @@ type Options = {
357360
};
358361

359362
functionrender(children: React$Element<any>,options?: Options): Destination{
363+
// $FlowFixMe[prop-missing]
360364
constdestination: Destination={
361365
root: null,
362366
placeholders: newMap(),
@@ -368,15 +372,19 @@ function render(children: React$Element<any>, options?: Options): Destination {
368372
};
369373
constrequest=ReactNoopServer.createRequest(
370374
children,
375+
// $FlowFixMe[incompatible-call]
371376
null,
377+
// $FlowFixMe[incompatible-call]
372378
null,
379+
// $FlowFixMe[incompatible-call]
373380
null,
374381
options ? options.progressiveChunkSize : undefined,
375382
options ? options.onError : undefined,
376383
options ? options.onAllReady : undefined,
377384
options ? options.onShellReady : undefined,
378385
);
379386
ReactNoopServer.startWork(request);
387+
// $FlowFixMe[incompatible-call]
380388
ReactNoopServer.startFlowing(request,destination);
381389
returndestination;
382390
}

0 commit comments

Comments
 (0)