Fix single-character code blocks rendering as empty#18572
Merged
krassowski merged 3 commits intojupyterlab:mainfrom Feb 27, 2026
Merged
Fix single-character code blocks rendering as empty#18572krassowski merged 3 commits intojupyterlab:mainfrom
krassowski merged 3 commits intojupyterlab:mainfrom
Conversation
|
Thanks for making a pull request to jupyterlab! |
5 tasks
krassowski
reviewed
Feb 27, 2026
Member
krassowski
left a comment
There was a problem hiding this comment.
Great, thank you for investigating it! Can you also add a test case that would fail before and pass after this change in:
jupyterlab/packages/codemirror/test/language.spec.ts
Lines 48 to 66 in 92c8993
Contributor
Author
@krassowski sure |
meeseeksmachine
pushed a commit
to meeseeksmachine/jupyterlab
that referenced
this pull request
Feb 27, 2026
Contributor
Author
Thank you @krassowski for reviewing and merging it—thrilled to be part of the project! 🚀 |
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.
References
This PR fixes a bug in JupyterLab’s highlighting helper (
/packages/codemirror/src/language.ts) where single-character code blocks like x rendered as empty blocks.Root cause:
The helper used
tree.length - 1(number of syntax tree nodes) instead ofcode.length(actual string length) and did not handle the case wherehighlightTreeemits no tokens. As a result, unrecognized single-character identifiers could be dropped even though the input code string was valid.This PR:
code.lengthto compute the remaining text instead oftree.length.<code>blocks) and required HTML post-processing. This PR replaces that with a root-cause fix in language.ts.Code changes
BEFORE (Buggy Code):
File: packages/codemirror/src/language.ts (lines 250-253)AFTER (Fixed Code):
Proofs
jupyterlab.mp4