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 perform get on revoked proxy error when no recursion #117

Closed
TrueWill opened this issue Mar 6, 2018 · 4 comments
Closed

Cannot perform get on revoked proxy error when no recursion #117

TrueWill opened this issue Mar 6, 2018 · 4 comments

Comments

@TrueWill
Copy link

TrueWill commented Mar 6, 2018

Similar to #100, I'm getting
TypeError: Cannot perform 'get' on a proxy that has been revoked
from a test after converting a reducer to immer.

I narrowed the code down from the original to a minimal example, which is why it looks odd.

export default (state, action) =>
  produce(state, draft => {
    switch (action.type) {
      case types.SET_STARTING_DOTS:
        return draft.availableStartingDots.map(a => a);
      default:
        break;
    }
  });

The above reducer will raise the error when given this state and the SET_STARTING_DOTS action:

{
    availableStartingDots: [
      { dots: 4, count: 1 },
      { dots: 3, count: 2 },
      { dots: 2, count: 3 },
      { dots: 1, count: 4 }
    ]
}

Changing the case to return state.availableStartingDots.map(a => a); removes the error.

@mweststrate
Copy link
Collaborator

@TrueWill I fixed the issue that the result set was not properly finalized. However, I am pretty sure that this reducer is not doing what you intend it to do; you return a sub part of the original state, effectively changing its shape.

Your reducer now transforms the state:

{
    availableStartingDots: [
      { dots: 4, count: 1 },
      { dots: 3, count: 2 },
      { dots: 2, count: 3 },
      { dots: 1, count: 4 }
    ]
}

into

  [
      { dots: 4, count: 1 },
      { dots: 3, count: 2 },
      { dots: 2, count: 3 },
      { dots: 1, count: 4 }
    ]

What you probably want is:

case types.SET_STARTING_DOTS:
        draft.availableStartingDots = draft.availableStartingDots.map(a => a);
        return

@mweststrate
Copy link
Collaborator

Released as 1.1.3. Thanks for reporting!

@TrueWill
Copy link
Author

TrueWill commented Mar 6, 2018

@mweststrate Yep - I changed the shape to keep the example as simple as possible. The original code preserves shape. Thank you! 😃

@TrueWill
Copy link
Author

TrueWill commented Mar 7, 2018

Just tested it - works fine! Great job!

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

2 participants