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

Prevent max call stack when merging overlapping keys #483

Merged
merged 4 commits into from May 8, 2019

Conversation

timhudson
Copy link
Contributor

@timhudson timhudson commented May 8, 2019

The merge function added in #473 expects all keys to be unique across merged objects, otherwise it will trigger a max call stack error as it attempts to merge strings.

The merge implementation was intentionally minimal in scope, and an argument could be made for continuing to expect unique keys, but I ran into this issue with a fairly basic use-case – composing variant to allow overrides.

To help evaluate this PR, I added an additional test which covers this use-case. It is a bit specific so I'm not sure it should land in master as is.

@codecov-io
Copy link

codecov-io commented May 8, 2019

Codecov Report

Merging #483 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #483   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           1      1           
  Lines         173    173           
=====================================
  Hits          173    173
Impacted Files Coverage Δ
src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e6b5032...cc67fbb. Read the comment docs.

src/index.js Outdated
@@ -44,8 +44,10 @@ export const merge = (a, b) => {
for (const key in b) {
if (!a[key]) {
result[key] = b[key]
} else {
} else if (typeof a[key] === 'object') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition could go in the if statement above, couldn’t it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Addressed in cc67fbb.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no! Looks like this computer's time is borked – sorry about that...

@jxnblk jxnblk merged commit 01d4669 into styled-system:master May 8, 2019
@timhudson timhudson deleted the merge-max-call-stack branch May 8, 2019 14:55
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

Successfully merging this pull request may close these issues.

None yet

3 participants