fix: move optional dependencies to peerDependencies#384
fix: move optional dependencies to peerDependencies#384james-elicx merged 4 commits intocloudflare:mainfrom
Conversation
commit: |
|
/bigbonk review |
There was a problem hiding this comment.
Thanks for the PR — the intent makes sense. Moving @vitejs/plugin-rsc and react-server-dom-webpack out of dependencies prevents them from being unconditionally installed in users' node_modules, which is the right thing to do since they're only needed for App Router.
A few points to consider:
1. @vitejs/plugin-rsc and react-server-dom-webpack should arguably NOT be optional
These packages are required for any App Router project. vinext's index.ts throws a hard error if @vitejs/plugin-rsc isn't installed when app/ is detected (line 690). Similarly, the App Router entry files have static imports from @vitejs/plugin-rsc/rsc, @vitejs/plugin-rsc/ssr, and @vitejs/plugin-rsc/browser.
Marking them as optional peer deps means package managers won't warn users if they're missing. That pushes the error discovery to runtime rather than install time. The current code handles this gracefully with helpful error messages, so it's not catastrophic — but it's worth considering whether the "optional" annotation is the right signal.
For Pages Router-only projects, these truly aren't needed. So the "optional" marking is technically correct, but the ergonomics are a tradeoff.
2. Version range mismatch for react-server-dom-webpack
See inline comment — devDependencies pins ^19.2.4 but peerDependencies says >=19.2.0. These should be consistent.
3. @mdx-js/rollup was never a dependency — adding it as optional peer is good
This is a nice addition. The codebase already tries a dynamic import("@mdx-js/rollup") with a fallback warning, so declaring it as an optional peer dep makes the relationship explicit.
Overall this is a reasonable change — the core idea of not force-installing these on every user is correct. Just the version range inconsistency should be addressed.
| "@mdx-js/rollup": { | ||
| "optional": true | ||
| }, | ||
| "@vitejs/plugin-rsc": { |
There was a problem hiding this comment.
Given that @vitejs/plugin-rsc is required for App Router (vinext throws a hard error at index.ts:690 if it's missing when app/ is detected, and App Router entries have static imports from it), marking it as optional may cause confusion. Users who set up an App Router project and skip this dependency won't get a package manager warning — they'll only find out at runtime.
Same applies to react-server-dom-webpack — it's a transitive requirement of @vitejs/plugin-rsc.
This is arguably fine since vinext has good runtime error messages, and Pages Router users genuinely don't need these. Just flagging it as a design tradeoff worth an explicit decision.
|
Review posted. Here's a summary of the feedback:
|
|
Version is updated for |
|
/bigbonk re-review |
There was a problem hiding this comment.
LGTM. This is a correct and well-scoped change.
What this does: Moves @vitejs/plugin-rsc and react-server-dom-webpack from dependencies (unconditionally installed) to optional peerDependencies (user manages installation). Adds @mdx-js/rollup as a new optional peer dep.
Why it's correct:
@vitejs/plugin-rscis only needed for App Router projects. The codebase already handles its absence gracefully —index.tspre-resolves it viacreateRequirein a try/catch, and only throws a clear error if App Router is detected without it. Pages Router projects work fine without it.react-server-dom-webpackis never directly imported by vinext — it's consumed transitively through@vitejs/plugin-rsc's subpath exports. Declaring it as an optional peer makes the relationship explicit for App Router users without forcing installation on Pages Router users.@mdx-js/rollupalready uses a dynamicimport()with a try/catch fallback (index.ts:982), logging a warning if missing. Adding it as an optional peer documents the relationship without introducing a hard requirement.- Version ranges now align:
^0.5.19for@vitejs/plugin-rscand^19.2.4forreact-server-dom-webpackin bothdevDependenciesandpeerDependencies. - The lockfile changes are minimal and expected — just moving entries between dependency categories.
The previous review's concern about optional peers masking install-time warnings is a reasonable tradeoff observation, but vinext's runtime error messages (init.ts:getInitDeps, deploy.ts missing-dep checks, and the startup error in index.ts) cover the user experience adequately.
|
Review submitted. Here's a summary of my findings: Approved — this is a correct and well-scoped change. The PR moves Key validation points:
|
We are currently installing these dependencies on the user side.