Repository navigation
[lexical-y][lexical-website] Feature: Refuse to run against a Yjs other than the one @lexical/y supports #9607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7d3b658
[lexical-y][lexical-website] Feature: Refuse to run against a Yjs oth…
zurfyx cd5da79
[lexical-y] Feature: Check Yjs members by typed reads, not names or a…
zurfyx 59d3ab3
[lexical-y] Feature: Check each Yjs object before the probe changes i…
zurfyx 474c885
[lexical-y] Feature: Check Yjs collections across realms and every co…
zurfyx ec14689
[lexical-y][lexical-website] Feature: Probe Yjs in any realm and mini…
zurfyx 24f1471
[lexical-y][lexical-website] Chore: Merge main into the Yjs guard branch
zurfyx 0c23636
[lexical-y][lexical-website] Documentation Update: Record the Yjs gua…
zurfyx 7f1f9a2
[lexical-y][lexical-website] Chore: Merge main into the Yjs guard branch
zurfyx 906f6a3
[lexical-y][lexical-website] Feature: Keep the Yjs guard green on mai…
zurfyx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --- | ||
| '@lexical/y': patch | ||
| --- | ||
|
|
||
| [feature] Refuse a Yjs that lacks the internals `@lexical/y` uses, or a document from a second copy of Yjs, with a typed `YUnsupportedYjsError` before anything is written | ||
|
|
||
| `@lexical/y` supports exactly one `@y/y` version, its exact peer dependency, | ||
| now also exported as `SUPPORTED_YJS_VERSION`. The exact version is enforced | ||
| by that peer dependency: `@y/y` exposes no version at run time. Package | ||
| managers only warn about an unmet peer dependency (pnpm by default, npm | ||
| with `--legacy-peer-deps`), so an app could still run another `@y/y` and | ||
| misbehave without an error. `createYDoc`, `YBinding` (and so | ||
| `YCollabExtension`) and the headless helpers now check, once per app, that | ||
| the `@y/y` they loaded provides the exports, fields and events the binding | ||
| uses, and that the document comes from that same copy. Otherwise they throw a | ||
| `YUnsupportedYjsError` (`code: UNSUPPORTED_YJS_ERROR`) with | ||
| `data: {supported, found, reason}`, where `reason` is `'changed-internals'` | ||
| or `'other-copy'`. A `@y/y` older than `14.0.0-rc.25` fails earlier, at | ||
| build or load, with a missing `Node` export; `rc.25` to `rc.28` provide | ||
| everything the binding uses and pass the check, so pin the named version. | ||
|
|
||
| Verify: with `@y/y@14.0.0-rc.29` installed once (`npm ls @y/y`), nothing | ||
| changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/lexical-y/flow/__flowtests__/unsupportedYjs.js.flow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /** | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| * | ||
| * @flow strict | ||
| */ | ||
|
|
||
| // Checked by `pnpm run flow` (not shipped): YUnsupportedYjsError's data is | ||
| // typed, and its reasons are exhaustive. | ||
|
|
||
| import type {YUnsupportedYjsData} from '@lexical/y'; | ||
|
|
||
| import { | ||
| SUPPORTED_YJS_VERSION, | ||
| UNSUPPORTED_YJS_ERROR, | ||
| YUnsupportedYjsError, | ||
| } from '@lexical/y'; | ||
| import {YUnsupportedYjsError as HeadlessYUnsupportedYjsError} from '@lexical/y/headless'; | ||
|
|
||
| // The headless entry re-exports the same class. | ||
| const SameClass: typeof YUnsupportedYjsError = HeadlessYUnsupportedYjsError; | ||
| void SameClass; | ||
|
|
||
| function fixFor(error: unknown): string | null { | ||
| if (!(error instanceof YUnsupportedYjsError)) { | ||
| return null; | ||
| } | ||
| const code: '@lexical/y/unsupported-yjs' = error.code; | ||
| const data: YUnsupportedYjsData = error.data; | ||
| switch (data.reason) { | ||
| case 'changed-internals': | ||
| return `install @y/y@${data.supported} (found: ${data.found.join(', ')}; ${code})`; | ||
| case 'other-copy': | ||
| return `dedupe @y/y@${data.supported}`; | ||
| default: | ||
| data.reason as empty; | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| const supported: string = SUPPORTED_YJS_VERSION; | ||
| const errorCode: '@lexical/y/unsupported-yjs' = UNSUPPORTED_YJS_ERROR; | ||
| fixFor( | ||
| new YUnsupportedYjsError({ | ||
| found: ['Item#parentSub'], | ||
| reason: 'changed-internals', | ||
| supported, | ||
| }), | ||
| ); | ||
| // $FlowExpectedError[incompatible-type] the reasons are a closed set | ||
| new YUnsupportedYjsError({found: [], reason: 'newer', supported}); | ||
| void errorCode; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional:
packages/lexical-playground/package.jsonpins@y/yon its own, and no workspace override ties it to this package, so this step could name it too. Otherwise a bump leaves the playground on the old version, and its document (fromcreateYDoc) and@y/websocketresolve different copies of Yjs, the case D79 says the guard cannot see.