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

Update Flow to 0.70 #12875

Merged
merged 4 commits into from
May 21, 2018
Merged

Update Flow to 0.70 #12875

merged 4 commits into from
May 21, 2018

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented May 21, 2018

The errors are beautiful 😍 😍 😍

Thanks @calebmer, @leebyron and everybody who made that happen:

screen shot 2018-05-21 at 5 18 14 pm

(This is a demo, the PR shouldn’t have any errors :-)

if (possibleMap.entries === iteratorFn) {
const maybeMap = (newChildrenIterable: any);
if (typeof maybeMap.entries === 'function') {
if (maybeMap.entries === iteratorFn) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The outer conditional could be removed?

Map.prototype == null ||
typeof Map.prototype.forEach !== 'function' ||
typeof Set !== 'function' ||
// $FlowIssue Flow incorrectly thinks Set has no prototype
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Posted about this internally.

if (
isCustomComponentTag &&
!didWarnShadyDOM &&
(domElement: any).shadyRoot
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not a real property (we're detecting a bad polyfill). Fair game IMO.

@@ -63,20 +63,21 @@ function trackValueOnNode(node: any): ?ValueTracker {
// (needed for certain tests that spyOn input values and Safari)
if (
node.hasOwnProperty(valueField) ||
typeof descriptor === 'undefined' ||
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In theory this could happen and then the code would crash.
I'm not sure this is possible in practice.

Choose a reason for hiding this comment

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

Happened to me in practice :)

typeof descriptor.get !== 'function' ||
typeof descriptor.set !== 'function'
) {
return;
}

const {get, set} = descriptor;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Help Flow know these exist (we just refined).

if (hostInstance.canonical) {
// TODO: the code is right but the types here are wrong.
// https://github.com/facebook/react/pull/12863
if ((hostInstance: any).canonical) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll be working on a followup to fix this. The types are already wrong due to reconciler findHostInstance typing.

@@ -151,6 +151,7 @@ function coerceRef(
if (
current !== null &&
current.ref !== null &&
typeof current.ref === 'function' &&
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only attempt to read _stringRef from function refs. Otherwise we already know it won't match up.

if (typeof newChildrenIterable.entries === 'function') {
const possibleMap = (newChildrenIterable: any);
if (possibleMap.entries === iteratorFn) {
const maybeMap = (newChildrenIterable: any);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just move it up. No change in logic.

@@ -137,7 +137,7 @@ function pushTopLevelContextObject(
didChange: boolean,
): void {
invariant(
contextStackCursor.cursor == null,
contextStackCursor.current == null,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This looks like it caught a bug! The invariant could never fire because of the typo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually it fires in tests. 😮

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pushed a fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

Haha, nice 😅

@@ -60,24 +60,34 @@ let scheduleWork: (
callback: FrameCallbackType,
options?: {timeout: number},
) => number;
let cancelScheduledWork: (callbackID: number) => void;
let cancelScheduledWork: (callbackId: number) => void;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Consistent naming throughout the file.

let callbackIdCounter = 0;
// Timeouts are objects in Node.
// For consistency, we'll use numbers in the public API anyway.
const timeoutIds: {[number]: TimeoutID} = {};
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not super efficient (number keys are slow) but it can only fire in Node so it probably doesn't matter.
This is a naïve shim anyway.

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

😍

let callbackIdCounter = 0;
// Timeouts are objects in Node.
// For consistency, we'll use numbers in the public API anyway.
const timeoutIds: {[number]: TimeoutID} = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

The advantage of this isn't obvious to me.

Copy link
Collaborator Author

@gaearon gaearon May 21, 2018

Choose a reason for hiding this comment

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

In Node setTimeout gives you an object, not a number.
This is a primarily Node code path.

Since our intentional API is to return a number I think it would be confusing if we started returning objects in Node environment. The fact that it uses setTimeout in Node should be an implementation detail.

@pull-bot
Copy link

pull-bot commented May 21, 2018

ReactDOM: size: 🔺+0.1%, gzip: 🔺+0.1%

Details of bundled changes.

Comparing: 089d2de...271c2b7

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.1% +0.1% 617.64 KB 618.11 KB 143.99 KB 144.12 KB UMD_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 93.68 KB 93.8 KB 30.32 KB 30.34 KB UMD_PROD
react-dom.development.js +0.1% +0.1% 602.01 KB 602.48 KB 139.99 KB 140.13 KB NODE_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 92.17 KB 92.3 KB 29.3 KB 29.34 KB NODE_PROD
ReactDOM-dev.js +0.1% +0.1% 623.77 KB 624.23 KB 142.63 KB 142.77 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.1% 🔺+0.1% 273.23 KB 273.56 KB 51.48 KB 51.54 KB FB_WWW_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.1% +0.1% 400.77 KB 401.04 KB 89.75 KB 89.81 KB UMD_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.1% 80.64 KB 80.72 KB 24.87 KB 24.89 KB UMD_PROD
react-art.development.js +0.1% +0.1% 326.62 KB 326.9 KB 70.83 KB 70.91 KB NODE_DEV
react-art.production.min.js 🔺+0.2% 🔺+0.3% 45 KB 45.09 KB 13.99 KB 14.03 KB NODE_PROD
ReactART-dev.js +0.1% +0.1% 331.62 KB 331.88 KB 70.12 KB 70.2 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.2% 🔺+0.2% 146.11 KB 146.41 KB 25.25 KB 25.29 KB FB_WWW_PROD

react-scheduler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-scheduler.development.js +2.6% +1.9% 13.37 KB 13.71 KB 4.48 KB 4.57 KB UMD_DEV
react-scheduler.production.min.js 🔺+2.8% 🔺+2.6% 2.02 KB 2.08 KB 1.01 KB 1.04 KB UMD_PROD
react-scheduler.development.js +2.6% +2.0% 13.18 KB 13.52 KB 4.43 KB 4.52 KB NODE_DEV
react-scheduler.production.min.js 🔺+2.7% 🔺+2.6% 2.11 KB 2.16 KB 1.04 KB 1.06 KB NODE_PROD

Generated by 🚫 dangerJS

@gaearon gaearon merged commit dd5fad2 into facebook:master May 21, 2018
@gaearon gaearon deleted the bump-flow branch May 21, 2018 16:54
NMinhNguyen referenced this pull request in enzymejs/react-shallow-renderer Jan 29, 2020
* Update Flow to 0.70

* Remove unnecessary condition

* Fix wrong assertion

* Strict check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants