Skip to content

fix(packages/ui,packages/cli,packages/zpress): resolve duplicate React instances in dev server#90

Merged
zrosenbauer merged 5 commits intomainfrom
fix/dev-server
Apr 10, 2026
Merged

fix(packages/ui,packages/cli,packages/zpress): resolve duplicate React instances in dev server#90
zrosenbauer merged 5 commits intomainfrom
fix/dev-server

Conversation

@zrosenbauer
Copy link
Copy Markdown
Member

Summary

  • Fixes "Invalid hook call" errors when running zpress dev in consumer repos (e.g. kidd, serenity)
  • Root cause: pnpm installed a private React copy for @zpress/cli, creating two React instances that rspack resolved inconsistently during theme compilation

Changes

  • packages/ui/src/config.ts — Add react and react-dom resolve aliases to the Rspress builder config, forcing rspack to use the consumer's single React instance
  • packages/cli/package.json — Move react from dependencies to peerDependencies (kept in devDependencies) so pnpm no longer installs a separate copy in consumer repos
  • packages/zpress/package.json — Align React peer version range from ^19.2.4 to ^19.2.5

Test plan

  • Run zpress dev in kidd repo — verify no "Invalid hook call" errors and dev server loads
  • Run zpress dev in serenity repo — verify dev server loads
  • Run zpress build in both repos — verify production build succeeds
  • Verify theme components render correctly (sidebar, nav, home page)

…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>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
oss-zpress Ready Ready Preview, Comment Apr 10, 2026 6:24pm

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 10, 2026

🦋 Changeset detected

Latest commit: 312eaab

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@zpress/ui Patch
@zpress/cli Patch
@zpress/kit Patch

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

The 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 @zpress/kit, refactors configuration example keys (linkpath, frominclude), and adds a pnpm packageExtensions entry for the ink-gradient package to declare React as a peer dependency.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main objective: fixing duplicate React instances in the dev server across the affected packages.
Description check ✅ Passed The description is directly related to the changeset, clearly explaining the root cause, changes made, and test plan for resolving duplicate React instances.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between c02525c and 4a175b0.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (4)
  • .changeset/fix-duplicate-react.md
  • packages/cli/package.json
  • packages/ui/src/config.ts
  • packages/zpress/package.json

Comment thread packages/ui/src/config.ts Outdated
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>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between e62c308 and 312eaab.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (3)
  • examples/simple/zpress.config.ts
  • package.json
  • packages/ui/src/config.ts

Comment thread package.json
@zrosenbauer zrosenbauer merged commit ffed994 into main Apr 10, 2026
5 checks passed
@zrosenbauer zrosenbauer deleted the fix/dev-server branch April 10, 2026 19:53
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.

1 participant