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 well_formed_exports for shared #25343

Merged
merged 1 commit into from
Oct 4, 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
9 changes: 9 additions & 0 deletions packages/react/src/ReactServerContextRegistry.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {ReactServerContext} from 'shared/ReactTypes';

export const ContextRegistry: {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/ReactErrorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function hasCaughtError(): boolean {
return hasError;
}

export function clearCaughtError() {
export function clearCaughtError(): mixed {
if (hasError) {
const error = caughtError;
hasError = false;
Expand Down
6 changes: 5 additions & 1 deletion packages/shared/ReactServerContextRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
* @flow
*/

import type {ReactServerContext} from 'shared/ReactTypes';

import {REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED} from 'shared/ReactSymbols';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {createServerContext} from 'react';

const ContextRegistry = ReactSharedInternals.ContextRegistry;

export function getOrCreateServerContext(globalName: string) {
export function getOrCreateServerContext(
globalName: string,
): ReactServerContext<any> {
if (!ContextRegistry[globalName]) {
ContextRegistry[globalName] = createServerContext(
globalName,
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/enqueueTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let didWarnAboutMessageChannel = false;
let enqueueTaskImpl = null;

export default function enqueueTask(task: () => void) {
export default function enqueueTask(task: () => void): void {
if (enqueueTaskImpl === null) {
try {
// read require off the module object to get around the bundlers.
Expand Down
39 changes: 12 additions & 27 deletions packages/shared/invokeGuardedCallbackImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@
* @flow
*/

function invokeGuardedCallbackProd<A, B, C, D, E, F, Context>(
function invokeGuardedCallbackProd<Args: Array<mixed>, Context>(
name: string | null,
func: (a: A, b: B, c: C, d: D, e: E, f: F) => mixed,
func: (...Args) => mixed,
context: Context,
a: A,
b: B,
c: C,
d: D,
e: E,
f: F,
) {
): void {
const funcArgs = Array.prototype.slice.call(arguments, 3);
try {
// $FlowFixMe[incompatible-call] Flow doesn't understand the arguments splicing.
func.apply(context, funcArgs);
} catch (error) {
this.onError(error);
}
}

let invokeGuardedCallbackImpl = invokeGuardedCallbackProd;
let invokeGuardedCallbackImpl: <Args: Array<mixed>, Context>(
name: string | null,
func: (...Args) => mixed,
context: Context,
) => void = invokeGuardedCallbackProd;

if (__DEV__) {
// In DEV mode, we swap out invokeGuardedCallback for a special version
Expand Down Expand Up @@ -59,24 +58,9 @@ if (__DEV__) {
const fakeNode = document.createElement('react');

invokeGuardedCallbackImpl = function invokeGuardedCallbackDev<
A,
B,
C,
D,
E,
F,
Args: Array<mixed>,
Context,
>(
name: string | null,
func: (a: A, b: B, c: C, d: D, e: E, f: F) => mixed,
context: Context,
a: A,
b: B,
c: C,
d: D,
e: E,
f: F,
) {
>(name: string | null, func: (...Args) => mixed, context: Context): void {
Copy link
Collaborator

@sebmarkbage sebmarkbage Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works because we're not calling it with anything more specific, right? Othewise it might be an error to use this now because it would just pass "mixed" to all arguments of the callback.

Copy link
Member Author

@kassens kassens Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// If document doesn't exist we know for sure we will crash in this method
// when we call document.createEvent(). However this can cause confusing
// errors: https://github.com/facebook/create-react-app/issues/3482
Expand Down Expand Up @@ -142,6 +126,7 @@ if (__DEV__) {
function callCallback() {
didCall = true;
restoreAfterDispatch();
// $FlowFixMe[incompatible-call] Flow doesn't understand the arguments splicing.
func.apply(context, funcArgs);
didError = false;
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/flow/config/flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ well_formed_exports.includes=<PROJECT_ROOT>/packages/react-server-native-relay
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-suspense-test-utils
; well_formed_exports.includes=<PROJECT_ROOT>/packages/react-test-renderer
well_formed_exports.includes=<PROJECT_ROOT>/packages/scheduler
; well_formed_exports.includes=<PROJECT_ROOT>/packages/shared
well_formed_exports.includes=<PROJECT_ROOT>/packages/shared
well_formed_exports.includes=<PROJECT_ROOT>/packages/use-subscription
well_formed_exports.includes=<PROJECT_ROOT>/packages/use-sync-external-store

Expand Down