Skip to content
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

[lexical-react] Bug Fix: LexicalTypeaheadMenuPlugin SSR error: ReferenceError: document is not defined #6794

Merged
merged 7 commits into from
Nov 5, 2024

Conversation

bedre7
Copy link
Contributor

@bedre7 bedre7 commented Nov 5, 2024

Description

Used CAN_USE_DOM to check if the DOM can be used when accessing the document object in the useMenuAnchorRef hook. This prevents runtime errors when the hook is used by a plugin in SSR.

Closes #6716

Test plan

Unit test has been added for useMenuAnchorRef.

Copy link

vercel bot commented Nov 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 5, 2024 4:44pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 5, 2024 4:44pm

@facebook-github-bot facebook-github-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 Nov 5, 2024
Copy link

github-actions bot commented Nov 5, 2024

size-limit report 📦

Path Size
lexical - cjs 29.92 KB (0%)
lexical - esm 29.78 KB (0%)
@lexical/rich-text - cjs 38.57 KB (0%)
@lexical/rich-text - esm 31.63 KB (0%)
@lexical/plain-text - cjs 37.22 KB (0%)
@lexical/plain-text - esm 28.94 KB (0%)
@lexical/react - cjs 40.31 KB (0%)
@lexical/react - esm 33.04 KB (0%)

Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

I think that the LexicalMenu anchorElementRef type should change to match the new expectations rather than using a cast. It's a mutable object, the contents can change from not-null to null at any time (at least per the type contract)

packages/lexical-react/src/shared/LexicalMenu.ts Outdated Show resolved Hide resolved
packages/lexical-react/src/shared/LexicalMenu.ts Outdated Show resolved Hide resolved
packages/lexical-react/src/LexicalTypeaheadMenuPlugin.tsx Outdated Show resolved Hide resolved
packages/lexical-react/src/LexicalNodeMenuPlugin.tsx Outdated Show resolved Hide resolved
packages/lexical-react/src/LexicalContextMenuPlugin.tsx Outdated Show resolved Hide resolved
etrepum
etrepum previously approved these changes Nov 5, 2024
Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

I think this is good to go, I will apply the small suggested nit and assuming the e2e test suite looks good then it will be merged. Thank you!

packages/lexical-react/src/shared/LexicalMenu.ts Outdated Show resolved Hide resolved
Merged via the queue into facebook:main with commit f5ae852 Nov 5, 2024
67 of 69 checks passed
@etrepum etrepum mentioned this pull request Nov 7, 2024
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. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: LexicalTypeaheadMenuPlugin SSR error: ReferenceError: document is not defined
3 participants