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-playground] Bug Fix: Disable table hover actions in read-only mode #6706

Merged
merged 2 commits into from
Oct 22, 2024

Conversation

neysanfoo
Copy link
Contributor

Description

Currently, the table hover actions allows users to add new rows and columns by hovering over the edges of the table, even when the editor is in read-only mode. Specifically the problems are: hover buttons are visible, interactions with the buttons are allowed, and the event handlers are active all while in read-only mode.

Changes Introduced in this PR

  • The hover buttons for adding rows and columns are hidden when the editor is in read-only mode and users cannot trigger hover actions in read-only mode.
  • Disabled event listeners in read-only mode
  • The TableHoverActionsContainer component returns null when the editor is not editable

Before

tables_readonly_before.mov

After

tables_readonly_after.mov

Copy link

vercel bot commented Oct 6, 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 Oct 13, 2024 5:05pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 13, 2024 5:05pm

@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 Oct 6, 2024
Copy link

github-actions bot commented Oct 6, 2024

size-limit report 📦

Path Size
lexical - cjs 29.94 KB (0%)
lexical - esm 29.81 KB (0%)
@lexical/rich-text - cjs 38.54 KB (0%)
@lexical/rich-text - esm 31.61 KB (0%)
@lexical/plain-text - cjs 37.15 KB (0%)
@lexical/plain-text - esm 28.99 KB (0%)
@lexical/react - cjs 40.34 KB (0%)
@lexical/react - esm 33.08 KB (0%)

);
const isEditable = useLexicalEditable();

return isEditable
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for all the additional isEditable checks? Wouldn't the check here suffice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this check is sufficient to prevent rendering the plugin when the editor is not editable, but the additional checks help with defensive programming. For example, when switching from editing to read-only mode, the main check will eventually unmount the component, but there is a brief period before the re-render completes, during this time, the internal checks ensure that not table modifications can occur. Basically preventing race conditions. For example, in a collobrative environment if one person sets the document as read-only, and at the same time another person trys to add a column before the rerendering has occurred.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good explanation, thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the defensive programming is useful in this case, the resolved state of the document over the network should override whatever the local settings are for any specific client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah i guess i dont really understand how collaborative editors work, I have removed the isEditable checks.

@etrepum etrepum added this pull request to the merge queue Oct 22, 2024
Merged via the queue into facebook:main with commit 3055e54 Oct 22, 2024
45 of 46 checks passed
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.

4 participants