kickstartcrew / redux-offline-queue

Simple offline queue for redux. Queue actions while offline to dispatch the requests upon connectivity.
Other
136 stars 17 forks source link

action.payload.offline is undefined in the first REHYDRATE. #19

Closed gabrielroriz closed 5 years ago

gabrielroriz commented 5 years ago

In reducer.js,

It's needed to verify if action.payload is undefined instead of use this variable directly. I found this problem when I reinstall the app, I got an error because the application was trying to read action.payload.offlinewhile action.payload was an undefined variable.

Suggestion:

screenshot from 2018-12-09 17-50-22

From:

 case REHYDRATE: { // Handle rehydrating with custom shallow merge.
      const incoming = action.payload.offline
      if (incoming) return { ...state, ...incoming }
      return state
    }

To:

case REHYDRATE:// Handle rehydrating with custom shallow merge.
      {
        if (action.payload != undefined) {
          var incoming = action.payload.offline;
          if (incoming) return _extends({}, state, incoming);
        }
        return state;
      }
RobPando commented 5 years ago

@gabrielroriz nice find man!. Thanks for reporting this, someone actually made a PR to fix this a couple of weeks back but it was a bit weird and they ended up closing it.

gabrielroriz commented 5 years ago

@RobPando

Nice, Rob! It's good to contribute with this project that's helping me a lot in my project.

Can I make a PR to solve it ir or it's a thing that you need to do? :smile:

I'm here if you need me.

(I'm asking because I don't have any experience with contribution in open source projects but I would like to contribute)

RobPando commented 5 years ago

@gabrielroriz sure!, best time to get do your first contribution. Go ahead and make a PR with the changed. I do have a suggestion however, for the conditional check you can either use lodash which is a dependency, you can use if (_.get(action, 'payload.offline')) or just do if (action.payload && action.payload.offline)

gabrielroriz commented 5 years ago

@RobPando

https://github.com/InspireNL/redux-offline-queue/pull/20

Done! :heavy_check_mark:

RobPando commented 5 years ago

Closed by #20