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

[BUG] [Immer 5.0.x] Uncaught TypeError: undefined is not a function (Object.assign) #482

Closed
2 tasks done
FKobus opened this issue Dec 17, 2019 · 9 comments
Closed
2 tasks done
Labels

Comments

@FKobus
Copy link

FKobus commented Dec 17, 2019

🐛 Bug Report

On older browsers (mobile) the immer polyfill for Object.assign doesn't get polyfilled correctly.
The error thrown is super generic. But with debugging boils down to this code:

function makeTrapsForGetters(getters) {
  return Object.assign({}, reflectTraps, {
    get: function get(state, prop, receiver) {
      return getters.hasOwnProperty(prop) ? getters[prop](state, prop, receiver) : Reflect.get(state, prop, receiver);
    },
    setPrototypeOf: function setPrototypeOf(state) {
      throw new Error("Object.setPrototypeOf() cannot be used on an Immer draft"); // prettier-ignore
    }
  });
}

Link to repro

Our repro is private.

To Reproduce

Just run immer on an old browser.

We used a HTC ONE M9
Chrome version: 40.0.2214.89

Observed behavior

Crashes completely the application

Expected behavior

Custom polyfill works.

Environment

  • Immer version:
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)

Workaround,

Use immer 4.0.2. There the polyfill functions as expected.

This issue is created because of this issue that was closed: #477 (comment)

@mweststrate
Copy link
Collaborator

mweststrate commented Dec 17, 2019 via email

@mweststrate
Copy link
Collaborator

@egoist ideas?

@egoist
Copy link
Contributor

egoist commented Dec 17, 2019

@mweststrate You're using object rest spreading here so it gets transpiled to Object.assign:

...reflectTraps,

I guess you should change this to use your assign utility:

export const assign =

@mweststrate
Copy link
Collaborator

@egoist yeah that is what I assumed, but I guess that means that the transpilation config is off, as that should prevent us against such mistakes? Probably the target ES version is too high? If transpilation doesn't guard us against this we will run into it every time a spread is introduced :) IIRC babel shout emit utility functions for this automatically?

@aleclarson
Copy link
Member

🎉 This issue has been resolved in version 5.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mweststrate
Copy link
Collaborator

Pushed a patch, will revisit when finalizing TS conversion. @FBKobus could you confirm version 5.0.02 fixes the issue?

@FKobus
Copy link
Author

FKobus commented Dec 18, 2019

@mweststrate I will test tomorrow on several old devices and report here the outcome.
Looking at the MR it seems to resolve to your internal polyfill, so i'm suspecting green flags

@FKobus
Copy link
Author

FKobus commented Dec 19, 2019

@mweststrate ; hereby I confirm that the bug has been resolved in version 5.0.2.

@mweststrate
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants