fix(core): use the default language for a code block typed without one - #3024
fix(core): use the default language for a code block typed without one#3024adarshsm wants to merge 1 commit into
Conversation
Typing ``` with no language suffix stored an empty string as the block's language: the input rule fell back to the raw match when getLanguageId found nothing to resolve. createLanguageSelect then threw "Language is not supported." because "" is not in supportedLanguages, and the block was left half-initialised, which is what broke the cursor and made Backspace and Delete misbehave inside it. Fall back to the configured defaultLanguage instead, so the block is created with a language a highlighter can actually render. The two tests that asserted the empty language encoded this behaviour and now assert the default.
|
@adarshsm is attempting to deploy a commit to the TypeCell Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe code-block input rule now resolves language suffixes and assigns the configured default language, or ChangesCode block language handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Bare code blocks now use the configured default language instead of an empty value, preventing the initialization failure and related editing problems. No actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Description checkExplanation The description explains the defect, root cause, fix, intended behavior for unrecognized languages, regression tests, full-suite results, and known lint limitations. It is complete in substance despite not reproducing every template heading. Full details: Linked Issues checkExplanation The implementation addresses issue Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. ✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/diagram-block
@blocknote/mantine
@blocknote/math-block
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
commit: |
Fixes #3005.
Typing
```with no language suffix stored an empty string as the code block'slanguage. The input rule fell back to the raw match when there was nothing to resolve:
createLanguageSelectthen threwLanguage is not supported.— the double space in themessage is the empty language — and because it threw partway through creating the block,
the block was left half-initialised, which is what produced the misplaced cursor and the
broken Backspace/Delete the reporter saw afterwards.
The fix falls back to the configured
defaultLanguage("text") when no language isgiven, so the block is created with something a highlighter can actually render.
Two existing tests encoded the bug
"converts ``` + space into a codeBlock with empty language"and the+ Enterequivalentboth asserted
language === "". They now assert the default, and they are the regressiontests — both fail on
mainwithexpected '' to be 'text'.One case I deliberately did not change
An unrecognised language still passes through as-is:
```notalanguageproduceslanguage: "notalanguage", whichcreateLanguageSelectwill also reject. I left thatalone because it is a different call from the empty case — there the user typed a name and
silently replacing it with
textwould discard what they asked for, and a customhighlighter registered later could legitimately support it. Happy to handle it here, or in
its own issue, if you would rather it fall back too.
Testing
pnpm vp run lintreports 49 errors both with and without this change — allCannot find module '@blocknote/…'from unbuilt workspace packages, none in the filestouched here.
Summary by CodeRabbit
text.