[lexical-react] Bug Fix: Add getServerSnapshot for RSC compatibility#7935
Conversation
This adds the missing getServerSnapshot argument to the useSyncExternalStore call, resolving hydration warnings in RSC environments. Fixes facebook#7934
|
Hi @nestarz! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
💡 Enable Vercel Agent with $100 free credit for automated AI reviews |
|
The PR title and description should be changed to match the pull request template and you'll need to accept the CLA but other than that this looks like it will be good to merge for the next release. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Description
Current behavior: When using Lexical in a React Server Components (RSC) environment (e.g., Next.js App Router), a console warning appears:
useSyncExternalStore missing getServerSnapshot, which is required for server-rendered content. This is caused by theuseSyncExternalStorehook inuseReactDecorators.tsxbeing called without the required third argument.Changes in this PR: This PR passes the existing
getSnapshotfunction as the third argument (getServerSnapshot) to theuseSyncExternalStorehook. This satisfies the hook's API for server rendering, resolves the warning, and ensures correct hydration in RSC environments.Closes #7934
Test plan
The test plan follows the reproduction steps outlined in the issue.
Before
The following warning is visible in the console, and there may be hydration mismatch errors.
useSyncExternalStore missing getServerSnapshot, which is required for server-rendered contentAfter
The
useSyncExternalStorewarning is no longer present in the console, and the editor component hydrates correctly without errors.