Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flow] enable LTI inference mode #26104

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"eslint-plugin-react-internal": "link:./scripts/eslint-rules",
"fbjs-scripts": "^3.0.1",
"filesize": "^6.0.1",
"flow-bin": "^0.199.0",
"flow-bin": "^0.199.1",
"flow-remove-types": "^2.198.2",
"glob": "^7.1.6",
"glob-stream": "^6.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-react/src/internalAct.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function act<T>(scope: () => Thenable<T> | T): Thenable<T> {
) {
const thenableResult: Thenable<T> = (result: any);
return {
then(resolve, reject) {
then(resolve: T => mixed, reject: mixed => mixed) {
thenableResult.then(
returnValue => {
flushActWork(
Expand Down Expand Up @@ -108,7 +108,7 @@ export function act<T>(scope: () => Thenable<T> | T): Thenable<T> {
didFlushWork = Scheduler.unstable_flushAllWithoutAsserting();
} while (didFlushWork);
return {
then(resolve, reject) {
then(resolve: T => mixed, reject: mixed => mixed) {
resolve(returnValue);
},
};
Expand Down
4 changes: 2 additions & 2 deletions packages/react-cache/src/ReactCacheOld.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ function identityHashFn(input) {
}

const CACHE_LIMIT = 500;
const lru = createLRU(CACHE_LIMIT);
const lru = createLRU<$FlowFixMe>(CACHE_LIMIT);

const entries: Map<Resource<any, any>, Map<any, any>> = new Map();

const CacheContext = React.createContext(null);
const CacheContext = React.createContext<mixed>(null);

function accessResult<I, K, V>(
resource: any,
Expand Down
11 changes: 5 additions & 6 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ Chunk.prototype.then = function <T>(
case BLOCKED:
if (resolve) {
if (chunk.value === null) {
chunk.value = [];
chunk.value = ([]: Array<(T) => mixed>);
}
chunk.value.push(resolve);
}
if (reject) {
if (chunk.reason === null) {
chunk.reason = [];
chunk.reason = ([]: Array<(mixed) => mixed>);
}
chunk.reason.push(reject);
}
Expand Down Expand Up @@ -435,7 +435,7 @@ function createModelResolver<T>(
chunk: SomeChunk<T>,
parentObject: Object,
key: string,
) {
): (value: any) => void {
let blocked;
if (initializingChunkBlockedModel) {
blocked = initializingChunkBlockedModel;
Expand All @@ -446,7 +446,6 @@ function createModelResolver<T>(
value: null,
};
}
// $FlowFixMe[missing-local-annot]
return value => {
parentObject[key] = value;
blocked.deps--;
Expand All @@ -465,7 +464,7 @@ function createModelResolver<T>(
};
}

function createModelReject<T>(chunk: SomeChunk<T>) {
function createModelReject<T>(chunk: SomeChunk<T>): (error: mixed) => void {
return (error: mixed) => triggerErrorOnChunk(chunk, error);
}

Expand Down Expand Up @@ -583,7 +582,7 @@ export function resolveModule(
const chunks = response._chunks;
const chunk = chunks.get(id);
const moduleMetaData: ModuleMetaData = parseModel(response, model);
const moduleReference = resolveClientReference(
const moduleReference = resolveClientReference<$FlowFixMe>(
response._bundlerConfig,
moduleMetaData,
);
Expand Down
6 changes: 3 additions & 3 deletions packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
// This initializes a cache of all primitive hooks so that the top
// most stack frames added by calling the primitive hook can be removed.
if (primitiveStackCache === null) {
const cache = new Map();
const cache = new Map<string, Array<any>>();
let readHookLog;
try {
// Use all hooks here to add them to the hook log.
Dispatcher.useContext(({_currentValue: null}: any));
Dispatcher.useState(null);
Dispatcher.useReducer((s, a) => s, null);
Dispatcher.useReducer((s: mixed, a: mixed) => s, null);
Dispatcher.useRef(null);
if (typeof Dispatcher.useCacheRefresh === 'function') {
// This type check is for Flow only.
Expand Down Expand Up @@ -809,7 +809,7 @@ export function inspectHooksOfFiber(
// Set up the current hook so that we can step through and read the
// current state from them.
currentHook = (fiber.memoizedState: Hook);
const contextMap = new Map();
const contextMap = new Map<ReactContext<$FlowFixMe>, $FlowFixMe>();
try {
setupContexts(contextMap, fiber);
if (fiber.tag === ForwardRef) {
Expand Down
6 changes: 3 additions & 3 deletions packages/react-devtools-core/src/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function connectToDevTools(options: ?ConnectOptions) {
useHttps = false,
port = 8097,
websocket,
resolveRNStyle = null,
resolveRNStyle = (null: $FlowFixMe),
retryConnectionDelay = 2000,
isAppActive = () => true,
devToolsSettingsManager,
Expand Down Expand Up @@ -230,7 +230,7 @@ export function connectToDevTools(options: ?ConnectOptions) {
get() {
return lazyResolveRNStyle;
},
set(value) {
set(value: $FlowFixMe) {
lazyResolveRNStyle = value;
initAfterTick();
},
Expand All @@ -246,7 +246,7 @@ export function connectToDevTools(options: ?ConnectOptions) {
get() {
return lazyNativeStyleEditorValidAttributes;
},
set(value) {
set(value: $FlowFixMe) {
lazyNativeStyleEditorValidAttributes = value;
initAfterTick();
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-core/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export function launchEditor(
}
childProcess.on('error', function () {});
// $FlowFixMe[incompatible-use] found when upgrading Flow
childProcess.on('exit', function (errorCode) {
childProcess.on('exit', function () {
childProcess = null;
});
}
8 changes: 4 additions & 4 deletions packages/react-devtools-core/src/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function onDisconnected() {
}

// $FlowFixMe[missing-local-annot]
function onError({code, message}) {
function onError({code, message}: $FlowFixMe) {
safeUnmount();

if (code === 'EADDRINUSE') {
Expand Down Expand Up @@ -335,13 +335,13 @@ function startServer(
initialize(socket);
});

server.on('error', event => {
server.on('error', (event: $FlowFixMe) => {
onError(event);
log.error('Failed to start the DevTools server', event);
startServerTimeoutID = setTimeout(() => startServer(port), 1000);
});

httpServer.on('request', (request, response) => {
httpServer.on('request', (request: $FlowFixMe, response: $FlowFixMe) => {
// Serve a file that immediately sets up the connection.
const backendFile = readFileSync(join(__dirname, 'backend.js'));

Expand Down Expand Up @@ -377,7 +377,7 @@ function startServer(
);
});

httpServer.on('error', event => {
httpServer.on('error', (event: $FlowFixMe) => {
onError(event);
statusListener('Failed to start the server.', 'error');
startServerTimeoutID = setTimeout(() => startServer(port), 1000);
Expand Down
5 changes: 2 additions & 3 deletions packages/react-devtools-extensions/src/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let welcomeHasInitialized = false;

// $FlowFixMe[missing-local-annot]
function welcome(event) {
function welcome(event: $FlowFixMe) {
if (
event.source !== window ||
event.data.source !== 'react-devtools-content-script'
Expand Down Expand Up @@ -56,8 +56,7 @@ function setup(hook: any) {

const bridge = new Bridge({
listen(fn) {
// $FlowFixMe[missing-local-annot]
const listener = event => {
const listener = (event: $FlowFixMe) => {
if (
event.source !== window ||
!event.data ||
Expand Down
6 changes: 2 additions & 4 deletions packages/react-devtools-inline/src/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import type {BackendBridge} from 'react-devtools-shared/src/bridge';
import type {Wall} from 'react-devtools-shared/src/types';

function startActivation(contentWindow: any, bridge: BackendBridge) {
// $FlowFixMe[missing-local-annot]
const onSavedPreferences = data => {
const onSavedPreferences = (data: $FlowFixMe) => {
// This is the only message we're listening for,
// so it's safe to cleanup after we've received it.
bridge.removeListener('savedPreferences', onSavedPreferences);
Expand Down Expand Up @@ -102,8 +101,7 @@ export function createBridge(contentWindow: any, wall?: Wall): BackendBridge {
if (wall == null) {
wall = {
listen(fn) {
// $FlowFixMe[missing-local-annot]
const onMessage = ({data}) => {
const onMessage = ({data}: $FlowFixMe) => {
fn(data);
};
contentWindow.addEventListener('message', onMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let reentry = false;
let componentFrameCache;
if (__DEV__) {
const PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
componentFrameCache = new PossiblyWeakMap();
componentFrameCache = new PossiblyWeakMap<$FlowFixMe, string>();
}

export function describeNativeComponentFrame(
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/backend/StyleX/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import isArray from 'react-devtools-shared/src/isArray';
const cachedStyleNameToValueMap: Map<string, string> = new Map();

export function getStyleXData(data: any): StyleXPlugin {
const sources = new Set();
const sources = new Set<string>();
const resolvedStyles = {};

crawlData(data, sources, resolvedStyles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ export function attach(
const numUnmountIDs =
pendingUnmountedIDs.length + (pendingUnmountedRootID === null ? 0 : 1);

const operations = new Array(
const operations = new Array<number>(
// Identify which renderer this update is coming from.
2 + // [rendererID, rootFiberID]
// How big is the string table?
Expand Down
13 changes: 8 additions & 5 deletions packages/react-devtools-shared/src/backend/profilingHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
import type {Wakeable} from 'shared/ReactTypes';
import type {
BatchUID,
InternalModuleSourceToRanges,
LaneToLabelMap,
ReactComponentMeasure,
ReactLane,
ReactMeasure,
ReactMeasureType,
TimelineData,
SuspenseEvent,
SchedulingEvent,
ReactScheduleStateUpdateEvent,
SchedulingEvent,
SuspenseEvent,
TimelineData,
} from 'react-devtools-timeline/src/types';

import isArray from 'shared/isArray';
Expand Down Expand Up @@ -837,7 +839,8 @@ export function createProfilingHooks({
isProfiling = value;

if (isProfiling) {
const internalModuleSourceToRanges = new Map();
const internalModuleSourceToRanges: InternalModuleSourceToRanges =
new Map();

if (supportsUserTimingV3) {
const ranges = getInternalModuleRanges();
Expand All @@ -856,7 +859,7 @@ export function createProfilingHooks({
}
}

const laneToReactMeasureMap = new Map();
const laneToReactMeasureMap = new Map<ReactLane, ReactMeasure[]>();
let lane = 1;
for (let index = 0; index < REACT_TOTAL_NUM_LANES; index++) {
laneToReactMeasureMap.set(lane, []);
Expand Down
10 changes: 5 additions & 5 deletions packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export function getInternalReactConstants(version: string): {
TracingMarkerComponent,
} = ReactTypeOfWork;

function resolveFiberType(type: any) {
function resolveFiberType(type: any): $FlowFixMe {
const typeSymbol = getTypeSymbol(type);
switch (typeSymbol) {
case MEMO_NUMBER:
Expand Down Expand Up @@ -1627,7 +1627,7 @@ export function attach(
}
}

let flushPendingErrorsAndWarningsAfterDelayTimeoutID = null;
let flushPendingErrorsAndWarningsAfterDelayTimeoutID: null | TimeoutID = null;

function clearPendingErrorsAndWarningsAfterDelay() {
if (flushPendingErrorsAndWarningsAfterDelayTimeoutID !== null) {
Expand Down Expand Up @@ -1790,7 +1790,7 @@ export function attach(
pendingSimulatedUnmountedIDs.length +
(pendingUnmountedRootID === null ? 0 : 1);

const operations = new Array(
const operations = new Array<number>(
// Identify which renderer this update is coming from.
2 + // [rendererID, rootFiberID]
// How big is the string table?
Expand Down Expand Up @@ -4144,7 +4144,7 @@ export function attach(

// Map of id and its force error status: true (error), false (toggled off),
// null (do nothing)
const forceErrorForFiberIDs = new Map();
const forceErrorForFiberIDs = new Map<number | null, $FlowFixMe>();

function shouldErrorFiberAccordingToMap(fiber: any) {
if (typeof setErrorHandler !== 'function') {
Expand Down Expand Up @@ -4209,7 +4209,7 @@ export function attach(
return false;
}

const forceFallbackForSuspenseIDs = new Set();
const forceFallbackForSuspenseIDs = new Set<number>();

function shouldSuspendFiberAccordingToSet(fiber: any) {
const maybeID = getFiberIDUnsafe(((fiber: any): Fiber));
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/backend/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function getEffectDurations(root: Object): {
}

export function serializeToString(data: any): string {
const cache = new Set();
const cache = new Set<mixed>();
// Use a custom replacer function to protect against circular references.
return JSON.stringify(data, (key, value) => {
if (typeof value === 'object' && value !== null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/backend/views/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function getNestedBoundingClientRect(
): Rect {
const ownerIframe = getOwnerIframe(node);
if (ownerIframe && ownerIframe !== boundaryWindow) {
const rects = [node.getBoundingClientRect()];
const rects: Array<Rect | ClientRect> = [node.getBoundingClientRect()];
let currentIframe: null | HTMLElement = ownerIframe;
let onlyOneMore = false;
while (currentIframe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export default class ProfilerStore extends EventEmitter<{
// Record snapshot of tree at the time profiling is started.
// This info is required to handle cases of e.g. nodes being removed during profiling.
this._store.roots.forEach(rootID => {
const profilingSnapshots = new Map();
const profilingSnapshots = new Map<number, SnapshotNode>();
this._initialSnapshotsByRootID.set(rootID, profilingSnapshots);
this._takeProfilingSnapshotRecursive(rootID, profilingSnapshots);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/react-devtools-shared/src/devtools/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ export default class Store extends EventEmitter<{
}

getOwnersListForElement(ownerID: number): Array<Element> {
const list = [];
const list: Array<Element> = [];
const element = this._idToElement.get(ownerID);
if (element != null) {
list.push({
Expand Down Expand Up @@ -900,7 +900,7 @@ export default class Store extends EventEmitter<{
let i = 2;

// Reassemble the string table.
const stringTable = [
const stringTable: Array<string | null> = [
null, // ID = 0 corresponds to the null string.
];
const stringTableSize = operations[i++];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function EditableName({
const [isValid, setIsValid] = useState(false);

const handleChange = useCallback(
({target}) => {
({target}: $FlowFixMe) => {
let value = target.value;
if (!allowWhiteSpace) {
value = value.trim();
Expand All @@ -61,7 +61,7 @@ export default function EditableName({
);

const handleKeyDown = useCallback(
event => {
(event: $FlowFixMe) => {
// Prevent keydown events from e.g. change selected element in the tree
event.stopPropagation();

Expand Down
Loading