Skip to content

[lexical-yjs] Bug Fix: Mark the yjs peer optional, as @lexical/react already does - #9931

Open
xiezhenjia-meta wants to merge 1 commit into
meta:mainfrom
xiezhenjia-meta:fix/lexical-yjs-optional-yjs-peer
Open

xiezhenjia-meta wants to merge 1 commit into
meta:mainfrom
xiezhenjia-meta:fix/lexical-yjs-optional-yjs-peer

Conversation

@xiezhenjia-meta

Copy link
Copy Markdown
Contributor

Description

@lexical/react depends on @lexical/yjs unconditionally and marks its own
yjs peer optional, because only @lexical/react/LexicalCollaborationPlugin
loads @lexical/yjs and yjs at runtime. @lexical/yjs declares the same
yjs peer without marking it optional, so the required peer comes back
through the transitive edge: every app that uses @lexical/react without
collaboration gets yjs auto-installed by pnpm (autoInstallPeers: true) or
a missing required yjs peer (autoInstallPeers: false).

This marks yjs optional in @lexical/yjs's peerDependenciesMeta. Its
range is unchanged, so a yjs that is installed is still checked against it;
code that loads @lexical/yjs still needs yjs installed, as before.
Moving @lexical/yjs to an optional peer of @lexical/react instead would be
a breaking change for collaboration users and conflicts with the "must not
have monorepo peerDependencies" audit.

A new package.json audit in scripts/__tests__/unit/build.test.ts checks
that a peer a package marks optional is also optional in every monorepo
package in its dependency tree that declares it; @lexical/react ->
@lexical/yjs -> yjs is the only violation today.

Changeset

Added .changeset/yjs-optional-peer.md (@lexical/yjs: patch, [fix]).

Test plan

Before

$ pnpm exec vitest --project scripts-unit --no-watch scripts/__tests__/unit/build.test.ts
 FAIL  |scripts-unit| scripts/__tests__/unit/build.test.ts > public package.json audits (`pnpm run update-packages` to fix most issues) > @lexical/react > keeps its optional peerDependencies optional in the monorepo packages it depends on
AssertionError: expected [ '@lexical/yjs requires yjs' ] to deeply equal []

App depending on @lexical/react@0.53.0 only, autoInstallPeers: false:

$ pnpm peers check
Issues with peer dependencies found

✕ missing peer yjs
  Wanted:
    >=13.5.37:
      @lexical/yjs@0.53.0

With autoInstallPeers: true, yjs is in the lockfile.

After

$ pnpm exec vitest --project scripts-unit --no-watch scripts/__tests__/unit/build.test.ts
 Test Files  1 passed (1)
      Tests  2805 passed (2805)

Same app with @lexical/yjs 0.53.0 repacked with this peerDependenciesMeta:

$ pnpm peers check
No peer dependency issues found

With autoInstallPeers: true, yjs is no longer in the lockfile.

pnpm run update-packages leaves the manifest unchanged,
pnpm install --frozen-lockfile passes with no lockfile change, and
pnpm run check-changesets, prettier, eslint and tsc -p tsconfig.scripts.json
/ tsconfig.test.json pass.

…already does

## Description

`@lexical/react` depends on `@lexical/yjs` unconditionally and marks its own
`yjs` peer optional, because only `@lexical/react/LexicalCollaborationPlugin`
loads `@lexical/yjs` and `yjs` at runtime. `@lexical/yjs` declares the same
`yjs` peer without marking it optional, so the required peer comes back
through the transitive edge: every app that uses `@lexical/react` without
collaboration gets `yjs` auto-installed by pnpm (`autoInstallPeers: true`) or
a missing required `yjs` peer (`autoInstallPeers: false`).

This marks `yjs` optional in `@lexical/yjs`'s `peerDependenciesMeta`. Its
range is unchanged, so a `yjs` that is installed is still checked against it;
code that loads `@lexical/yjs` still needs `yjs` installed, as before.
Moving `@lexical/yjs` to an optional peer of `@lexical/react` instead would be
a breaking change for collaboration users and conflicts with the "must not
have monorepo peerDependencies" audit.

A new package.json audit in `scripts/__tests__/unit/build.test.ts` checks
that a peer a package marks optional is also optional in every monorepo
package in its dependency tree that declares it; `@lexical/react` ->
`@lexical/yjs` -> `yjs` is the only violation today.

## Test plan

### Before

```
$ pnpm exec vitest --project scripts-unit --no-watch scripts/__tests__/unit/build.test.ts
 FAIL  |scripts-unit| scripts/__tests__/unit/build.test.ts > public package.json audits (`pnpm run update-packages` to fix most issues) > @lexical/react > keeps its optional peerDependencies optional in the monorepo packages it depends on
AssertionError: expected [ '@lexical/yjs requires yjs' ] to deeply equal []
```

App depending on `@lexical/react@0.53.0` only, `autoInstallPeers: false`:

```
$ pnpm peers check
Issues with peer dependencies found

✕ missing peer yjs
  Wanted:
    >=13.5.37:
      @lexical/yjs@0.53.0
```

With `autoInstallPeers: true`, `yjs` is in the lockfile.

### After

```
$ pnpm exec vitest --project scripts-unit --no-watch scripts/__tests__/unit/build.test.ts
 Test Files  1 passed (1)
      Tests  2805 passed (2805)
```

Same app with `@lexical/yjs` 0.53.0 repacked with this `peerDependenciesMeta`:

```
$ pnpm peers check
No peer dependency issues found
```

With `autoInstallPeers: true`, `yjs` is no longer in the lockfile.

`pnpm run update-packages` leaves the manifest unchanged,
`pnpm install --frozen-lockfile` passes with no lockfile change, and
`pnpm run check-changesets`, prettier, eslint and `tsc -p tsconfig.scripts.json`
/ `tsconfig.test.json` pass.
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
lexical Ready Ready Preview Nov 17, 2026 4:45am UTC
lexical-playground Ready Ready Preview Nov 17, 2026 4:45am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 17, 2026
@rootnode-bot

rootnode-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 17, 2026, 4:58 AM UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 17, 2026

Copy link
Copy Markdown
lexical

npm i https://pkg.pr.new/lexical@9931

@lexical/a11y

npm i https://pkg.pr.new/@lexical/a11y@9931

@lexical/clipboard

npm i https://pkg.pr.new/@lexical/clipboard@9931

@lexical/code

npm i https://pkg.pr.new/@lexical/code@9931

@lexical/code-core

npm i https://pkg.pr.new/@lexical/code-core@9931

@lexical/code-prism

npm i https://pkg.pr.new/@lexical/code-prism@9931

@lexical/code-shiki

npm i https://pkg.pr.new/@lexical/code-shiki@9931

@lexical/compiler

npm i https://pkg.pr.new/@lexical/compiler@9931

@lexical/devtools-core

npm i https://pkg.pr.new/@lexical/devtools-core@9931

@lexical/dragon

npm i https://pkg.pr.new/@lexical/dragon@9931

@lexical/eslint-plugin

npm i https://pkg.pr.new/@lexical/eslint-plugin@9931

@lexical/extension

npm i https://pkg.pr.new/@lexical/extension@9931

@lexical/fast-check

npm i https://pkg.pr.new/@lexical/fast-check@9931

@lexical/file

npm i https://pkg.pr.new/@lexical/file@9931

@lexical/hashtag

npm i https://pkg.pr.new/@lexical/hashtag@9931

@lexical/headless

npm i https://pkg.pr.new/@lexical/headless@9931

@lexical/history

npm i https://pkg.pr.new/@lexical/history@9931

@lexical/html

npm i https://pkg.pr.new/@lexical/html@9931

@lexical/internal

npm i https://pkg.pr.new/@lexical/internal@9931

@lexical/link

npm i https://pkg.pr.new/@lexical/link@9931

@lexical/list

npm i https://pkg.pr.new/@lexical/list@9931

@lexical/mark

npm i https://pkg.pr.new/@lexical/mark@9931

@lexical/markdown

npm i https://pkg.pr.new/@lexical/markdown@9931

@lexical/mdast

npm i https://pkg.pr.new/@lexical/mdast@9931

@lexical/offset

npm i https://pkg.pr.new/@lexical/offset@9931

@lexical/overflow

npm i https://pkg.pr.new/@lexical/overflow@9931

@lexical/plain-text

npm i https://pkg.pr.new/@lexical/plain-text@9931

@lexical/react

npm i https://pkg.pr.new/@lexical/react@9931

@lexical/rich-text

npm i https://pkg.pr.new/@lexical/rich-text@9931

@lexical/selection

npm i https://pkg.pr.new/@lexical/selection@9931

@lexical/table

npm i https://pkg.pr.new/@lexical/table@9931

@lexical/tailwind

npm i https://pkg.pr.new/@lexical/tailwind@9931

@lexical/text

npm i https://pkg.pr.new/@lexical/text@9931

@lexical/utils

npm i https://pkg.pr.new/@lexical/utils@9931

@lexical/y

npm i https://pkg.pr.new/@lexical/y@9931

@lexical/yjs

npm i https://pkg.pr.new/@lexical/yjs@9931

commit: d40296d

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks, this looks good. Marking yjs optional in @lexical/yjs's peerDependenciesMeta matches what @lexical/react already declares. Only @lexical/react/LexicalCollaborationPlugin loads @lexical/yjs at runtime, so apps without collaboration no longer have yjs forced on them, and apps that list yjs (as the collaboration guide's install line does) still resolve that same copy. The new audit in scripts/__tests__/unit/build.test.ts fails on main with @lexical/yjs requires yjs and passes on this branch. The changeset follows .changeset/README.md: a patch, a [fix] summary and a Verify: paragraph.

One optional, non-blocking suggestion, which could go in a separate PR:

  • CONSUMER_MANIFEST_FIELDS in scripts/changesets/coverage.mjs lists peerDependencies but not peerDependenciesMeta, so the Changesets job would not have asked for this entry. Adding 'peerDependenciesMeta' there would make any later change to an optional peer require a changeset, in line with .changeset/README.md's rule that a change to the consumer-facing fields of a published package's package.json needs one.

Automated review (maintainer link)

This branch was successfully deployed

2 active deployments
Preview – lexical — d40296d4 Deployed Nov 17, 2026 by vercel[bot]
Preview – lexical-playground — d40296d4 Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant