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]: Jest unit test fails for useEditor() #5108

Closed
1 of 2 tasks
ClaudiuGS opened this issue May 1, 2024 · 4 comments
Closed
1 of 2 tasks

[Bug]: Jest unit test fails for useEditor() #5108

ClaudiuGS opened this issue May 1, 2024 · 4 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

@ClaudiuGS
Copy link

Which packages did you experience the bug in?

"@tiptap/core": "^2.3.0",     "@tiptap/extension-bold": "^2.3.0,  "react": "^18.2.0",",     "@tiptap/extension-document": "^2.3.0",     "@tiptap/extension-hard-break": "^2.3.0",     "@tiptap/extension-history": "^2.3.0",     "@tiptap/extension-paragraph": "^2.3.0",     "@tiptap/extension-strike": "^2.3.0",     "@tiptap/extension-text": "^2.3.0",     "@tiptap/pm": "^2.3.0",     "@tiptap/react": "^2.3.0",

What Tiptap version are you using?

2.3.0

What’s the bug you are facing?

I've upgraded TipTap from 2.1.13 to 2.3.0 and now my unit tests are failing. After inspection, it seems that useEditor always returns null.

I've tried commenting out all my custom code and using a very basic example of Editor but useEditor still returns null.

What browser are you using?

Chrome

Code example

No response

What did you expect to happen?

Expected my unit tests not to fail as in previous version.

Anything to add? (optional)

No response

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. 💖
@ClaudiuGS ClaudiuGS 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 May 1, 2024
@github-project-automation github-project-automation bot moved this to Triage open in Tiptap May 1, 2024
@nnuzaba
Copy link

nnuzaba commented Jul 12, 2024

I am also seeing this issue.

Pretty sure it was due to this change in 2.3.1: #4856

Specifically removal of this line

Before that the setEditor was updating state and causing a rerender, and then returning a not null editor.

(I tried copy pasting the old version of the code with the setEditor and my tests start working again)

@svenadlung if you could explain why this is not an issue in the production code, it would help us understand what we need to emulate in our tests.

@nperez0111
Copy link

SSR is the reason behind this. Without a document the editor can fail since it is expected to run within the browser. With the new react binding and immediatelyRender: true you can control this behavior in tiptap 2.5

But do note that any bugs that happen on the server are not going to be prioritized as the editor is not meant to be ran there and could have incompatibilities

@github-project-automation github-project-automation bot moved this from Triage open to Done in Tiptap Jul 23, 2024
@nnuzaba
Copy link

nnuzaba commented Jul 23, 2024

Sorry confused, but our tests were running with jest-dom, so wouldn't that mean it did have a "browser", and was not doing SSR? (our team can't upgrade React so we can't use the new stuff 😅 )

@nperez0111
Copy link

My comment around SSR was the reason why we changed useEditor to return null on first render & then an actual editor instance afterward (via a useEffect which would not be called in SSR).

jest-dom emulates a browser, but is not an actual instance, I'm unsure if it can even declare a global document instance or not, in any case tiptap is not really meant to be running in a node instance.

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
Archived in project
Development

No branches or pull requests

3 participants