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

Forward shouldForwardProp through withComponent #1668

Merged
merged 5 commits into from
Sep 4, 2020

Conversation

animecyc
Copy link
Contributor

@animecyc animecyc commented Dec 3, 2019

What:

Why:

  • Ensures similar composition semantics as the as prop. This sort of begs the question of whether or not the withComponent functionality is needed given we have the as prop; Regardless, they should operate the same if the API exists.

How:

  • Coalesces shouldForwardProp together with options and nextOptions.

Checklist:

  • Documentation
  • Tests
  • Code complete
  • Changeset

@changeset-bot
Copy link

changeset-bot bot commented Dec 3, 2019

🦋 Changeset is good to go

Latest commit: 81a6877

We got this.

This PR includes changesets to release 6 packages
Name Type
@emotion/styled Major
@emotion/react Major
@emotion/jest Major
@emotion/primitives-core Major
@emotion/native Major
@emotion/primitives Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link

codecov bot commented Dec 3, 2019

Codecov Report

Merging #1668 into next will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted Files Coverage Δ
packages/styled/src/base.js 100% <100%> (ø) ⬆️
packages/jest-emotion/src/index.js 100% <0%> (ø) ⬆️
packages/jest-emotion/src/utils.js 96.96% <0%> (+0.06%) ⬆️

@Andarist Andarist changed the base branch from master to next December 3, 2019 22:07
@Andarist
Copy link
Member

Andarist commented Dec 3, 2019

Could you branch your change out from the next branch?

@animecyc
Copy link
Contributor Author

animecyc commented Dec 4, 2019

Could you branch your change out from the next branch?

Sure, reconciling things now.

@Andarist
Copy link
Member

Andarist commented Dec 5, 2019

Not sure exactly why, but the diff includes stuff that it shouldn't. Maybe it would be best to just close this PR and reopen it after branching away from next and cherry-picking your single commit?

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 5, 2019

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 81a6877:

Sandbox Source
Emotion Configuration

@animecyc
Copy link
Contributor Author

animecyc commented Dec 5, 2019

Not sure exactly why, but the diff includes stuff that it shouldn't. Maybe it would be best to just close this PR and reopen it after branching away from next and cherry-picking your single commit?

I thought I pushed, sorry -- its been reconciled now.

? propName =>
nextOptions.shouldForwardProp(propName) &&
defaultShouldForwardProp(propName)
: defaultShouldForwardProp
Copy link
Contributor Author

@animecyc animecyc Dec 5, 2019

Choose a reason for hiding this comment

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

My understanding here is that we want to pipe the shouldForwardProp calls like a funnel (C -> B -> A) using either the supplied shouldForwardProp falling back to the composed defaultShouldForwardProp of the parent.

expect(shouldForwardPropA).toHaveBeenNthCalledWith(1, 'as')
expect(shouldForwardPropA).toHaveBeenNthCalledWith(2, 'disabled')

expect(tree).toMatchSnapshot()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I figured it would be good to be a bit more explicit with this test and the calls made to shouldForwardProp on each withComponent

- Fixes a bug that prevented `shouldForwardProp` from forwarding to components created via `withComponent`; Fixes emotion-js#1394
- Compacts `createStyled`'s options argument
nextTag = { ...nextTag }
nextTag.__emotion_real = nextTag
nextTag.__emotion_styles = nextTag.__emotion_styles.slice(1)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we don't remove the prepended label for nextTag we end up with duplicate labels.

- Fixes duplicate labels when composing components.
- Allows for correctly setting the label for the new composed component.
@Andarist
Copy link
Member

@mitchellhamilton could you take this over? I'm afraid I won't have time to finish reviewing this right now.

@emmatown
Copy link
Member

@mitchellhamilton could you take this over? I'm afraid I won't have time to finish reviewing this right now.

Absolutely, no problem!

@emmatown emmatown self-requested a review December 18, 2019 21:19
})()

const ComposedDiv = styled(StyledDiv, {
shouldForwardProp: () => true
shouldForwardProp: prop => prop !== 'bar'
Copy link
Member

Choose a reason for hiding this comment

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

Why these changes? Was this test failing with the changes to styled here? If the original test here was failing, I think that's a problem.

Copy link
Member

@Andarist Andarist Aug 26, 2020

Choose a reason for hiding this comment

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

I don't think the previous version of this test was foo - it was supposed to test shouldForwardProp composition but () => true doesn't make any difference in regards to the final behavior.

This test would pass with it or without this shouldForwardProp as the composition uses && so if we fold this shouldForwardProp1(prop) && shouldForwardProp2(prop) to shouldForwardProp1(prop) && true then all we really have is shouldForwardProp1(prop)

louisgv pushed a commit to louisgv/emotion that referenced this pull request Sep 6, 2020
…mponent` (emotion-js#1668)

* Forward shouldForwardProp through withComponent

- Fixes a bug that prevented `shouldForwardProp` from forwarding to components created via `withComponent`; Fixes emotion-js#1394
- Compacts `createStyled`'s options argument

* Fixes an issue with label duplication

- Fixes duplicate labels when composing components.
- Allows for correctly setting the label for the new composed component.

* Refactor how withComponent handles shouldForwardProp

* Fix flow errors

Co-authored-by: Seth Benjamin <animecyc@Seths-MacBook-Pro.local>
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
@github-actions github-actions bot mentioned this pull request Nov 10, 2020
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