Skip to content

Commit cdfecd1

Browse files
authored
Revert "feat: remove npm flags" (#5707)
* Revert "feat: remove npm flags (#5686)" This reverts commit 4ff64ba. * chore: temporarily bring back flag
1 parent 2c043e7 commit cdfecd1

File tree

4 files changed

+63
-47
lines changed

4 files changed

+63
-47
lines changed

.changeset/calm-bees-train.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"shadcn": patch
3+
---
4+
5+
temporarily bring back npm flag

apps/www/content/docs/components/chart.mdx

+12-42
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ description: Beautiful charts. Built using Recharts. Copy and paste into your ap
44
component: true
55
---
66

7+
<Callout className="mb-6">
8+
9+
**Note:** If you are using charts with **React 19** or the **Next.js 15**, see the note [here](/docs/react-19#recharts).
10+
11+
</Callout>
12+
713
<ComponentPreview
814
name="chart-bar-interactive"
915
className="-mt-4 [&_.preview]:p-0 [&_.preview]:border-t [&_.preview>div]:shadow-none [&_.preview>div]:border-none [&_.preview>div]:w-full [&_.preview]:lg:min-h-[404px]"
@@ -45,6 +51,12 @@ We do not wrap Recharts. This means you're not locked into an abstraction. When
4551

4652
## Installation
4753

54+
<Callout className="mt-4">
55+
56+
**Note:** If you are using charts with **React 19** or the **Next.js 15**, see the note [here](/docs/react-19#recharts).
57+
58+
</Callout>
59+
4860
<Tabs defaultValue="cli">
4961

5062
<TabsList>
@@ -83,27 +95,6 @@ npx shadcn@latest add chart
8395
}
8496
```
8597

86-
<Step>
87-
To use recharts with React 19 and Next.js 15, you will need to override the
88-
`react-is` dependency.{" "}
89-
</Step>
90-
91-
Add the following to your `package.json`
92-
93-
```json title="package.json"
94-
"overrides": {
95-
"react-is": "^19.0.0-rc-69d4b800-20241021"
96-
}
97-
```
98-
99-
Note: the `react-is` version needs to match the version of React 19 you are using. The above is an example.
100-
101-
<Step>Run `npm install`</Step>
102-
103-
```bash
104-
npm install
105-
```
106-
10798
</Steps>
10899

109100
</TabsContent>
@@ -144,27 +135,6 @@ npm install recharts
144135
}
145136
```
146137

147-
<Step>
148-
To use recharts with React 19 and Next.js 15, you will need to override the
149-
`react-is` dependency.{" "}
150-
</Step>
151-
152-
Add the following to your `package.json`
153-
154-
```json title="package.json"
155-
"overrides": {
156-
"react-is": "^19.0.0-rc-69d4b800-20241021"
157-
}
158-
```
159-
160-
Note: the `react-is` version needs to match the version of React 19 you are using. The above is an example.
161-
162-
<Step>Run `npm install`</Step>
163-
164-
```bash
165-
npm install
166-
```
167-
168138
</Steps>
169139

170140
</TabsContent>

apps/www/content/docs/react-19.mdx

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ title: Next.js 15 + React 19
33
description: Using shadcn/ui with Next.js 15 and React 19.
44
---
55

6-
**shadcn/ui is now fully compatible with React 19!**
7-
8-
<Callout className="mt-6">
6+
<Callout>
97
**The following guide applies to any framework that supports React 19**. I
108
titled this page "Next.js 15 + React 19" to help people upgrading to Next.js
119
15 find it. We are working with package maintainers to help upgrade to React
@@ -144,7 +142,7 @@ To make it easy for you track the progress of the upgrade, I've created a table
144142
| [react-day-picker](https://www.npmjs.com/package/react-day-picker) || Works with flag for npm. Work to upgrade to v9 in progress. |
145143
| [input-otp](https://www.npmjs.com/package/input-otp) || |
146144
| [vaul](https://www.npmjs.com/package/vaul) || |
147-
| [@radix-ui/react-icons](https://www.npmjs.com/package/@radix-ui/react-icons) | | |
145+
| [@radix-ui/react-icons](https://www.npmjs.com/package/@radix-ui/react-icons) | 🚧 | See [PR #194](https://github.com/radix-ui/icons/pull/194) |
148146
| [cmdk](https://www.npmjs.com/package/cmdk) || |
149147

150148
If you have any questions, please [open an issue](https://github.com/shadcn/ui/issues) on GitHub.

packages/shadcn/src/utils/updaters/update-dependencies.ts

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { Config } from "@/src/utils/get-config"
2+
import { getPackageInfo } from "@/src/utils/get-package-info"
23
import { getPackageManager } from "@/src/utils/get-package-manager"
4+
import { logger } from "@/src/utils/logger"
35
import { RegistryItem } from "@/src/utils/registry/schema"
46
import { spinner } from "@/src/utils/spinner"
57
import { execa } from "execa"
8+
import prompts from "prompts"
69

710
export async function updateDependencies(
811
dependencies: RegistryItem["dependencies"],
@@ -26,12 +29,52 @@ export async function updateDependencies(
2629
})?.start()
2730
const packageManager = await getPackageManager(config.resolvedPaths.cwd)
2831

32+
// Offer to use --force or --legacy-peer-deps if using React 19 with npm.
33+
let flag = ""
34+
if (isUsingReact19(config) && packageManager === "npm") {
35+
dependenciesSpinner.stopAndPersist()
36+
logger.warn(
37+
"\nIt looks like you are using React 19. \nSome packages may fail to install due to peer dependency issues in npm (see https://ui.shadcn.com/react-19).\n"
38+
)
39+
const confirmation = await prompts([
40+
{
41+
type: "select",
42+
name: "flag",
43+
message: "How would you like to proceed?",
44+
choices: [
45+
{ title: "Use --force", value: "force" },
46+
{ title: "Use --legacy-peer-deps", value: "legacy-peer-deps" },
47+
],
48+
},
49+
])
50+
51+
if (confirmation) {
52+
flag = confirmation.flag
53+
}
54+
}
55+
56+
dependenciesSpinner?.start()
57+
2958
await execa(
3059
packageManager,
31-
[packageManager === "npm" ? "install" : "add", ...dependencies],
60+
[
61+
packageManager === "npm" ? "install" : "add",
62+
...(packageManager === "npm" && flag ? [`--${flag}`] : []),
63+
...dependencies,
64+
],
3265
{
3366
cwd: config.resolvedPaths.cwd,
3467
}
3568
)
3669
dependenciesSpinner?.succeed()
3770
}
71+
72+
function isUsingReact19(config: Config) {
73+
const packageInfo = getPackageInfo(config.resolvedPaths.cwd)
74+
75+
if (!packageInfo?.dependencies?.react) {
76+
return false
77+
}
78+
79+
return /^(?:\^|~)?19(?:\.\d+)*(?:-.*)?$/.test(packageInfo.dependencies.react)
80+
}

0 commit comments

Comments
 (0)