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

[Bug]: Keyboard Handlers have stale state in React #4433

Open
1 of 2 tasks
adamjerickson opened this issue Sep 8, 2023 · 0 comments
Open
1 of 2 tasks

[Bug]: Keyboard Handlers have stale state in React #4433

adamjerickson opened this issue Sep 8, 2023 · 0 comments
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug

Comments

@adamjerickson
Copy link

Which packages did you experience the bug in?

react

What Tiptap version are you using?

"@tiptap/core": "^2.0.0", "@tiptap/extension-mention": "^2.0.4", "@tiptap/extension-placeholder": "^2.0.4", "@tiptap/pm": "^2.0.4", "@tiptap/react": "^2.0.4", "@tiptap/starter-kit": "^2.0.4", "@tiptap/suggestion": "^2.0.4",

What’s the bug you are facing?

Similar to (and called out at the end of) Bug 2403, the React state is stale when using keyboard handlers.

See the codesandbox link for example.

I am trying to submit the content of the editor on press of the Enter key. This seems like a very common use case, but it's taken me a long time even to find the referenced bug and now create a sandbox to show that it also doesn't work properly.

Anyway, go to the sandbox, you'll see two examples, one that uses the editorProps.handleKeyDown and one that creates an extension and uses addKeyuboardShortcuts. In box examples, you'll see in the console that the key is pressed, but the content that is logged is stale.

Initially it will log blank/undefined. It is really hard to tell exactly when it does refresh, but if you edit enough, or change focus, or even edit the code, you'll eventually get it to log the placeholder content plus some of the things you typed.

What browser are you using?

Chrome

Code example

https://codesandbox.io/s/gracious-dirac-pwvvql?file=/src/App.tsx

What did you expect to happen?

When using TipTap with React, you should be able to add a keyboard shortcut that properly interacts with state so that you can submit the content of the editor on press of a key (Enter in this case).

Anything to add? (optional)

Here is a loom video: https://www.loom.com/share/909b8874d7464ba78858cc73d08617d2

Did you update your dependencies?

  • Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖
@adamjerickson adamjerickson added Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug labels Sep 8, 2023
@github-project-automation github-project-automation bot moved this to Triage open in Tiptap Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug
Projects
No open projects
Status: Triage open
Development

No branches or pull requests

3 participants