fix(LetterGlitch): smooth colour transitions freeze after one frame - #1070
Open
FelipeKreulich wants to merge 1 commit into
Open
fix(LetterGlitch): smooth colour transitions freeze after one frame#1070FelipeKreulich wants to merge 1 commit into
FelipeKreulich wants to merge 1 commit into
Conversation
handleSmoothTransitions parsed letter.color with hexToRgb, but that same field had already been overwritten with interpolateColor's `rgb(r, g, b)` output on the previous frame. hexToRgb matches hex only, returned null, and the guarded branch never ran again: colorProgress kept climbing to 1 while the colour stayed ~5% of the way to its target, and needsRedraw stayed false. In practice `smooth` had almost no effect. Interpolation now happens in numbers and the CSS string is built only at paint time, so the parser is never handed its own output. Each letter keeps rgb (what is painted), fromRgb and targetRgb (the endpoints), which also means a letter picked again mid-fade continues from the colour currently on screen instead of jumping. An unparseable entry in glitchColors previously left fillStyle invalid and the fade frozen; it now falls back to white, which is visible rather than silent. Applied to all four variants, and the registry output regenerated with `npm run registry:build`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1069.
smoothwas effectively doing nothing. The fade started and then stopped on the very next frame, leaving each letter about 5% of the way to its target colour until the next glitch tick swapped it out.What was happening
handleSmoothTransitionsread the fade's starting point fromletter.color:but the line just below it overwrites that same field with
interpolateColor(...), which returnsrgb(r, g, b). From the second frame onwardshexToRgbwas being handed its own formatted output, matched neither regex, and returnednull— so the guarded branch never ran again.colorProgressstill climbed to 1 andneedsRedrawstayedfalse.It's easy to miss because the canvas keeps animating regardless:
updateLetters()swaps characters everyglitchSpeedms and callsdrawLetters()on its own. Only the colour fade was missing.What I changed
Interpolation now happens in numbers, and the CSS string is built only where it's used, at
ctx.fillStyle. The parser is never handed its own output, so the failure can't come back.Each letter now carries:
rgb— what is currently paintedfromRgb/targetRgb— the two endpoints of the fadeinterpolateColorbecamemixRgb(returns{r, g, b}) plusrgbToCss.Two things fall out of this that I think are improvements, but say the word if you'd rather I drop them:
updateLetterssetsfromRgbto the letter's currentrgb.glitchColorsno longer stalls the animation. Previously it produced an invalidfillStyleand a frozen fade; now it falls back to white, which is visible rather than silent. I hit this by accident while testing — the docs page's?colors=URL param splits the value incorrectly and passes#,f,fto the component. That looks like a separate demo-side bug, unrelated to this PR; happy to open an issue for it if it's news to you.All four variants
content,tailwind,ts-defaultandts-tailwindall carry the identical change. I checked first that they only differ in their styling layer, so the animation logic stays byte-identical across them. The fourpublic/r/LetterGlitch-*.jsonfiles were regenerated withnpm run registry:buildrather than hand-edited.npm run registry:buildalso rewrotepublic/r/DecryptedText-{JS,TS}-CSS.json, which looked like pre-existing drift between that component's source and its registry output. I left those out of this PR since they're unrelated.Testing
Locally, in the docs app, sampling one letter cell over 90 frames and measuring the distance between consecutive colours:
smoothonsmoothoffBefore the fix these two columns were near-identical, which is the bug. Now
smoothon walks through intermediate tones, andsmoothoff jumps straight between palette colours — which is what each mode should do.Repeated at a 360×640 container to cover the mobile resize path, since
resizeCanvas→initializeLettersis where the new per-letter state is built from scratch: 43 distinct colours, 42 gradual steps, 0 hard jumps. Browser console is clean — no errors, and no new warnings (the only ones present are the pre-existing React Router v7 future-flag notices).Type checking: both
.tsxvariants passtsc --noEmit --strict.Lint:
npx eslinton the two.jsxvariants reports nothing, before and after the change. (Repo-widenpm run lintreports 44 pre-existing problems in other components, none in these files.)There's also a dependency-free Node reproduction of the original bug in #1069 if it's useful for confirming the diagnosis.