Skip to content

Conversation

Ashoat
Copy link
Member

@Ashoat Ashoat commented Sep 20, 2017

The main reason there are errors on a stock RN app with react-navigation is that the .flowconfig had [ignore]s that caused the types to drift from stock packages. The first commit in this PR fixes .flowconfig, the second and third update package and type library versions, and the remaining commits fix the resultant Flow errors.

…ative libraries

Currently, there are numerous ignored libraries that are hiding type errors. Actually, they're causing type errors too. This sort of thing only patches over actual problems, so we have to revert them to get a config we can build upon.
We want to have Flow types working with the latest packages.
The current typing is clearly a typo, as it is circular. `NavigationScreenProp` should be used to type the navigation prop
What's funny is that I fixed this before in d71ed75. @skevy reintroduced the mistyped function in 9436d03, which didn't trigger any Flow errors because .flowconfig was ignoring the entire react-native package
The current code thinks it can import these, but this isn't true, and was being hidden because the .flowconfig ignored the whole react-native package. There's no easy to type Text and View at the current moment, as far as I can tell. Importing the highly generic `StyleObj` seems like the best bet, and is what I have being using in my projects.
Copy link

@mrm1ck mrm1ck left a comment

Choose a reason for hiding this comment

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

Well looks like you are doing a great job of iliminating some of the ignoring issues and ignoring creating issues-issues keep up the good. From what i can see this PR should benefit us reducing flow errors so with this review I will close this issue. But if i have missed something dont be afraid to reopen it. :)

Copy link

@mrm1ck mrm1ck left a comment

Choose a reason for hiding this comment

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

It's still failing some tests here let me look a bit harder at what the issue is

Copy link

@mrm1ck mrm1ck left a comment

Choose a reason for hiding this comment

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

Added temp test reports from cli and all should be good close this issue for 2680 to add reports

Copy link

@mrm1ck mrm1ck left a comment

Choose a reason for hiding this comment

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

Sorry #2620 is the adding of cli temp test reports to fix this PR

@Ashoat
Copy link
Member Author

Ashoat commented Sep 20, 2017

Hey @mrm1ck, I'm not really sure what you're talking about, and your PR doesn't really explain it. What test failures are you addressing? Is the new folder you're creating (cli/temp/test) some sort of magic folder for some test suite? What test suite exactly?

Sorry if I'm missing something obvious; I'm not too failure with how React Navigation tests. As far as I can tell, however, the CircleCI failures are all the result of Prettier Lint complaints that don't have anything to do with this PR (ie. Lint is failing on the entire project right now due to Prettier).

@skovhus - Good find. Right now there is a flow/react-navigation.js file that types src/react-navigation.js, but it's not included when react-navigation package is installed in another package, and on top of that it just types everything as any.

I went ahead and removed that file (as well as flow-typed/react-native.js) and things seem fine. However, adding @flow to src/react-navigation.js revealed another type error: createNavigator takes 4 parameters, but in the website code only one is passed to it. It's worth noting that the docs only talk about one parameter too. I'll try to investigate a bit more to figure out what's going on there.

@Ashoat
Copy link
Member Author

Ashoat commented Sep 20, 2017

@grabbou, in 93976d3 ("Introducing flat options") you updated createNavigator to take four params instead of one. However, you didn't update the docs or the nine createNavigator calls in the website code.

The type errors with the website code didn't get uncovered until now, since the Flow configuration on this project has been broken for quite a while. I am trying to fix it.

Can you provide some guidance on what we should do here? Are the new parameters optional? If not, how should we update the website code? Should the docs still mention createNavigator at all?

For now, I'll proceed under the assumption that the new parameters were supposed to be typed as optional, as this would keep the functionality in the docs/website still working, and everything typechecks with them as optional.

@@ -1,5 +1,5 @@
/*
* @noflow - get/set properties not yet supported by flow. also `...require(x)` is broken #6560135

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

@Ashoat
Copy link
Member Author

Ashoat commented Sep 20, 2017

Okay, so I went ahead and integrated this version of the library into my personal app. I got a whole bunch of new Flow errors, which was a good indication that things were working! I worked through all them, and I identified one typing issue and one unfortunate shortcoming of Flow.

Typing Issue

The issue has to do with the TabNavigator/StackNavigator/etc. component factories. The component they spit out should be possible to use with just a navigation prop, according to the docs. However, the NavigationNavigatorProps type includes two other required props. createNavigationContainer.js is where the component factory logic is defined.

Things seem to work okay if I just set these two other props (screenProps and navigationOptions) to optional in NavigationNavigatorProps. This is what I did to "fix" the issue I addressed to @grabbou above as well. Not sure if that's what we should be doing.

If things typecheck, I guess we're good. But for all of these cases, it'd be great if somebody could elucidate why these props were originally listed as required.

@grabbou - three questions currently for you, about type errors that have been exposed after fixing up Flow configuration:

  1. The question asked above.
  2. You added screenProps to NavigationNavigatorProps in the same commit that introduced the createNavigator type issue above: 93976d3 ("Introducing flat options"). Is it really a required prop for all components created from TabNavigator/StackNavigator/etc.?
  3. Same question for navigationOptions, which you added in a252b46 ("Breaking: Replace containerOptions with just props").

Flow Shortcoming

Unfortunately, it seems impossible to properly type your exact NavigationState in your application. I'm using Redux, and there are some cases where I reach into particular parts of the NavigationState to get something that I know is there. This relies on a particular configuration of the NavigationRoute tree. However, each NavigationStateRoute's children are typed as Array<NavigationRoute>, and it doesn't seem to be possible to refine the type of an Array to a Tuple, nor does it seem possible to declare a particular type for a specific member of an array using object notation.

@Ashoat
Copy link
Member Author

Ashoat commented Sep 20, 2017

I can confirm that the latest version of this PR typechecks both in the root directory, the NavigationPlayground example, and in my personal app. The only possibly sketchy parts are the three questions addressed to @grabbou above.

It's worth noting that if ReduxExample was Flow-typed, we would've noticed the "Typing Issue" in my last comment earlier. As it stands, I only noticed it when integrating with my personal app, which means there's no real way to detect when NavigationNavigatorProps is mistyped within React Navigation.

@matthamil
Copy link
Member

I'll review this and get it merged over the weekend 😄

duration?: number,
// An easing function from `Easing`.
easing?: (t?: number) => number,
easing?: (t: number) => number,

This comment was marked as abuse.

matthamil
matthamil previously approved these changes Sep 25, 2017
Copy link
Member

@matthamil matthamil left a comment

Choose a reason for hiding this comment

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

This is fantastic work, and thank you for going through and fixing these Flow errors.

@matthamil
Copy link
Member

matthamil commented Sep 25, 2017

@Ashoat Can you run yarn run format on this PR so CircleCI doesn't fail with lint/prettier checks? I'll get it merged once you do.

@Ashoat
Copy link
Member Author

Ashoat commented Sep 25, 2017

Went ahead and ran yarn run format and committed the results. The first parallel test (npm run lint && npm run flow-check && npm run jest) ran fine, but the second parallel test (node node_modules/jest/bin/jest.js) is failing due to some React Native issue it seems?

$ node node_modules/jest/bin/jest.js
 FAIL  ./App.test.js
  ● Test suite failed to run

    TypeError: Cannot read property 'BLOB_URI_SCHEME' of undefined
      
      at Object.<anonymous> (node_modules/react-native/Libraries/Blob/URL.js:21:21)
      at node_modules/react-native/Libraries/Core/InitializeCore.js:174:40
      at getValue (node_modules/react-native/Libraries/Utilities/defineLazyObjectProperty.js:44:10)
      at ContextifyScript.Script.runInContext (vm.js:53:29)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        5.059s
Ran all test suites.
error Command failed with exit code 1.
Exited with code 1

@GertjanReynaert
Copy link

GertjanReynaert commented Sep 25, 2017

@Ashoat you might want to take a look at this issue facebook/react-native#15810 for the BLOB_URI_SCHEME error

Edit: This comment facebook/react-native#15810 (comment) fixed the issue in our app. Not sure if you want to include it in this package, but it might be a temporary workaround.

@codecov
Copy link

codecov bot commented Sep 25, 2017

Codecov Report

Merging #2619 into master will decrease coverage by 0.02%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2619      +/-   ##
==========================================
- Coverage   36.76%   36.73%   -0.03%     
==========================================
  Files          48       48              
  Lines        1281     1282       +1     
  Branches      318      319       +1     
==========================================
  Hits          471      471              
  Misses        629      629              
- Partials      181      182       +1
Impacted Files Coverage Δ
src/views/Header/HeaderBackButton.js 0% <ø> (ø) ⬆️
src/views/TouchableItem.js 0% <ø> (ø) ⬆️
src/routers/StackRouter.js 98.62% <ø> (ø) ⬆️
src/views/Header/Header.js 0% <ø> (ø) ⬆️
src/navigators/createNavigator.js 0% <ø> (ø) ⬆️
src/views/Drawer/DrawerNavigatorItems.js 0% <ø> (ø) ⬆️
src/react-navigation.js 0% <ø> (ø) ⬆️
src/navigators/StackNavigator.js 0% <0%> (ø) ⬆️
src/views/Drawer/DrawerView.js 0% <0%> (ø) ⬆️
src/navigators/DrawerNavigator.js 0% <0%> (ø) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 17c910f...b3570bf. Read the comment docs.

….flowconfig

Realized this line I removed in the first commit is necessary when using npm link/yarn link, which is what the CircleCI build does
Some of these params are marked as optional because they have defaults. However, the only place `DrawerViewConfig` is used is as the input the function that then applies the defaults
`NavigationNavigatorProps` is used to type the props of the component that is output by the `StackNavigator`, `TabNavigator`, etc. component factories. This component does not need to have any props specified.
`DrawerNavigator`, just like `TabNavigator` and `StackNavigator`, can be called with just a single argument (ie. omitting the config)
@Ashoat
Copy link
Member Author

Ashoat commented Sep 25, 2017

The BLOB_URI_SCHEME issue discussed above happens in NavigationPlayground, and is fixed in RN 0.48.4, so I upgraded to that (b3570bf).

In the process of debugging that I discovered that the test config uses yarn link with NavigationPlayground. When I tried this on my local copy, more Flow errors popped up. One of them was because the absolute paths Flow compares are different when using yarn link, and so one the lines I removed in the first commit of this PR had to be re-added to NavigationPlayground's .flowconfig (6bba368). Besides that, there were three legitimate type errors that I corrected with e9a48b1, e790d45, and 0f58da1.

Looks like the tests fully pass now!

@kelset
Copy link

kelset commented Sep 25, 2017

Thanks for taking such a good care of this PR! Now that tests are passing I think @matthamil will easily give his 💯 - it looks good to me ;D

Copy link
Member

@matthamil matthamil left a comment

Choose a reason for hiding this comment

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

🚢 it!

@matthamil matthamil merged commit b759d31 into react-navigation:master Sep 25, 2017
@Ashoat Ashoat deleted the fixflow branch September 25, 2017 19:32
@GertjanReynaert
Copy link

@Ashoat Sorry for the late response, but I'm glad you got it fixed.

Really great work, and I'm really excited to see the community effort in this project ignited again!

sourcecode911 pushed a commit to sourcecode911/react-navigation that referenced this pull request Mar 9, 2020
* Fix .flowconfig to stop ignoring modules and properly include React Native libraries

Currently, there are numerous ignored libraries that are hiding type errors. Actually, they're causing type errors too. This sort of thing only patches over actual problems, so we have to revert them to get a config we can build upon.

* Update react-native/flow-bin dependencies

We want to have Flow types working with the latest packages.

* Update flow-typed libraries (auto-generated)

* Fix typing of navigation prop used by withNavigation HOC

The current typing is clearly a typo, as it is circular. `NavigationScreenProp` should be used to type the navigation prop

* Fix typing of easing function

What's funny is that I fixed this before in d71ed75. @skevy reintroduced the mistyped function in 9436d03, which didn't trigger any Flow errors because .flowconfig was ignoring the entire react-native package

* Correct typing of View and Text style prop

The current code thinks it can import these, but this isn't true, and was being hidden because the .flowconfig ignored the whole react-native package. There's no easy to type Text and View at the current moment, as far as I can tell. Importing the highly generic `StyleObj` seems like the best bet, and is what I have being using in my projects.

* Import NavigationScreenComponent using full path

* Updating yarn.lock files

* Get rid of library overrides in flow-typed/react-native.js and flow/react-navigation.js

* Add @flow to src/react-navigation.js and make last three params to createNavigator optional

* Make screenProps and navigationOptions optional in NavigationNavigatorProps

* yarn run format

* Readd react-navigation/node_modules ignore to NavigationPlayground's .flowconfig

Realized this line I removed in the first commit is necessary when using npm link/yarn link, which is what the CircleCI build does

* Make all DrawerViewConfig's params optional

Some of these params are marked as optional because they have defaults. However, the only place `DrawerViewConfig` is used is as the input the function that then applies the defaults

* Make all props in NavigationNavigatorProps optional

`NavigationNavigatorProps` is used to type the props of the component that is output by the `StackNavigator`, `TabNavigator`, etc. component factories. This component does not need to have any props specified.

* Make second param to `DrawerNavigator` factory optional

`DrawerNavigator`, just like `TabNavigator` and `StackNavigator`, can be called with just a single argument (ie. omitting the config)

* Upgrade to RN 0.48.4 to address facebook/react-native#15810
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants