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

Unhandled JS Exception when one of the item in object is a React-Native element #76

Closed
alexmngn opened this issue Sep 19, 2017 · 8 comments

Comments

@alexmngn
Copy link

alexmngn commented Sep 19, 2017

I have 2 objects I'd like to deep merge. One element in the object is a React-Native element.

First object:

const obj1 = {
  headerStyle: {
    color: 'blue',
  },
  headerLeft: (
    <Text>Back</Text>
  )
};

const obj2 = {
  headerStyle: {
    backgroundColor: 'red',
  },
  headerLeft: (
    <Text>Close</Text>
  )
}

merge(obj1, obj2);

I get the following error when I try to merge those 2 objects:

Unhandled JS Exception: Maximum call stack size exceeded

screen shot 2017-09-19 at 16 12 09

@TehShrike
Copy link
Owner

I'm guessing that the React/React Native objects have cycles somewhere in their properties.

I assume that you are expecting the React Native objects to not be merged?

Can you find out if there's a canonical way to detect the React Native object type? If so, we can add it to is-mergeable-object, which would fix the issue in your case.

@alexmngn
Copy link
Author

@TehShrike I'm not expecting to merge the React Native objects but to get the last one indeed.
I cannot find a way to distinguish a React element of a React Native element

Both objects are quite similar:

ReactJS:
screen shot 2017-09-19 at 16 55 44

React Native:
screen_shot_2017-09-19_at_16_50_25

One has a defined _source_ but this doesn't seem to be accessible via code.

Although I would think the same rule should apply and we shouldn't merge ReactJS element either.

We can create a check for $$typeof === Symbol(react.element)

@TehShrike
Copy link
Owner

Check over TehShrike/is-mergeable-object#1

@TehShrike
Copy link
Owner

Any thoughts @alexmngn?

@macdja38
Copy link
Collaborator

It would be interesting to support merging circular references since in theory it would be possible.

@alexmngn
Copy link
Author

@TehShrike Looks good to me 👍

@alexmngn alexmngn reopened this Sep 21, 2017
TehShrike added a commit that referenced this issue Sep 21, 2017
Which prevents attempting to merge React elements, fixing #76
@TehShrike
Copy link
Owner

Published as 1.5.2.

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