Repository navigation
[lexical-yjs] Bug Fix: Mark the yjs peer optional, as @lexical/react already does - #9931
xiezhenjia-meta wants to merge 1 commit into
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/y
@lexical/yjs
commit: |
There was a problem hiding this comment.
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_FIELDSinscripts/changesets/coverage.mjslistspeerDependenciesbut notpeerDependenciesMeta, 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'spackage.jsonneeds one.
Description
@lexical/reactdepends on@lexical/yjsunconditionally and marks its ownyjspeer optional, because only@lexical/react/LexicalCollaborationPluginloads
@lexical/yjsandyjsat runtime.@lexical/yjsdeclares the sameyjspeer without marking it optional, so the required peer comes backthrough the transitive edge: every app that uses
@lexical/reactwithoutcollaboration gets
yjsauto-installed by pnpm (autoInstallPeers: true) ora missing required
yjspeer (autoInstallPeers: false).This marks
yjsoptional in@lexical/yjs'speerDependenciesMeta. Itsrange is unchanged, so a
yjsthat is installed is still checked against it;code that loads
@lexical/yjsstill needsyjsinstalled, as before.Moving
@lexical/yjsto an optional peer of@lexical/reactinstead would bea 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.tschecksthat a peer a package marks optional is also optional in every monorepo
package in its dependency tree that declares it;
@lexical/react->@lexical/yjs->yjsis the only violation today.Changeset
Added
.changeset/yjs-optional-peer.md(@lexical/yjs: patch,[fix]).Test plan
Before
App depending on
@lexical/react@0.53.0only,autoInstallPeers: false:With
autoInstallPeers: true,yjsis in the lockfile.After
Same app with
@lexical/yjs0.53.0 repacked with thispeerDependenciesMeta:With
autoInstallPeers: true,yjsis no longer in the lockfile.pnpm run update-packagesleaves the manifest unchanged,pnpm install --frozen-lockfilepasses with no lockfile change, andpnpm run check-changesets, prettier, eslint andtsc -p tsconfig.scripts.json/
tsconfig.test.jsonpass.