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

Token transitions color transition errors #457

Closed
jyecusch opened this issue Sep 18, 2024 · 5 comments · Fixed by #463
Closed

Token transitions color transition errors #457

jyecusch opened this issue Sep 18, 2024 · 5 comments · Fixed by #463

Comments

@jyecusch
Copy link

Hey, first this library is incredible.

I've noticed some odd behavior with colors when using token transitions, where the tokens end up the wrong color.

Here is an example recorded on the Scrollycoding page on the docs:

transitions-color-error.mp4

This is in Chrome, but the same occurs in Firefox and Safari.

I can see something similar on the Token Transitions page, where the opening parenthesis in if (n == 0) turns blue when switching from scala to python and back to scala.

Token_Transitions___Code_Hike

The strange thing is that if you inspect those elements, they have the correct color set on their inline style.

@tatasadi
Copy link

tatasadi commented Sep 24, 2024

I can confirm this issue. I'm noticing many incorrect colors in various places. Here are one example:

grafik

actually it should have these colors:

grafik

@tjholm
Copy link

tjholm commented Sep 27, 2024

Have found changing the fill of the transitions from both to backwards seems to solve the color issue, at least for me. Still need to do more testing.

see componentDidUpdate() of SmoothPre:
https://codehike.org/docs/code/token-transitions

@pomber
Copy link
Contributor

pomber commented Oct 2, 2024

I think it's a problem with React reusing the elements for different tokens (and keeping the transition state). For example, forcing React to re-create all elements should fix it:

export const tokenTransitions: AnnotationHandler = {
  name: "token-transitions",
  PreWithRef,
  Token: (props) => (
    <InnerToken
      merge={props}
      style={{ display: "inline-block" }}
      key={Math.random()} // HACK 
    />
  ),
}

I'll try to find a good solution, ideally making React reset any token transition before calculating the new colors.

Copy link
Contributor

github-actions bot commented Oct 2, 2024

This issue has been fixed but not yet released.

Try it in your project before the release with:

npm i https://pkg.pr.new/codehike@463

Or wait for the next release.

Copy link
Contributor

github-actions bot commented Oct 3, 2024

🚀 Released in [email protected] 🚀

If this was helpful, consider sponsoring Code Hike. Your contribution helps sustain open-source work.

Thanks for using Code Hike!

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 a pull request may close this issue.

4 participants