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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object.assign polyfill does not match spec (causing error on browsers without Object.assign) #477

Closed
Venryx opened this issue Dec 9, 2019 · 7 comments

Comments

@Venryx
Copy link

Venryx commented Dec 9, 2019

馃悰 Bug Report

The Object.assign polyfill does not satisfy the Object.assign spec; it errors if it's passed "null" as the second (or later) argument.

To Reproduce

The code below works with Object.assign, but fails for the polyfill:

Object.assign({}, null); // works
assign({}, null); // errors

The assign function is declared here:

immer/src/common.js

Lines 64 to 71 in d3be40e

export const assign =
Object.assign ||
((target, ...overrides) => {
overrides.forEach(override =>
Object.keys(override).forEach(key => (target[key] = override[key]))
)
return target
})

So to reproduce in console, just copy that assign function (removing the Object.assign || part of course), then run the code in the first code block.

Expected behavior

The function should not error. Instead, it should return null, like Object.assign does.

Link to repro (highly encouraged)

Not needed, since can repro directly in console.

Why does it matter

It matters because the immer module itself calls assign with the third argument as null:
Step1) https://github.com/immerjs/immer/blob/master/src/index.js#L3
Step2) https://github.com/immerjs/immer/blob/master/src/immer.js#L40

Thus, by default, just importing the immer module crashes browsers that do not have Object.assign defined!

(I discovered this issue when I grabbed the Object.assign polyfill from immer for some other purpose, but then noticed that it errorred with null arguments provided)

Environment

  • Immer version: 5.0.0 (latest)
@mweststrate
Copy link
Collaborator

Thanks for the detailed bug report! This really helps. A new version (5.0.1) should be published by CI soon.

@aleclarson
Copy link
Member

馃帀 This issue has been resolved in version 5.0.1 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

@FKobus
Copy link

FKobus commented Dec 11, 2019

For me this fix isn't working. It's giving me the following error on a HTC One M9:

"undefined" isn't a function

Falling back to 4.0.2 (works with older specs browsers)

[edit] verified 4.0.2 works

@mweststrate
Copy link
Collaborator

@FKobus that error message is very generic, and I can't tell from your message whether or not it relates to this issue. Please open a new issue including reproduction details, stack traces, example code etc etc.

@Venryx could you confirm that the issue is solved for you?

@Venryx
Copy link
Author

Venryx commented Dec 15, 2019

@mweststrate As mentioned in my OP, I didn't actually hit this error in production -- I just discovered the issue while copying the assign polyfill for some temporary usage elsewhere, and realized it meant the library would break on older browsers.

That said, the console-based test/usage I described earlier now passes. (but you probably already knew that)

Anyway, thanks for the quick fix! Open-source development on GitHub is so much more streamlined than the painstaking bug-report processes for enterprise/legacy software. (like Windows issues that I've seen in multiple versions, left unfixed for over half a decade)

@majesticuser
Copy link

Our team also switched back to the 4.0.2 version of immer as the versions 5.0.0 and 5.0.1 of immer throw an "Object.assign undefined" error in the IE11 browser.

@mweststrate
Copy link
Collaborator

@majesticuser @FKobus please note that this issue is resolved and closed. Same symptoms !== same issue. So if you want your issue to be looked into, please take the courtesy to file a new issue, and take this issue as example on how to provide actionable information rather than throwing symptoms over the wall :) This project is maintained for you for free, so please make things at least as easy for us as you can!

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

No branches or pull requests

5 participants