Repository navigation
set up listener for provider doc reload after disconnection/reconnection - #1409
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). lexical – ./packages/lexical-website🔍 Inspect: https://vercel.com/fbopensource/lexical/euH5WCvsSRbToX6urriJG9skdDzF lexical-playground – ./packages/lexical-playground🔍 Inspect: https://vercel.com/fbopensource/lexical-playground/J4rrNsBsqii4EK2gZYPpF1Z17LkS [Deployment for e2cbcd4 failed] |
|
This shouldn’t need changes to the package-lock? |
|
yeah, I've removed the change to package-lock.json |
…ion (#1409) * set up listener for provider doc reload after disconnection/reconnection * fixing package-lock.json
… replaced ## Description meta#9051 makes `CollaborationPlugin` build a new `Provider` when `providerFactory`, `id` or `yjsDocMap` change. The `Binding` did not follow. It was guarded by an `isBindingInitialized` ref, and because React runs an effect's cleanup before every re-run, a change to any of that effect's dependencies destroyed the `Binding` and then took the early return -- leaving a destroyed `Binding` in state. That fires on the very case meta#9051 set out to fix: swapping `providerFactory` changes `provider`, which is one of those dependencies. Changing `id` was worse: the new document was created and the `Provider` swapped, but nothing was ever bound to it, so edits reached neither document. The two effects are now one. Provider, document and `Binding` are built together and set in a single commit, so the components below always see a consistent set -- staged across renders, `useProvider()` connects once for the new `Provider` and again for the new `Binding`. The guard survives, because `providerFactory` must not be called twice under StrictMode, but the inputs it compares now match the dependency list exactly, so there is no dependency that can tear the session down and then be skipped. `excludedProperties` and `rootName` are in neither list: they are read once when the `Binding` is built, exactly as before, so a caller passing a fresh object each render keeps its connection rather than churning it. No public API changes: `CollaborationPluginProps` is untouched, and `YjsCollaborationCursors` is module-private. The `doc` state is now write-only and kept solely for the legacy 'reload' callback (meta#1409); rebinding on reload is a pre-existing gap this does not close. ## Test plan ### Before The new test, against meta#9051 as submitted -- nothing is ever bound to the second document, so `root` does not exist on it: ``` $ npx vitest run --project unit \ packages/lexical-react/src/__tests__/unit/LexicalCollaborationPlugin.test.tsx × the binding follows the id onto the new document AssertionError: expected undefined to be defined Tests 1 failed | 2 passed (3) ``` Against `main` (before meta#9051), the id change is ignored outright: ``` × provider is replaced when providerFactory changes × the binding follows the id onto the new document AssertionError: expected "vi.fn()" to be called 1 times, but got 0 times Tests 2 failed | 1 passed (3) ``` ### After ``` $ npx vitest run --project unit \ packages/lexical-react/src/__tests__/unit/LexicalCollaborationPlugin.test.tsx Test Files 1 passed (1) Tests 3 passed (3) $ pnpm run test-unit Test Files 293 passed (293) Tests 5513 passed | 1 skipped (5514) $ pnpm run test-browser Test Files 21 passed (21) Tests 142 passed | 1 skipped (143) $ pnpm run ci-check No errors! ``` `provider is replaced when providerFactory changes` still asserts exactly one `connect()` on the replacement provider, which is what the single-commit update preserves. The collab E2E suite needs a websocket server and was not run here. Co-Authored-By: Claude Opus <[email protected]>
when provider disconnects / reconnects, it pulls latest server copy into a new yjs doc, which means our collab plugin will need to renew our bindings. Adding a new listener listening to 'reload' even from provider. Then recreate the binding from new doc, clear the root in editorState, finally reload latest updates.