Skip to content

Conversation

@rossipedia
Copy link
Contributor

Yarn@4 is reporting that @react-router/dev isn't properly fulfilling the peerDependencies declared by @vitejs/plugin-rsc:

pe2594 → ✘ @react-router/dev@npm:7.8.2 [87a77] doesn't provide react to @vitejs/plugin-rsc@npm:0.4.11 [63686]
pdd559 → ✘ @react-router/dev@npm:7.8.2 [87a77] doesn't provide react-dom to @vitejs/plugin-rsc@npm:0.4.11 [63686]

Looking at the package.json for @vitejs/plugin-rsc, that seems accurate:

https://github.com/vitejs/vite-plugin-react/blob/508bed6625d899fd5123b5495fe81166f2e9fa2f/packages/plugin-rsc/package.json#L66-L67

Since @react-router/dev doesn't need react or react-dom itself direct as dependencies or devDependencies, I believe the correct setup is to add them to peerDependencies so that dependency chain can be delegated up to the consuming React Router application.

@changeset-bot
Copy link

changeset-bot bot commented Aug 30, 2025

⚠️ No Changeset found

Latest commit: 5851634

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

@MichaelDeBoey MichaelDeBoey changed the title Add react and react-dom to @react-router/dev peer deps fix(dev): add react & react-dom to peerDependencies Aug 30, 2025
@MichaelDeBoey MichaelDeBoey added dependencies Pull requests that update a dependency file pkg:@react-router/dev labels Aug 30, 2025
Copy link
Member

@MichaelDeBoey MichaelDeBoey left a comment

Choose a reason for hiding this comment

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

It feels a bit odd to have to add these to @react-router/dev 🤔
But I do get that an React Server Components plugin needs them

@hi-ogawa so I guess we can't just remove them upstream?

@rossipedia
Copy link
Contributor Author

rossipedia commented Aug 30, 2025

It feels a bit odd to have to add these to @react-router/dev 🤔 But I do get that an React Server Components plugin needs them

Yeah that was my initial thought as well, but it kinda does make sense since @react-router/dev is sorta wrapping @vitejs/plugin-rsc and acting kinda like an intermediary.

But I can also see @react-router/dev declaring them as peer deps since it's a React Router package 🤔 even though it might not directly utilize them itself.

@hi-ogawa
Copy link
Contributor

I think @react-router/dev should have the peer dependencies already since they are referenced by the package files through (non-rsc) default entries such as:

import { startTransition, StrictMode } from "react";
import { hydrateRoot } from "react-dom/client";
import { HydratedRouter } from "react-router/dom";

Probably they didn't cause issues only because resolve.dedupe forces Vite's resolution to pick up these deps from root project dependencies.

resolve: {
dedupe: [
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
"react",
"react-dom",

@MichaelDeBoey
Copy link
Member

@hi-ogawa Files like react-router/packages/react-router-dev/config/defaults/entry.client.tsx are default files and act as a convenience like they are in the user's codebase, so they're technically not used/needed by @react-router/dev, so I would argue that (for these files) @react-router/dev doesn't need to have a dependency on react/react-dom

@markdalgleish
Copy link
Member

markdalgleish commented Sep 1, 2025

I've opened a PR that makes @vitejs/plugin-rsc and optional peer dep rather than a dependency of @react-router/dev which should fix the original issue behind this PR: #14270

I agree with @hi-ogawa's point that react and react-router should technically be peer deps since they need to be accessible from @react-router/dev when the default entries are used. Maybe they should be optional peer deps so this change doesn't cause issues for consumers using this package in other scenarios?

@rossipedia rossipedia closed this Sep 21, 2025
@rossipedia
Copy link
Contributor Author

Don't think this is necessary anymore 👍

@rossipedia rossipedia deleted the chore/rsc-plugin-peer-deps branch September 21, 2025 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed dependencies Pull requests that update a dependency file pkg:@react-router/dev

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants