fix(packages/ui,packages/cli,packages/zpress): resolve duplicate React instances in dev server#90
Conversation
…t instances in dev server pnpm's strict isolation caused consumer repos to get two React copies — one from the consumer's peer dep and one privately installed for @zpress/cli. Rspress's rspack resolved theme components to a different React instance, triggering "Invalid hook call" errors and preventing the dev server from loading. - Add react/react-dom resolve aliases in Rspress builder config - Move react from dependencies to peerDependencies in @zpress/cli - Align React peer version in @zpress/kit to ^19.2.5 Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 312eaab The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughThe pull request adds a changeset documenting patch releases and addresses duplicate React instance issues across the monorepo. It introduces rspack resolve aliases in the Rspress configuration to ensure a single React instance resolution, updates React peer dependency constraints from ^19.2.4 to ^19.2.5 in 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/ui/src/config.ts`:
- Around line 83-85: The aliases currently set via
projectRequire.resolve('react') and projectRequire.resolve('react-dom') point to
package entry files which breaks rspack's prefix-matching for subpath imports;
change the alias targets to the package directories by resolving
'react/package.json' and 'react-dom/package.json' and taking their directory
(use path.dirname on projectRequire.resolve('react/package.json') and
projectRequire.resolve('react-dom/package.json')), or alternatively add explicit
subpath aliases for 'react/jsx-runtime' and 'react-dom/client'; update the
variables reactAlias and reactDomAlias (and any code that uses them) to use
those package directories instead of entry-file paths so subpath imports resolve
correctly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: b8f1683c-4870-4a82-a3ae-a902ca41cc00
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!pnpm-lock.yaml
📒 Files selected for processing (4)
.changeset/fix-duplicate-react.mdpackages/cli/package.jsonpackages/ui/src/config.tspackages/zpress/package.json
Rspack uses prefix matching for aliases, so aliasing react to its entry file (index.js) would break subpath imports like react/jsx-runtime. Resolve to the package directory instead via react/package.json dirname. Co-Authored-By: Claude <noreply@anthropic.com>
ink-gradient and other ink transitive deps import react directly. With pnpm's strict isolation, moving react to peerDependencies breaks these transitive imports on Vercel. Keep react in dependencies for runtime resolution; the webpack alias in @zpress/ui handles browser deduplication independently. Co-Authored-By: Claude <noreply@anthropic.com>
…-gradient and react alias - Add packageExtensions for ink-gradient to declare react as a peer dep (ink-gradient imports react without declaring it, breaking pnpm strict mode) - Resolve react alias from @zpress/ui's own context (import.meta.url) instead of project root, which may not have react as a direct dependency Co-Authored-By: Claude <noreply@anthropic.com>
Replace removed keys (link, from, prefix, titleFrom) with their current equivalents (path, include). Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@package.json`:
- Around line 68-73: The packageExtensions entry under pnpm.packageExtensions
(specifically the "ink-gradient" block adding a peerDependencies "react": "*")
is workspace-local and won’t be published, so update the actual package
manifest(s) that will be published: add the peerDependencies declaration
("react": "*") to the ink-gradient package's package.json (or to any `@zpress/`*
package that re-exports or wraps it) so consumers receive the peer metadata;
remove or keep the root packageExtensions for local development only, but ensure
the published package.json has the correct peerDependencies field.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: d92910d9-0467-4cae-a59b-f0ac5c9ad893
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!pnpm-lock.yaml
📒 Files selected for processing (3)
examples/simple/zpress.config.tspackage.jsonpackages/ui/src/config.ts
Summary
zpress devin consumer repos (e.g. kidd, serenity)@zpress/cli, creating two React instances that rspack resolved inconsistently during theme compilationChanges
packages/ui/src/config.ts— Addreactandreact-domresolve aliases to the Rspress builder config, forcing rspack to use the consumer's single React instancepackages/cli/package.json— MovereactfromdependenciestopeerDependencies(kept indevDependencies) so pnpm no longer installs a separate copy in consumer repospackages/zpress/package.json— Align React peer version range from^19.2.4to^19.2.5Test plan
zpress devin kidd repo — verify no "Invalid hook call" errors and dev server loadszpress devin serenity repo — verify dev server loadszpress buildin both repos — verify production build succeeds