cozy / cozy-client

Document store and React components for the Cozy platform
MIT License
13 stars 13 forks source link

Error after deleting todo with function query #329

Open dscottboggs opened 5 years ago

dscottboggs commented 5 years ago

To learn the cozy platform I'm trying to expand on the example to create a todo-lists app that supports more than one to-do list. I have the list ID passed to the Todos component as a route parameter, then I have the following query:

const entriesForList = listID => client =>
  client.find(ENTRIES_DOCTYPE).where({ 'list.id': listID })
queryConnect({
  todos: ({ match }) => {
    return {
      query: entriesForList(match.params.listID),
      as: 'todos'
    }
  }
})(Todos)

My Schema is as so:

{
  entries: {
    doctype: ENTRIES_DOCTYPE,
    attributes: {},
    relationships: {
      list: {
        type: 'belongs-to-in-place',
        doctype: LISTS_DOCTYPE
      }
    }
  },
  lists: {
    doctype: LISTS_DOCTYPE,
    attributes: {},
    relationships: {
      entries: {
        type: 'has-many',
        doctype: ENTRIES_DOCTYPE
      }
    }
  }
}

When I deleteDocument(todo) in TodoRemoveButton, the following exception is thrown


Unhandled promise rejection Error: "getDocumentFromSlice: Cannot retrieve document with undefined id"
    getDocumentFromSlice http://localhost:8888/vendors.266519827524fb8a4278.js:16206:11
    getDocumentFromState http://localhost:8888/vendors.266519827524fb8a4278.js:21640:11
    getDocumentFromState http://localhost:8888/vendors.266519827524fb8a4278.js:2275:15
    get http://localhost:8888/vendors.266519827524fb8a4278.js:22297:32
    findValues http://localhost:8888/vendors.266519827524fb8a4278.js:22703:16
    findValues http://localhost:8888/vendors.266519827524fb8a4278.js:22703:5
    nestedValidator http://localhost:8888/vendors.266519827524fb8a4278.js:22660:3
    validate http://localhost:8888/vendors.266519827524fb8a4278.js:22331:10
    filter http://localhost:8888/vendors.266519827524fb8a4278.js:22782:12
    getQueryDocumentsChecker http://localhost:8888/vendors.266519827524fb8a4278.js:79031:30
    matchedIds http://localhost:8888/vendors.266519827524fb8a4278.js:79046:12
    updateData http://localhost:8888/vendors.266519827524fb8a4278.js:79045:20
    autoQueryUpdater http://localhost:8888/vendors.266519827524fb8a4278.js:79082:12
    mapValues http://localhost:8888/vendors.266519827524fb8a4278.js:77989:34
    createBaseFor http://localhost:8888/vendors.266519827524fb8a4278.js:76226:11
    baseForOwn http://localhost:8888/vendors.266519827524fb8a4278.js:20193:20
    mapValues http://localhost:8888/vendors.266519827524fb8a4278.js:77988:3
    queries http://localhost:8888/vendors.266519827524fb8a4278.js:79133:13
    combinedReducer http://localhost:8888/vendors.266519827524fb8a4278.js:21627:15
    combination http://localhost:8888/vendors.266519827524fb8a4278.js:65544:29
    dispatch http://localhost:8888/vendors.266519827524fb8a4278.js:56432:22
    dispatch http://localhost:8888/vendors.266519827524fb8a4278.js:2449:14
    _callee6$ http://localhost:8888/vendors.266519827524fb8a4278.js:1966:17
    tryCatch http://localhost:8888/vendors.266519827524fb8a4278.js:69261:37
    invoke http://localhost:8888/vendors.266519827524fb8a4278.js:69495:22
    method http://localhost:8888/vendors.266519827524fb8a4278.js:69313:16
    step http://localhost:8888/vendors.266519827524fb8a4278.js:14212:30
    step http://localhost:8888/vendors.266519827524fb8a4278.js:14223:13
    run http://localhost:8888/vendors.266519827524fb8a4278.js:20434:22
    notify http://localhost:8888/vendors.266519827524fb8a4278.js:20451:30
    flush http://localhost:8888/vendors.266519827524fb8a4278.js:80106:9

es6.promise.js:110
onUnhandled/</result<
es6.promise.js:110
nICZ/module.exports
_perform.js:3:12
onUnhandled/<
es6.promise.js:104
MfQN/module.exports
_invoke.js:5
<anonymous>
_task.js:35
run
_task.js:21
listener
_task.js:25
​```

... And the entry is not deleted from the page view. However, if I refresh the page, it's gone, so the request to remove it from the database was successful, the page just didn't reload.
ptbrowne commented 5 years ago

Thanks for the detailed explanation. Do you have a reproducing repository ? It seems a bug on our end :/

dscottboggs commented 5 years ago

sure, here you go https://github.com/dscottboggs/first-cozy-app