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]: how to defined async commands #5763

Closed
1 task done
dingshaohua-com opened this issue Oct 24, 2024 · 1 comment
Closed
1 task done

[Bug]: how to defined async commands #5763

dingshaohua-com opened this issue Oct 24, 2024 · 1 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

Comments

@dingshaohua-com
Copy link

Affected Packages

core

Version(s)

2.8.0

Bug Description

this dispatch is not execute,why?
how to defined async commands?
dcdc9be54e27c0a261262f121140b251

Browser Used

Chrome

Code Example URL

No response

Expected Behavior

nomal

Additional Context (Optional)

No response

Dependency Updates

  • Yes, I've updated all my dependencies.
@dingshaohua-com dingshaohua-com 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 Oct 24, 2024
@nperez0111
Copy link
Contributor

Please don't cross-post. You asked this in Github issues, discussions and Discord.

So the issue here is that you're trying to dispatch in a Promise and Tiptap's chain runs synchronously, therefore your dispatch is not executed.

The solution would be to do something like this:

addCommands() {
  return {
    uploadImg: () => (arg) => {
      openFileWindow().then(async (imgFile) => {
        ...
        editor.chain().insertContentAt(0, paragraphNode).run();
      })
    }
  }
}

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
None yet
Development

No branches or pull requests

2 participants