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

mergeIn throws Cannot read property 'merge' of null when mergeIn on keyPath that has a null value #1807

Open
Vetrano89 opened this issue Feb 2, 2021 · 3 comments

Comments

@Vetrano89
Copy link

Vetrano89 commented Feb 2, 2021

What happened

mergeIn throws Cannot read property 'merge' of null when mergeIn on keyPath that has a null value

Screen Shot 2021-02-02 at 12 29 57 PM

An error is also thrown when a field is undefined, which makes more sense. To me, null is a placeholder and says "yes there will eventually be a value here" and that value can be anything. So why can't we merge into it?

It looks like mergeIn works on other values that aren't objects such as Bool/Nums etc. so it doesn't seem like this is intentional.

How to reproduce

https://codepen.io/vetrano89/pen/xxRGaJE

@jdeniau
Copy link
Member

jdeniau commented Jul 9, 2021

The error message is better in the latest 4.0.0-rc:

TypeError: Cannot merge into non-data-structure value: null

The mergeIn will try to merge at the path you specify, so you will try to merge null and Map({foo: 'bar'}), which is not possible because null can not be merged.

This is arguable thought, because it will work with an undefined value :

map1.mergeIn(['foo'], map2);
// will output
{
  foo: {foo: "bar"}
  nullField: null
}

@jdeniau jdeniau added this to the 4.0 milestone Jul 19, 2021
@jdeniau
Copy link
Member

jdeniau commented Jul 19, 2021

Probably related to the discussion in #1840 for resolution

@Methuselah96
Copy link
Contributor

Took a brief look at this and I think it will require its own PR/fix separate from #1840.

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

3 participants