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: prevent duplicated characters in typing animation. #143

Merged

Conversation

joacoc
Copy link
Contributor

@joacoc joacoc commented Jun 11, 2024

Changed the <TypingAnimation /> component logic to avoid duplicated characters by updating it to use text.substring(..) instead of concatenating with prevState + text.charAt(i).

Context

Using small durations, e.g., <TypingAnimation duration={5} />, can duplicate characters. This does not always happen, but when switching tabs or when the application is in the background, it is more prone to happen.

Changed setDisplayedText logic to avoid duplicated characters by updating it to use text.substring(..) instead of concatenating with prevState and text.charAt(i).
Copy link

vercel bot commented Jun 11, 2024

@joacoc is attempting to deploy a commit to the product-studio Team on Vercel.

A member of the Team first needs to authorize it.

@dillionverma
Copy link
Collaborator

wasn't able to replicate the issue - do you have a video or something?

what exactly happened?

@joacoc
Copy link
Contributor Author

joacoc commented Jun 16, 2024

It took me a bit to find a proper way to replicate it easily: recording timelines in Safari, or adding a compute-intensive component next to < TypingAnimation ... />, makes the issue more prone to appear unless you have a powerful machine.

In the second 17, it is visible that the typing animation duplicates characters. Why this happens, I'm not 100% sure.

Browser: Safari (Version 17.4)
Device: MacBook Air (M1)

Test.mp4

Copy link

vercel bot commented Jul 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
magicui ❌ Failed (Inspect) Jul 1, 2024 10:11am

Copy link
Collaborator

@dillionverma dillionverma left a comment

Choose a reason for hiding this comment

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

fascinating!

thanks for video and fix :) this is super helpful

@dillionverma dillionverma merged commit c1a92fe into magicuidesign:main Jul 1, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants