Conversation
The token cache key was the language, the code length and the first and last 100 characters, so two blocks with the same length and ends shared one entry and the second block showed the first block's code. The key already held the length, so every distinct code string is already its own entry; using the full code only makes the key exact.
createHighlighter rejects a language that is not in the shiki bundle, so the "text" fallback in highlightCode never ran: the rejected promise was cached for that language, and every block in it stayed unhighlighted and logged "Failed to highlight code". The language is now resolved to "text" before the highlighter is created.
Contributor
|
@HardMax71 is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
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.
Two fixes in the same cache code, one commit each:
language:code. The old key already held the code length, so each streamed version of a growing block was already its own entry and the entry count does not change; the full string is small next to the tokens stored under it. The unbounded growth fix(elements): bound code block token cache with LRU eviction #454 addresses is untouched.getHighlighterresolves a language that is neither inbundledLanguagesnor special (text,plaintext, ...) to"text"before callingcreateHighlighter, so the existing"text"fallback inhighlightCodeapplies and no rejected promise is cached.Two new tests in
__tests__/code-block.test.tsx, "does not show the tokens of other code with the same length and ends" and "highlights a language shiki does not bundle as plain text", fail on main and pass here; each also fails with only the other commit applied. The full@repo/elementssuite passes (960 tests).Closes #503