Skip to content

[lexical-react] Bug Fix: CollaborationPlugin recreates the provider when providerFactory changes - #8965

Closed
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:fix/collab-provider-factory-update
Closed

[lexical-react] Bug Fix: CollaborationPlugin recreates the provider when providerFactory changes#8965
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:fix/collab-provider-factory-update

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

CollaborationPlugin guards provider creation with an isProviderInitialized ref that is set on first run and never reset, so the effect's [id, providerFactory, yjsDocMap] dependencies never take effect — the provider is created exactly once for the lifetime of the component. Changing providerFactory afterwards does nothing, which makes it impossible to reconnect with refreshed connection parameters such as a rotated auth token.

The guard exists so that a StrictMode/remount re-run with unchanged inputs does not create a second provider. This replaces it with a ref that remembers the inputs the current provider was built from, and short-circuits only when all of them are identical. The effect stays idempotent for re-runs, but a genuine change now tears down the old provider and creates a new one.

The binding is intentionally left alone: it is keyed to the Yjs document, which the documented getDocFromMap factory pattern preserves across a provider re-create.

Adds a unit test that re-renders with a new factory and asserts the new provider is created and connected and the old one disconnected; it fails on main.

Fixes #7136

…hen providerFactory changes

CollaborationPlugin guarded provider creation with an `isProviderInitialized`
ref that was never reset, so the provider was created exactly once for the
lifetime of the component. Changing `providerFactory` (or `id`) afterwards had
no effect, which makes it impossible to reconnect with refreshed connection
parameters such as a rotated auth token.

Replace the boolean guard with a ref that remembers the inputs the current
provider was built from. The effect stays idempotent for StrictMode/remount
re-runs with unchanged inputs, but a genuine change now tears down the old
provider and creates a new one.
@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@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 Aug 8, 2026
@LeSingh1

Copy link
Copy Markdown
Contributor Author

Consolidated into #9051 with the other PRs that share this defect, per @etrepum's note on #9027 and @mayrang's on #9035. Same fix and same tests, one review.

@LeSingh1 LeSingh1 closed this Aug 10, 2026
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.

Bug: Collaboration Plugin does not update the provider when providerFactory is updated.

1 participant