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

docs(versioning): update guide with changes to event handlers #4688

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

joshblack
Copy link
Member

This came up in our release cycle this week and I wanted to document the behavior here to make sure we're aligned 👀

This updates our versioning guide with a specific case around making event handlers broaden, specifically when changing the element type on which the event occurs.

Changelog

New

Changed

  • Add section to the versioning docs in the repo

Removed

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

This is a change to documentation

@joshblack joshblack requested a review from a team as a code owner June 20, 2024 18:03
@joshblack joshblack requested a review from TylerJDev June 20, 2024 18:03
Copy link

changeset-bot bot commented Jun 20, 2024

⚠️ No Changeset found

Latest commit: 7ab6da2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Contributor

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 90.8 KB (0%)
packages/react/dist/browser.umd.js 91.16 KB (0%)

Copy link
Member

@broccolinisoup broccolinisoup left a comment

Choose a reason for hiding this comment

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

Thanks so much for pushing this PR! Types are hard, versioning types are harder 😆 Left a comment and questions, looking forward to hearing your thoughts 🙌🏻


### The element type in an event handler becomes broader

semver bump: **major**
Copy link
Member

Choose a reason for hiding this comment

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

Just to note that I am making this comment ActionList semantics issue in mind 🙂

It feels to me that types, especially the event type changes in that PR, feels a bit blur to me in terms of semver. Because on the consumers side, the event types are event: React.MouseEvent<HTMLLIElement> | React.KeyboardEvent<HTMLLIElement> and since it doesn't overlap with event: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>, it fails. However if the types were less specific, or in other words, maybe not directly rely on the component details i.e. expecting the event to be triggered on the li element, that changes wouldn't break anything. Based on this, would this be more like "potentially breaking" ? 🤔 I would love to learn more about the best practises on the consumer side as well if you have thoughts on that! Is this a good practise to "hard code" the event types like currently or can they be inferred from what is defined in the component? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

However if the types were less specific, or in other words, maybe not directly rely on the component details i.e. expecting the event to be triggered on the li element, that changes wouldn't break anything. Based on this, would this be more like "potentially breaking" ? 🤔

I think you're spot on pointing out that it 100% depends on what the caller is doing with the types. As you pointed out, this is definitely a case where if the caller had a less strict type or used the type from the component prop interfaces there wouldn't be any breakage that we would observe.

In general, I think broadening a type could be considered "potentially breaking". I think we have scenarios where it is okay like in:

type ComponentProps = {
-  variant?: 'a' | 'b',
+  variant?: 'a' | 'b' | 'c',
};

But then we have cases like this with an event handler where it will cause issues downstream:

-onClick: (gesture: 'a' | 'b') => void,
+onClick: (gesture: 'a' | 'b' | 'c') => void,

These seem like breaking changes to me since the caller cannot use the update without modifying their code. I think that the example for this with the generic would fall under this scenario since folks would have to update their code for it.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks Josh, this is great! I love the comparison you made above between the two examples.

These seem like breaking changes to me since the caller cannot use the update without modifying their code.

I like how you frame it. I think most of the time, this is a great indication to use to assess the versioning unless the consumer code is misused in the first place but this is another story 😅

Thanks for pushing this PR again, I appreciate talking about it and keeping it on the docs 🙏🏻

@joshblack joshblack added this pull request to the merge queue Jun 25, 2024
Merged via the queue into main with commit a2224c5 Jun 25, 2024
35 of 36 checks passed
@joshblack joshblack deleted the docs/add-event-types-to-versioning branch June 25, 2024 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip changeset This change does not need a changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants