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

Projects
None yet
3 participants
@timhudson
Copy link
Contributor

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

This comment has been minimized.

Copy link

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.

@@ -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') {

This comment has been minimized.

Copy link
@jxnblk

jxnblk May 8, 2019

Member

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

This comment has been minimized.

Copy link
@timhudson

timhudson May 8, 2019

Author Contributor

Good catch! Addressed in cc67fbb.

This comment has been minimized.

Copy link
@jxnblk

jxnblk May 8, 2019

Member

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

3 of 6 checks passed

Header rules - styled-system No header rules processed
Details
Pages changed - styled-system All files already uploaded
Details
Redirect rules - styled-system No redirect rules processed
Details
Mixed content - styled-system No mixed content detected
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
netlify/styled-system/deploy-preview Deploy preview ready!
Details

@timhudson timhudson deleted the timhudson:merge-max-call-stack branch May 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.