Skip to content

Types.reference and types.identifier crashing application upon deleting User Reference; Error: [mobx-state-tree] Failed to resolve reference #2134

Discussion options

You must be logged in to vote

Hey @ChristopherGabba - thanks for the very detailed question. Sorry it took a little while to get to you, I was busy this weekend haha.

You've got a lot of the patterns I would recommend, including the safeReference. I think the only thing you're missing is the onInvalidatedHook. That should clean up your stale data and allow you to use the safeReference approach that's working.

Might look like this for you:

export const MessageModel = types
  .model("Message")
  .props({
    id: types.identifier,
    sender: types.safeReference(UserModel).onInvalidate((sender) => {
      // Handle the case where sender is deleted
      // For example, set sender to a default user or handle it according …

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@coolsoftwaretyler
Comment options

@ChristopherGabba
Comment options

@coolsoftwaretyler
Comment options

@k-ode
Comment options

Answer selected by coolsoftwaretyler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants