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

fix: add react-dom as peer dependency #3786

Merged
merged 3 commits into from
Jul 13, 2022

Conversation

duarten
Copy link
Contributor

@duarten duarten commented Jul 8, 2022

If missing, then strict package managers like pnpm will not link this
react-dom in, causing react-query to fail at runtime cause it can't load
react-dom.

Fixes #3534

@vercel
Copy link

vercel bot commented Jul 8, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
query ✅ Ready (Inspect) Visit Preview Jul 13, 2022 at 3:52PM (UTC)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 8, 2022

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 4e78c7c:

Sandbox Source
@tanstack/query-example-react-basic Configuration
@tanstack/query-example-react-basic-typescript Configuration

Copy link
Collaborator

@TkDodo TkDodo left a comment

Choose a reason for hiding this comment

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

thanks. I guess we need react-native as well then, because we have both react-dom and react-native marked as optional in peerDependenciesMeta, right ?

@duarten
Copy link
Contributor Author

duarten commented Jul 13, 2022

thanks. I guess we need react-native as well then, because we have both react-dom and react-native marked as optional in peerDependenciesMeta, right ?

Yeah, that's right. I can add it to the PR, but I'm not sure what the version selector should be?

@TkDodo
Copy link
Collaborator

TkDodo commented Jul 13, 2022

Yeah, that's right. I can add it to the PR, but I'm not sure what the version selector should be?

yeah me neither. @arnaudbzn might know, or @hirbod ?

@hirbod
Copy link
Contributor

hirbod commented Jul 13, 2022

Depends. Expo users need 0.68.2, while RN is available at 0.69.1.
Expo SDK will release SDK 46 soon, which will also be at 0.69.1 (or .2)

@TkDodo
Copy link
Collaborator

TkDodo commented Jul 13, 2022

@hirbod can we just do >0.68.0 ? or is actually any version, so *, enough for us? react-query doesn't really care which version of react-native you use, right?

@hirbod
Copy link
Contributor

hirbod commented Jul 13, 2022

It's hard to say. I think folks might end up with the need to add a yarn resolution when different versions being installed.

Potentially, there could still be plenty of 0.64.3 users as well (SDK 44)

I think that * might be the correct way. Irc, @satya164 was tweeting about peer dep issues a while ago. He might know the correct answer.

@TkDodo
Copy link
Collaborator

TkDodo commented Jul 13, 2022

are optional peer dependencies also installed automatically ? I didn't think so, but not sure 🤔

@TkDodo
Copy link
Collaborator

TkDodo commented Jul 13, 2022

see: https://docs.npmjs.com/cli/v7/configuring-npm/package-json#peerdependenciesmeta

Marking a peer dependency as optional ensures npm will not emit a warning if the soy-milk package is not installed on the host. This allows you to integrate and interact with a variety of host packages without requiring all of them to be installed.

@hirbod
Copy link
Contributor

hirbod commented Jul 13, 2022

Yeah, that was something similar he was tweeting. Most people did the mistake to add it as devDependency, instead of peer. Adding * should be fine. All expo modules packages I know also add expo as *.

@TkDodo
Copy link
Collaborator

TkDodo commented Jul 13, 2022

thanks. @duarten then let's do react-native: '*' please as a peer dependency

@duarten
Copy link
Contributor Author

duarten commented Jul 13, 2022

Done!

@satya164
Copy link
Contributor

Keep in mind that adding react-native as a peer dependency means people who don't use react-native and use npm will get react-native installed since npm auto-installs missing peer deps. If they use yarn then they'll get a missing peer dep warning. Same for react-dom and react-native users.

I'd suggest not adding this peer dep. I haven't used pnpm but afaik pnpm users could add some extra config to make this work: pnpm/pnpm#4183 (comment) or maybe there's another way to specify this.

@TkDodo TkDodo merged commit b57e154 into TanStack:beta Jul 13, 2022
@TkDodo
Copy link
Collaborator

TkDodo commented Jul 13, 2022

sorry @satya164 I just saw your comment right now. I was under the impression that since the dependencies are marked as optional in peerDependenciesMeta, they would not be auto installed with npm. Is that not right?

@satya164
Copy link
Contributor

@TkDodo ah I right, I hadn't checked the full file, yes that should be fine then.

@ingvaldlorentzen
Copy link

ingvaldlorentzen commented Aug 8, 2022

Seems like npm sadly does auto-install optional peerDepedencies. There is a discussion about it on in the npm/feedback repo. Though there does seem to be some confusion as to what npm is supposed to do, and wether this is a bug or not.

I would suggest react-query remove react-native and react-dom as peerDependencies, i.e. reverse this PR, until this is solved in npm. As installing react-query in a web project now, results in react-native being installed, which adds a lot of potential issues to otherwise simple projects.

It's also worth noting that this is preventing us from setting react and react-dom to a version higher than 18.0.0 as it seems react-native doesn't support e.g. v18.2.0.

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.

Missing dependency on react-dom leads to runtime errors when using yarn berry
5 participants