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]: Editor is not actually read when onCreate is called #5237

Closed
1 task done
Nantris opened this issue Jun 16, 2024 · 1 comment
Closed
1 task done

[Bug]: Editor is not actually read when onCreate is called #5237

Nantris opened this issue Jun 16, 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

@Nantris
Copy link
Contributor

Nantris commented Jun 16, 2024

Affected Packages

react? or otherwise core

Version(s)

2.5.0-beta.3 and below

Bug Description

The editor cannot be focused when onCreate is called because the editor DOM element is not yet attached to the page's DOM.

This occurs even if you wait until an animation frame has passed. In CodeSandbox it seems that two animation frames are sufficient to access the editor's DOM on the page, but in my project that's not the case and instead it takes three, so it seems like there might be two components to this issue.

Browser Used

Chrome

Code Example URL

https://codesandbox.io/p/sandbox/dark-worker-tjp86f?file=%2Fsrc%2FApp.js%3A19%2C35

Expected Behavior

I'd suggest a ready event, which occurs after the create event that means the editor is fully ready. Short of that, I'd think that create means I can access the editor to do whatever I need, especially based on the description.

Additional Context (Optional)

The create event is described as "The editor is ready." That's arguably true because the headless editor is ready, but it's arguably not, because some real world uses aren't possible at that time.

Regarding the repro you have to click into the frame for the focus command to actually work, so I'd recommend:

  1. Click refresh
  2. Very quickly click into the frame
  3. The frame refreshed
  4. If the focus command worked, the editor will now have a caret shortly after refresh

Dependency Updates

  • Yes, I've updated all my dependencies.
@Nantris Nantris 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 Jun 16, 2024
@nperez0111
Copy link
Contributor

I'm pretty sure this is to do with the react integration, because the first render pass it is not actually attached to any dom element. I hope to fix this with #5161 but we are still reviewing it.

image

But a way around this is to use a useEffect like I've done here: https://codesandbox.io/p/sandbox/dark-worker-tjp86f?file=%2Fsrc%2FApp.js%3A19%2C35

screen shot since I don't trust that I've linked that properly:
image

But, in any case the autofocusing should work. But if you have the y-prosemirror extension we are seeing it not work, but it is a y-prosemirror issue not a tiptap one. See that thread here: #2840 (comment)

Hope this helps

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
Status: Done
Development

No branches or pull requests

2 participants