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

feat: Move @types/react-dom to optional peer dependencies #1305

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Apr 22, 2024

Closes #1184
Docs: testing-library/testing-library-docs#1384

BREAKING CHANGE:
@testing-library/dom was moved to a peer dependency and needs to be explicitly installed. This reduces the chance of having conflicting versions of @testing-library/dom installed that frequently caused bugs when used with @testing-library/user-event.
@types/react-dom needs to be installed if you're typechecking files using @testing-library/react.

Type dependencies need to match their runtime counterpart.
If foo is a dependency, @types/foo needs to be one as well.
If foo is a peer dependency, @types/foo needs to be one as well.
This is especially apparent if the constraint on foo spans multiple major versions.
If we'd make @types/foo a direct dependency, users couldn't control which major version they get.
Package managers would pick the highest.
By moving @types/foo to peer dependencies, users can control which version of @types/foo they have.

In our case specifically, you'd get type mismatches of @types/react-dom if we just widen the peer dependency constraint from ^18 to ^18 | ^19. Currently, we're already compatible with the planned React 19 features so all we'd have to do is widen the constraint on release.

Copy link

codesandbox-ci bot commented Apr 22, 2024

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 c4b764e:

Sandbox Source
react-testing-library-examples Configuration

MatanBobi
MatanBobi previously approved these changes Apr 23, 2024
Copy link
Member

@MatanBobi MatanBobi left a comment

Choose a reason for hiding this comment

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

Thanks.
Just a thought since we're doing this and bumping a major - lately we're having many issues with DTL version mismatches in RTL and user-event, do we maybe want to think about also move DTL to peerDeps?

@eps1lon
Copy link
Member Author

eps1lon commented Apr 23, 2024

do we maybe want to think about also move DTL to peerDeps?

I think so. Since DTL is stateful due to the config object, having multiple versions is problematic.

Ideally we wouldn't have the stateful config object to begin with but that requires a large refactor that needs coordination.

We don't need to rush this in this PR though. Could you help out and prepare docs and a commit making that change?

@MatanBobi
Copy link
Member

We don't need to rush this in this PR though. Could you help out and prepare docs and a commit making that change?

Sure thing, I'll get to it later this week.

@MatanBobi
Copy link
Member

MatanBobi commented Apr 24, 2024

@eps1lon Wdyt about making this change as part of a major too? #1277

Also, here's the PR to move DTL to peer: #1309

@eps1lon
Copy link
Member Author

eps1lon commented Apr 24, 2024

Also, here's the PR to move DTL to peer: #1309

Just push this commit to this branch. I don't want to go through the alpha branch shenanigans and just ship the major with one PR.

@MatanBobi
Copy link
Member

Just push this commit to this branch. I don't want to go through the alpha branch shenanigans and just ship the major with one PR.

Done. I haven't fixed the conflicts though as we have more changes coming to that file.

Type dependencies need to match their runtime counterpart.
If `foo` is a dependency, `@types/foo` needs to be one as well.
If `foo` is a peer dependency, `@types/foo` needs to be one as well.
This is especially apparent if the constraint on `foo` spans multiple major versions.
If we'd make `@types/foo` a direct dependency, users couldn't control which major version they get.
Package managers would pick the highest.
By moving `@types/foo` to peer dependencies, users can control which version of `foo` and  `@types/foo` they have.
commit 2fa5eac
Author: Matan Borenkraout <matanbobi@gmail.com>
Date:   Wed Apr 24 11:06:27 2024 +0300

    fix formatting

commit 7a07982
Author: Matan Borenkraout <matanbobi@gmail.com>
Date:   Wed Apr 24 09:14:25 2024 +0300

    feat!: move dtl to peerDeps
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.

Type conflicts in testing-library vs react
2 participants