Redux-persist: Flow errors

Created on 21 Dec 2018  ยท  6Comments  ยท  Source: rt2zz/redux-persist

Reopening this again, the last issues on flow issues is from March 2018, there's a lot of Flow errors.

Also when integrating with React and using , this specific error is thrown:

Error โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ src/integration/react.js:17:8

Cannot extend PureComponent [1] with PersistGate because:
 โ€ข in the return value of property render:
    โ€ข Either undefined [2] is incompatible with null [3].
    โ€ข Or property @@iterator is missing in undefined [2] but exists in $Iterable [4].
 โ€ข in the return value of property render:
    โ€ข Either undefined [5] is incompatible with null [3].
    โ€ข Or property @@iterator is missing in undefined [5] but exists in $Iterable [4].

     src/integration/react.js
 [2]  8โ”‚   children?: Node | Function,
 [5]  9โ”‚   loading?: Node,
       :
     14โ”‚   bootstrapped: boolean,
     15โ”‚ }
     16โ”‚
 [1] 17โ”‚ export class PersistGate extends PureComponent<Props, State> {
     18โ”‚   static defaultProps = {
     19โ”‚     loading: null,
     20โ”‚   }
     21โ”‚
     22โ”‚   state = {
     23โ”‚     bootstrapped: false,
     24โ”‚   }
     25โ”‚   _unsubscribe: ?Function
     26โ”‚
     27โ”‚   componentDidMount() {
     28โ”‚     this._unsubscribe = this.props.persistor.subscribe(
     29โ”‚       this.handlePersistorState
     30โ”‚     )
     31โ”‚     this.handlePersistorState()
       :
     52โ”‚
     53โ”‚   render() {
     54โ”‚     if (process.env.NODE_ENV !== 'production') {
     55โ”‚       if (typeof this.props.children === 'function' && this.props.loading)
     56โ”‚         console.error(
     57โ”‚           'redux-persist: PersistGate expects either a function child or loading prop, but not both. The loading prop will be ignored.'
     58โ”‚         )
     59โ”‚     }
     60โ”‚     if (typeof this.props.children === 'function') {
     61โ”‚       return this.props.children(this.state.bootstrapped)
     62โ”‚     }
     63โ”‚
     64โ”‚     return this.state.bootstrapped ? this.props.children : this.props.loading
     65โ”‚   }
     66โ”‚ }
     67โ”‚

     /tmp/flow/flowlib_fdae0d/react.js
 [3] 14โ”‚   | null
       :
 [4] 20โ”‚   | Iterable<?React$Node>;

It's solved by adding default values for children and loading, and making them required.

Any advice on what should I do with my React app to avoid that Flow issue?

bug report flow p1

Most helpful comment

Hi @rt2zz , could we please release another version to fix the flowtype? thanks

All 6 comments

Potentially related Flow issues:

A recent PR that fixed some Flow issues:

An important comment from the author about Flow usage (@rt2zz):

@baransu You recently submitted Flow improvements (thank you ๐Ÿ™), would you mind helping the project by looking at some of these issues and sizing up the root cause?

@kareemsalah227 Would you mind spending a little time to create a small test project that replicates these issues so we can look into them better? Also, you mention:

Also when integrating with React and using
Did you mean...
Also when integrating with React and using Flow

I haven't experienced these Flow issues myself but we should definitely get them resolved. Any help in doing so or contributing a fix to the project would be appreciated.

@aguynamedben Sure thing sir, I'll prepare it and share with you the links shortly, so sorry for the long time not replying you.

@aguynamedben I'm back, sorry for the delay again, here's a link to a mini-project and a small brief to reproduce the issue, it's not that complicated.
https://github.com/kareemsalah227/redux-persist-issue

The code inside might look a bit weird, it's because I'm working on a highly configurable, mono-repo project, I borrowed some stuff from there to make things faster.

Please let me know if you need anything else, I'm happy to help.

I created a pull request to fix this issue with the changes proposed by @kareemsalah227.
I added some more information about where the problem comes from.

@erksch's PR has been merged to master. We'll need @rt2zz to release a new version for the fix to be in npm (I don't have the power to do so).

Hi @rt2zz , could we please release another version to fix the flowtype? thanks

Was this page helpful?
0 / 5 - 0 ratings