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

fix: initially set editor object only on non-ssr environments #4864

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bdbch
Copy link
Contributor

@bdbch bdbch commented Feb 7, 2024

Please describe your changes

This PR gets rid of the initial null render on non-ssr environments.

How did you accomplish your changes

We're doing a check on the window object to see if the current env is a browser environment.

Checklist

  • The changes are not breaking the editor
  • Added tests where possible
  • Followed the guidelines
  • Fixed linting issues

@bdbch bdbch self-assigned this Feb 7, 2024
Copy link

netlify bot commented Feb 7, 2024

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit 446fef2
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/65c38ffd148cfd00081e8b68
😎 Deploy Preview https://deploy-preview-4864--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -99,7 +101,9 @@ export const useEditor = (options: Partial<EditorOptions> = {}, deps: Dependency
useEffect(() => {
let isMounted = true

editorRef.current = new Editor(options)
if (!editorRef.current) {
Copy link
Contributor

@C-Hess C-Hess Feb 21, 2024

Choose a reason for hiding this comment

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

Please take a look at #4579 if you get the chance. That pull request uses memo instead of a ref and also eliminates the double initialization that also causes issues (build failure). Best not to create the editor instance in an effect, but a memo instead; that way it gets created first render and after any deps array changes. The above PR also fixes the memory leak with the existing ref-based hook. Not a big deal to me either way if you want to just merge this PR in and abandon/close mine, but I would definitely recommend using memo. I am curious though if the types will be updated in a breaking change later, for those that extend the hook using Typescript or have ESLint rules for unnecessary null checks.

Also heads up, this is also similar to this draft PR https://github.com/ueberdosis/tiptap/pull/4858/files by @svenadlung , which has the same issue of double editor initialization.

Copy link
Contributor

Choose a reason for hiding this comment

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

pls 🙏 @bdbch @svenadlung

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage open
Development

Successfully merging this pull request may close these issues.

None yet

3 participants