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: upgrade to 0.140 #25252

Merged
merged 2 commits into from
Sep 13, 2022
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 @@ -63,7 +63,7 @@
"eslint-plugin-react-internal": "link:./scripts/eslint-rules",
"fbjs-scripts": "1.2.0",
"filesize": "^6.0.1",
"flow-bin": "^0.132",
"flow-bin": "^0.140",
"glob": "^7.1.6",
"glob-stream": "^6.1.0",
"google-closure-compiler": "^20200517.0.0",
Expand Down
11 changes: 9 additions & 2 deletions packages/react-cache/src/LRU.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ type Entry<T> = {
next: Entry<T>,
};

export function createLRU<T>(limit: number) {
type LRU<T> = {
add(value: Object, onDelete: () => mixed): Entry<Object>,
update(entry: Entry<T>, newValue: T): void,
access(entry: Entry<T>): T,
setLimit(newLimit: number): void,
};

export function createLRU<T>(limit: number): LRU<T> {
let LIMIT = limit;

// Circular, doubly-linked list
Expand Down Expand Up @@ -135,7 +142,7 @@ export function createLRU<T>(limit: number) {
return entry.value;
}

function setLimit(newLimit: number) {
function setLimit(newLimit: number): void {
LIMIT = newLimit;
scheduleCleanUp();
}
Expand Down
1 change: 1 addition & 0 deletions packages/react-cache/src/ReactCacheOld.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function accessResult<I, K, V>(
status: Pending,
value: thenable,
};
// $FlowFixMe[escaped-generic] discovered when updating Flow
const newEntry = lru.add(newResult, deleteEntry.bind(null, resource, key));
entriesForResource.set(key, newEntry);
return newResult;
Expand Down
1 change: 1 addition & 0 deletions packages/react-dom/src/client/ReactDOMInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export function updateWrapper(element: Element, props: Object) {
if (value != null) {
if (type === 'number') {
if (
// $FlowFixMe[incompatible-type]
(value === 0 && node.value === '') ||
// We explicitly want to coerce to number here if possible.
// eslint-disable-next-line
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dom/src/server/ReactDOMFizzServerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import type {ReactNodeList} from 'shared/ReactTypes';
import type {Writable} from 'stream';
import type {BootstrapScriptDescriptor} from './ReactDOMServerFormatConfig';
import type {Destination} from 'react-server/src/ReactServerStreamConfigNode';

import ReactVersion from 'shared/ReactVersion';

Expand All @@ -25,7 +26,7 @@ import {
createRootFormatContext,
} from './ReactDOMServerFormatConfig';

function createDrainHandler(destination, request) {
function createDrainHandler(destination: Destination, request) {
return () => startFlowing(request, destination);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ function accumulate<T>(
// Both are not empty. Warning: Never call x.concat(y) when you are not
// certain that x is an Array (x could be a string with concat method).
if (isArray(current)) {
/* $FlowFixMe[incompatible-return] if `current` is `T` and `T` an array,
* `isArray` might refine to the array element type of `T` */
return current.concat(next);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function forEachAccumulated<T>(
scope: ?any,
) {
if (Array.isArray(arr)) {
// $FlowFixMe[incompatible-call] if `T` is an array, `cb` cannot be called
arr.forEach(cb, scope);
} else if (arr) {
cb.call(scope, arr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ export function processUpdateQueue<State>(
hasForceUpdate = false;

if (__DEV__) {
// $FlowFixMe[escaped-generic] discovered when updating Flow
currentlyProcessingQueue = queue.shared;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ export function processUpdateQueue<State>(
hasForceUpdate = false;

if (__DEV__) {
// $FlowFixMe[escaped-generic] discovered when updating Flow
currentlyProcessingQueue = queue.shared;
}

Expand Down
25 changes: 18 additions & 7 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export type Effect = {
tag: HookFlags,
create: () => (() => void) | void,
destroy: (() => void) | void,
deps: Array<mixed> | null,
deps: Array<mixed> | void | null,
next: Effect,
};

Expand Down Expand Up @@ -1539,7 +1539,7 @@ function updateStoreInstance<T>(
}
}

function subscribeToStore(fiber, inst, subscribe) {
function subscribeToStore<T>(fiber, inst: StoreInstance<T>, subscribe) {
const handleStoreChange = () => {
// The store changed. Check if the snapshot changed since the last time we
// read from the store.
Expand All @@ -1552,7 +1552,7 @@ function subscribeToStore(fiber, inst, subscribe) {
return subscribe(handleStoreChange);
}

function checkIfSnapshotChanged(inst) {
function checkIfSnapshotChanged<T>(inst: StoreInstance<T>): boolean {
const latestGetSnapshot = inst.getSnapshot;
const prevValue = inst.value;
try {
Expand Down Expand Up @@ -1609,7 +1609,7 @@ function rerenderState<S>(
return rerenderReducer(basicStateReducer, (initialState: any));
}

function pushEffect(tag, create, destroy, deps) {
function pushEffect(tag, create, destroy, deps: Array<mixed> | void | null) {
const effect: Effect = {
tag,
create,
Expand Down Expand Up @@ -1728,7 +1728,12 @@ function updateRef<T>(initialValue: T): {current: T} {
return hook.memoizedState;
}

function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
function mountEffectImpl(
fiberFlags,
hookFlags,
create,
deps: Array<mixed> | void | null,
): void {
const hook = mountWorkInProgressHook();
const nextDeps = deps === undefined ? null : deps;
currentlyRenderingFiber.flags |= fiberFlags;
Expand All @@ -1740,7 +1745,12 @@ function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
);
}

function updateEffectImpl(fiberFlags, hookFlags, create, deps): void {
function updateEffectImpl(
fiberFlags,
hookFlags,
create,
deps: Array<mixed> | void | null,
): void {
const hook = updateWorkInProgressHook();
const nextDeps = deps === undefined ? null : deps;
let destroy = undefined;
Expand Down Expand Up @@ -2395,7 +2405,7 @@ function entangleTransitionUpdate<S, A>(
}
}

function markUpdateInDevTools(fiber, lane, action) {
function markUpdateInDevTools<A>(fiber, lane, action: A) {
if (__DEV__) {
if (enableDebugTracing) {
if (fiber.mode & DebugTracingMode) {
Expand Down Expand Up @@ -2490,6 +2500,7 @@ const HooksDispatcherOnMount: Dispatcher = {
if (enableCache) {
(HooksDispatcherOnMount: Dispatcher).getCacheSignal = getCacheSignal;
(HooksDispatcherOnMount: Dispatcher).getCacheForType = getCacheForType;
// $FlowFixMe[escaped-generic] discovered when updating Flow
(HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh;
}
if (enableUseHook) {
Expand Down
25 changes: 18 additions & 7 deletions packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export type Effect = {
tag: HookFlags,
create: () => (() => void) | void,
destroy: (() => void) | void,
deps: Array<mixed> | null,
deps: Array<mixed> | void | null,
next: Effect,
};

Expand Down Expand Up @@ -1539,7 +1539,7 @@ function updateStoreInstance<T>(
}
}

function subscribeToStore(fiber, inst, subscribe) {
function subscribeToStore<T>(fiber, inst: StoreInstance<T>, subscribe) {
const handleStoreChange = () => {
// The store changed. Check if the snapshot changed since the last time we
// read from the store.
Expand All @@ -1552,7 +1552,7 @@ function subscribeToStore(fiber, inst, subscribe) {
return subscribe(handleStoreChange);
}

function checkIfSnapshotChanged(inst) {
function checkIfSnapshotChanged<T>(inst: StoreInstance<T>): boolean {
const latestGetSnapshot = inst.getSnapshot;
const prevValue = inst.value;
try {
Expand Down Expand Up @@ -1609,7 +1609,7 @@ function rerenderState<S>(
return rerenderReducer(basicStateReducer, (initialState: any));
}

function pushEffect(tag, create, destroy, deps) {
function pushEffect(tag, create, destroy, deps: Array<mixed> | void | null) {
const effect: Effect = {
tag,
create,
Expand Down Expand Up @@ -1728,7 +1728,12 @@ function updateRef<T>(initialValue: T): {current: T} {
return hook.memoizedState;
}

function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
function mountEffectImpl(
fiberFlags,
hookFlags,
create,
deps: Array<mixed> | void | null,
): void {
const hook = mountWorkInProgressHook();
const nextDeps = deps === undefined ? null : deps;
currentlyRenderingFiber.flags |= fiberFlags;
Expand All @@ -1740,7 +1745,12 @@ function mountEffectImpl(fiberFlags, hookFlags, create, deps): void {
);
}

function updateEffectImpl(fiberFlags, hookFlags, create, deps): void {
function updateEffectImpl(
fiberFlags,
hookFlags,
create,
deps: Array<mixed> | void | null,
): void {
const hook = updateWorkInProgressHook();
const nextDeps = deps === undefined ? null : deps;
let destroy = undefined;
Expand Down Expand Up @@ -2395,7 +2405,7 @@ function entangleTransitionUpdate<S, A>(
}
}

function markUpdateInDevTools(fiber, lane, action) {
function markUpdateInDevTools<A>(fiber, lane, action: A) {
if (__DEV__) {
if (enableDebugTracing) {
if (fiber.mode & DebugTracingMode) {
Expand Down Expand Up @@ -2490,6 +2500,7 @@ const HooksDispatcherOnMount: Dispatcher = {
if (enableCache) {
(HooksDispatcherOnMount: Dispatcher).getCacheSignal = getCacheSignal;
(HooksDispatcherOnMount: Dispatcher).getCacheForType = getCacheForType;
// $FlowFixMe[escaped-generic] discovered when updating Flow
(HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh;
}
if (enableUseHook) {
Expand Down
1 change: 1 addition & 0 deletions packages/react-refresh/src/ReactFreshRuntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ export function createSignatureFunctionForTransform() {
// in HOC chains like _s(hoc1(_s(hoc2(_s(actualFunction))))).
if (!savedType) {
// We're in the innermost call, so this is the actual type.
// $FlowFixMe[escaped-generic] discovered when updating Flow
savedType = type;
hasCustomHooks = typeof getCustomHooks === 'function';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import type {ReactModel} from 'react-server/src/ReactFlightServer';
import type {Destination} from 'react-server/src/ReactServerStreamConfigNode';
import type {BundlerConfig} from './ReactFlightServerWebpackBundlerConfig';
import type {Writable} from 'stream';
import type {ServerContextJSONValue} from 'shared/ReactTypes';
Expand All @@ -19,7 +20,7 @@ import {
abort,
} from 'react-server/src/ReactFlightServer';

function createDrainHandler(destination, request) {
function createDrainHandler(destination: Destination, request) {
return () => startFlowing(request, destination);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ export function useSyncExternalStore<T>(
return value;
}

function checkIfSnapshotChanged(inst) {
function checkIfSnapshotChanged<T>(inst: {
value: T,
getSnapshot: () => T,
}): boolean {
const latestGetSnapshot = inst.getSnapshot;
const prevValue = inst.value;
try {
Expand Down
3 changes: 2 additions & 1 deletion scripts/flow/config/flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ esproposal.class_instance_fields=enable
esproposal.optional_chaining=enable
exact_by_default=true
munge_underscores=false
types_first=false

# Substituted by createFlowConfig.js:
%REACT_RENDERER_FLOW_OPTIONS%

[version]
^0.132.0
^0.140.0
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7914,10 +7914,10 @@ flatted@^2.0.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138"
integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==

flow-bin@^0.132:
version "0.132.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.132.0.tgz#8bf80a79630db24bd1422dc2cc4b5e97f97ccb98"
integrity sha512-S1g/vnAyNaLUdajmuUHCMl30qqye12gS6mr4LVyswf1k+JDF4efs6SfKmptuvnpitF3LGCVf0TIffChP8ljwnw==
flow-bin@^0.140:
version "0.140.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.140.0.tgz#bf1a2984a0e5604daa0d1e0432138d9897af65bb"
integrity sha512-9P/VciKACXocClhLiDg/p1ntYmgCEEc9QrNOoTqTi2SEdEZDTiAmJLONRJfw4uglPVRZ1p/esWF9KlbZiuxqVw==

fluent-syntax@0.13.0:
version "0.13.0"
Expand Down