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

Cannot read property 'id' of null #52

Open
matthiasbruns opened this issue Mar 23, 2017 · 0 comments
Open

Cannot read property 'id' of null #52

matthiasbruns opened this issue Mar 23, 2017 · 0 comments

Comments

@matthiasbruns
Copy link

Files that I talk about:

  • src/reducers/list/delete/success.ts
  • dist/reducers/map/delete/success.js

I've found something really weird. I know how to fix it, but would like to know, if this behaviour desired.
My default state is this:

const emptyState = {
  _meta: {
    isFetching: true,
    isSubmitting: false
  },
  _error: null
};

As you can see, there is a field _error, which is null by default and will be reset to null during the reduction, if no error happens.

When I want to delete an item, this happens:

Stacktrace:

TypeError: Cannot read property 'id' of null
    at predicate (app.js:99228)
    at app.js:35899
    at XWrap.f (app.js:28303)
    at XWrap.module.exports.XWrap.@@transducer/step (app.js:36172)
    at _arrayReduce (app.js:15717)
    at _reduce (app.js:15750)
    at app.js:28302
    at app.js:14662
    at f2 (app.js:936)
    at reject (app.js:24663)

It took me a bit to find out that calling deleteSuccess causes this error.
The reason is, that predicate(existingRecord) receives a null value, because _error is null.
This causes this error: null['id']

function success(config, current, record) {
    invariants_1.default(invariantArgs, config, current, record);
    var key = config.key;
    var deleteId = record[key];
    function predicate(existingRecord) {
        return deleteId == existingRecord[key];
    }
    return r.reject(predicate, current);
}

I would suggest, that you add a null check to the deleteId check - something like this:

function predicate(existingRecord) {
    return existingRecord && deleteId == existingRecord[key];
}
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

No branches or pull requests

1 participant