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

How to handle flicker on mount #2040

Closed
2 tasks done
kylesuss opened this issue Oct 14, 2021 · 15 comments
Closed
2 tasks done

How to handle flicker on mount #2040

kylesuss opened this issue Oct 14, 2021 · 15 comments
Assignees
Labels
Type: Bug The issue or pullrequest is related to a bug

Comments

@kylesuss
Copy link

kylesuss commented Oct 14, 2021

What’s the bug you are facing?

Hi! We are working to integrate TipTap into our app & are pretty early in the process. Thanks for the hard work on the lib.

When first rendering the editor, we notice that there is a period of time where nothing is rendered. Taking the CodeSandbox (also linked below), I can toggle the editor & see that when the editor is meant to be shown, the first render cycle is empty.

Is this expected? Can it be fixed?

Before toggle

data_image_jpg;base… (1)

After toggle

data_image_jpg;base… (2)

Editor now visible ("test")

data_image_jpg;base… (3)

How can we reproduce the bug on our side?

I was using the Chrome devtools Performance tab to record the behavior and capture screenshots.

Can you provide a CodeSandbox?

https://codesandbox.io/s/brave-thunder-7h41n?file=/src/App.js

What did you expect to happen?

I would expect there to be a way to avoid this flicker situation & have the editor visible on mount, but perhaps I am missing something in my setup?

Anything to add? (optional)

I am using the React lib & useEditor.

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. 💖
@kylesuss kylesuss added the Type: Bug The issue or pullrequest is related to a bug label Oct 14, 2021
@Miloshinjo
Copy link

Having the same issue in React with useEditor. Editor shows empty before showing text, causing the screen flicker.

@philippkuehn
Copy link
Contributor

I had to revert the last change. If you want to prevent that flicker you can use a custom useEditor hook.

@ospfranco
Copy link

ospfranco commented Jan 18, 2022

Screen Recording 2022-01-18 at 19 46 49

I'm seeing crazy amounts of flicker in my next.js app, even though I used the custom useEditor hook, any idea who to mitigate this issue? it happens every time I change any of the props

@ospfranco
Copy link

just realized it not only flickers but actually completely resets itself, when I type the cursor moves back to the first position

@hanspagel
Copy link
Contributor

hanspagel commented Jan 18, 2022

I can’t read the code on the screenshot, so without that it’s hard to say. :)

@ospfranco
Copy link

Trying to debug several issues right now, my entire code is here:

#2403

whenever adding a dependency to the useEditor hook the entire instance is destroyed which is not what I want

@Miloshinjo
Copy link

Has anyone found at least a workaround for this issue?

@ospfranco
Copy link

ospfranco commented Feb 2, 2022

Only load the instance once, then you have to use internal methods to reset the content and any handlers you have passed, here you can see some code on how to reset the handlers:

#2403

For the content there are other calls like editor.commands.setContent

That is the only way you will avoid flickers, trying to change them via the hook results in the internal editor instance being completely destroyed and re-mounted, so no way to use that without having flickers

@Miloshinjo
Copy link

Miloshinjo commented Feb 2, 2022

Only load the instance once, then you have to use internal methods to reset the content and any handlers you have passed, here you can see some code on how to reset the handlers:

#2403

For the content there are other calls like editor.commands.setContent

That is the only way you will avoid flickers, trying to change them via the hook results in the internal editor instance being completely destroyed and re-mounted, so no way to use that without having flickers

How do you load the instance only once? p.s. Sorry if this is common knowledge, I'm new to this lib :)

@Miloshinjo
Copy link

Just want to say that I used a custom hook that Phillip suggested and UI flicker is gone now. Edited it a bit to suit my case, but essentially it worked.

Thanks!

@rfgamaral
Copy link
Contributor

Just want to say that I used a custom hook that Phillip suggested and UI flicker is gone now. Edited it a bit to suit my case, but essentially it worked.

@Miloshinjo Would you mind sharing your edited version and explain your changes? Maybe it can be useful to others :)

@Miloshinjo
Copy link

Just want to say that I used a custom hook that Phillip suggested and UI flicker is gone now. Edited it a bit to suit my case, but essentially it worked.

@Miloshinjo Would you mind sharing your edited version and explain your changes? Maybe it can be useful to others :)

hello, it's this gist https://gist.github.com/ryanto/4a431d822a98770c4ca7905d9b7b07da, but I just removed 2 calls to requestsAnimationFrame and in my case, flickers were gone.

Also the option I'm using on the editor is editable: false , not sure if it matters, but I wanted to give u the full picture.

@rfgamaral
Copy link
Contributor

@Miloshinjo Thank you 👍

andrewlu0 pushed a commit to trybaseplate/tiptap that referenced this issue Oct 20, 2023
@benkingcode
Copy link

This is driving me crazy, is there really no fix coming for this? I have a very simple use case, an editor with the Collaboration extension, and I cannot switch documents without a jarring flicker.

@Nantris
Copy link
Contributor

Nantris commented May 19, 2024

This issue seemingly should not be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

No branches or pull requests

9 participants