ParseReact icon indicating copy to clipboard operation
ParseReact copied to clipboard

Observe: refresh with network error clears looses the data

Open 0x0ece opened this issue 10 years ago • 4 comments

Say I'm observing for MyObj, the data is populated and later refreshed. In case of error during the refresh, e.g. no network connection, the current data is lost.

Moreover, an Alert is thrown with "Received an error with invalid JSON from Parse: ..." (this should have changed in one of the latest commits -- in react-native appears on the user's screen).

Repro (with no network connection):

  observe: function() {
    return {
      myobjs: (new Parse.Query('MyObj'))
    };
  },
  componentDidMount: function() {
    // initial data
    var myobjs = [ /* some initial values here */ ];
    this._receiveData('myobjs', myobjs);
  },

I was able to work around by modifying Mixin.js as follows -- I can send a PR but would like to understand where you'd prefer to apply the patch (this doesn't look like a very good solution to me).

  _receiveData: function _receiveData(name, value) {
    if (typeof this.data[name] === 'undefined' || Object.prototype.toString.call(value) !== '[object Array]' || value.length > 0)
      this.data[name] = value;
    delete this._pendingQueries[name];
    delete this._queryErrors[name];
    this.forceUpdate();
  },

0x0ece avatar Jun 23 '15 03:06 0x0ece

Rather than handle it at the component level, I think we should handle it at the internal storage layer. As an initial fix, I'd say a failed subscription should not update its contents in any way. Down the road, we can query our local index of known objects to best-guess the result set. I'm exploring a number of offline support methods, so that developers can build better React Native apps.

andrewimm avatar Jun 30 '15 01:06 andrewimm

That's great news! Is there a place to follow discussion, or a changelog to monitor what's getting added?

0x0ece avatar Jun 30 '15 06:06 0x0ece

@andrewimm do you have any news? I've updated to 0.4.2 (and Parse to 1.5.0) but the issue seems still there.

0x0ece avatar Jul 18 '15 23:07 0x0ece

Sorry, I haven't had much time to devote to new Parse+React features lately. I'll open up a discussion task on the matter of disk caching, though.

andrewimm avatar Aug 04 '15 19:08 andrewimm