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

Does unflatten enter into infinite recursion on function or array members? #94

Open
cmeeren opened this issue Jan 25, 2020 · 3 comments

Comments

@cmeeren
Copy link

cmeeren commented Jan 25, 2020

I'm using this library in an F# project (transpiles to JS through using Fable). So unfortunately I have no JS repro (I'm not a JS dev).

unflatten is mostly working fine, but it seems to enter into infinite recursion on some objects. This happens even when there is seemingly nothing to unflatten.

I have an array of key-value pairs (React props) that I'm converting into an object, and then I'm using unflatten on this object.

This works fine for some prop arrays, such as this:

image

However, for others, such as this, it enters into an infinite recursion:

image

image

As you can see, in both cases, the original prop list (and thus the object) does not contain keys with the delimiter, and there are no sub-objects to recurse into (unless it does something with the function), so AFAIK unflatten shouldn't modify anything.

I have tried safe without any effect.

The weird thing is, the stack trace seems to come from the flatten function, which I do not call:

image

@cmeeren
Copy link
Author

cmeeren commented Jan 26, 2020

I think perhaps the problem might be the recursion into the children prop. I'll investigate some more.

@cmeeren
Copy link
Author

cmeeren commented Jan 26, 2020

I think I have a solution. For my use-case, I simply need unflatten to not recurse on this line:

flat/index.js

Lines 144 to 145 in 6e95c43

// unflatten again for 'messy objects'
recipient[key1] = unflatten(target[key], opts)

Edit: As well as only ever enter the first case here (i.e., not call addKeys):

flat/index.js

Lines 100 to 109 in 6e95c43

if (!isObject || isEmpty(target[key])) {
result[key] = target[key]
return result
} else {
return addKeys(
key,
result,
flatten(target[key], opts)
)
}

Would it be possible to add an option that controls this?

cmeeren added a commit to Shmew/Feliz.MaterialUI that referenced this issue Jan 26, 2020
@cmeeren
Copy link
Author

cmeeren commented Feb 5, 2020

I decided to implement my own unflatten instead. Feel free to close if you want.

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

1 participant