Skip to content

[lexical-react] Breaking change: enforce use of collab context provider - #7818

Merged
etrepum merged 5 commits into
meta:mainfrom
james-atticus:enforce-collab-context
Sep 19, 2025
Merged

etrepum merged 5 commits into
meta:mainfrom
james-atticus:enforce-collab-context

Conversation

@james-atticus

@james-atticus james-atticus commented Sep 15, 2025 •

Copy link
Copy Markdown
Contributor

Description

Flagged by @etrepum in #7816, useCollaborationContext didn't enforce that a provider was used. Indeed, neither the playground nor any of the examples used a provider. This could lead to significant issues with collab if two editors with the same ID were used on the page.


useCollaborationContext now requires that a context provider is used

Users of the CollaborationPlugin or useCollaborationContext must wrap the top-level LexicalComposer with a LexicalCollaboration component. For example:

<LexicalCollaboration>
  <LexicalComposer initialConfig={initialConfig}>
    <RichTextPlugin ... />
    <CollaborationPlugin id="lexical-editor" ... />
  </LexicalComposer>
<LexicalCollaboration>

The collaboration context is shared for nested editors, so the provider must only be used on the top-level editor.

@vercel

vercel Bot commented Sep 15, 2025 •

Copy link
Copy Markdown

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

Project Deployment Preview Comments Updated (UTC)
lexical Ready Ready Preview Comment Sep 19, 2025 0:30am
lexical-playground Ready Ready Preview Comment Sep 19, 2025 0:30am

@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 Sep 15, 2025
@james-atticus
james-atticus marked this pull request as draft September 15, 2025 22:55
}
ErrorBoundary={LexicalErrorBoundary}
/>
<LexicalCollaboration>

@etrepum etrepum Sep 15, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this might really need to go around LexicalComposer because if any DecoratorNode needs the context it might not find it from here

Comment thread tsconfig.json Resolved
etrepum
etrepum previously approved these changes Sep 17, 2025

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks right to me but we could make the transition a bit easier if we choose to

Comment on lines +69 to +72
invariant(
collabContext != null,
'useCollaborationContext: no context provider found',
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We could possibly make this transition a little smoother by transitionally having a global context default that we use when the context is null and print a warning. There's devInvariant which compiles to an error in dev and warning in prod that would maybe be good for this. The warning or error could also have a reference to this PR or some brief instructions to wrap your composer with <LexicalCollaboration>

etrepum
etrepum previously approved these changes Sep 18, 2025
@etrepum

etrepum commented Sep 18, 2025

Copy link
Copy Markdown
Collaborator

Will approve again once the conflict from merging #7816 is resolved

@etrepum
etrepum added this pull request to the merge queue Sep 19, 2025
Merged via the queue into meta:main with commit 5142c71 Sep 19, 2025
This was referenced Sep 25, 2025

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — 06597236 Deployed Sep 19, 2025 by vercel[bot]
Preview – lexical — 06597236 Deployed Sep 19, 2025 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.

2 participants