facebook / facebook/flow

Slow startup when using SyntheticEvent in flow-typed libdef

Open
#6,290 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

From discussion in https://github.com/flowtype/flow-typed/pull/2171

The latest update to the Formik libdef caused flow initialization to go from a handful of seconds to over a minute. While investigating, it appears that the introduction of using SyntheticEvent in FormikHandlers is the line that caused the slowdown.

Steps to reproduce
1. Clone flow-typed
`git clone git@github.com:flowtype/flow-typed.git`

2. Globally install flow-typed
`yarn global add flow-typed`

3. cd into flow-typed folder
`cd flow-typed`

4. Run Formik tests
`flow-typed run-tests formik_v0.11.x`

The tests will take over a minute to run.

To make the tests run fast again, replace the two uses of SyntheticEvent (https://github.com/flowtype/flow-typed/blob/master/definitions/npm/formik_v0.11.x/flow_v0.53.x-/formik_v0.11.x.js#L158 and (https://github.com/flowtype/flow-typed/blob/master/definitions/npm/formik_v0.11.x/flow_v0.53.x-/formik_v0.11.x.js#L160)) with any. So FormikHandlers looks like

```
declare export type FormikHandlers = {
/** Form submit handler */
handleSubmit: (e: any) => any,
/** Classic React change handler, keyed by input name */
handleChange: (e: any) => any,
/** Classic React blur handler */
handleBlur: (e: any) => void,
/** Reset form event handler */
handleReset: () => void
};
```

The tests now run very quickly.

https://github.com/facebook/flow/issues/5856 and https://github.com/facebook/flow/issues/5858 may very well be related, but this is odd because of the dependence on SyntheticEvent. Other libdefs (like [redux_form](https://github.com/flowtype/flow-typed/blob/master/definitions/npm/redux-form_v5.x.x/flow_v0.53.x-/redux-form_v5.x.x.js#L16)) are using SyntheticEvent without a slowdown.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.