Skip to content

fix(core): use the default language for a code block typed without one - #3024

Open
adarshsm wants to merge 1 commit into
TypeCellOS:mainfrom
adarshsm:fix/3005-empty-code-block-language
Open

fix(core): use the default language for a code block typed without one#3024
adarshsm wants to merge 1 commit into
TypeCellOS:mainfrom
adarshsm:fix/3005-empty-code-block-language

Conversation

@adarshsm

@adarshsm adarshsm commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #3005.

Typing ``` with no language suffix stored an empty string as the code block's
language. The input rule fell back to the raw match when there was nothing to resolve:

const languageName = match[1].trim();          // "" for a bare ```
const attributes = {
  language: getLanguageId(options, languageName) ?? languageName,   // -> ""
};

createLanguageSelect then threw Language is not supported. — the double space in the
message 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 is
given, 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 + Enter equivalent
both asserted language === "". They now assert the default, and they are the regression
tests — both fail on main with expected '' to be 'text'.

One case I deliberately did not change

An unrecognised language still passes through as-is: ```notalanguage produces
language: "notalanguage", which createLanguageSelect will also reject. I left that
alone because it is a different call from the empty case — there the user typed a name and
silently replacing it with text would discard what they asked for, and a custom
highlighter 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

packages/core: pnpm vp test --run src/blocks/Code/block.test.ts   # 19 passed
packages/core: pnpm vp test --run                                 # 759 passed, 9 skipped

pnpm vp run lint reports 49 errors both with and without this change — all
Cannot find module '@blocknote/…' from unbuilt workspace packages, none in the files
touched here.

Summary by CodeRabbit

  • Bug Fixes
    • Code blocks created without a language now consistently default to text.
    • Unrecognized language suffixes fall back to the configured default language instead of producing an empty language value.

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.
@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown

@adarshsm is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 355c9a8f-6475-4b27-976f-c5a5b8454f00

📥 Commits

Reviewing files that changed from the base of the PR and between 19b9b19 and c28f9e0.

📒 Files selected for processing (2)
  • packages/core/src/blocks/Code/block.test.ts
  • packages/core/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The code-block input rule now resolves language suffixes and assigns the configured default language, or "text", when the suffix is missing or unsupported. Tests update bare triple-backtick conversions triggered by space and Enter.

Changes

Code block language handling

Layer / File(s) Summary
Resolve code block language
packages/core/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts, packages/core/src/blocks/Code/block.test.ts
The input rule resolves language suffixes through getLanguageId and falls back to the configured default or "text". Tests cover space- and Enter-triggered bare triple-backtick conversions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to c28f9

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: nperez0111

Poem

A rabbit tapped three ticks in line
The block chose “text” and felt just fine
No empty tongue could cause a fright
Enter hopped through, then all was right
The cursor danced beneath moonlight

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: using the default language for code blocks created without a language suffix.
Description check ✅ Passed 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 despit…
Linked Issues check ✅ Passed The implementation addresses issue #3005 by assigning the configured default language for bare triple-backtick input. This prevents the empty-language error and its resulting block initialization and …
Out of Scope Changes check ✅ Passed The changes are limited to the code-block input rule and its regression tests. They directly support issue #3005 and do not introduce unrelated code changes.
Docstring Coverage ✅ Passed 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…
Full details: Description check

Explanation

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 check

Explanation

The implementation addresses issue #3005 by assigning the configured default language for bare triple-backtick input. This prevents the empty-language error and its resulting block initialization and cursor behavior problems. Tests cover both space and Enter conversion paths.

Full details: Docstring Coverage

Explanation

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 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/@blocknote/ariakit@3024

@blocknote/code-block

npm i https://pkg.pr.new/@blocknote/code-block@3024

@blocknote/core

npm i https://pkg.pr.new/@blocknote/core@3024

@blocknote/diagram-block

npm i https://pkg.pr.new/@blocknote/diagram-block@3024

@blocknote/mantine

npm i https://pkg.pr.new/@blocknote/mantine@3024

@blocknote/math-block

npm i https://pkg.pr.new/@blocknote/math-block@3024

@blocknote/react

npm i https://pkg.pr.new/@blocknote/react@3024

@blocknote/server-util

npm i https://pkg.pr.new/@blocknote/server-util@3024

@blocknote/shadcn

npm i https://pkg.pr.new/@blocknote/shadcn@3024

@blocknote/xl-ai

npm i https://pkg.pr.new/@blocknote/xl-ai@3024

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/@blocknote/xl-docx-exporter@3024

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/@blocknote/xl-email-exporter@3024

@blocknote/xl-multi-column

npm i https://pkg.pr.new/@blocknote/xl-multi-column@3024

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/@blocknote/xl-odt-exporter@3024

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/@blocknote/xl-pdf-exporter@3024

commit: c28f9e0

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 this pull request may close these issues.

Typing ``` then Enter throws "Language is not supported" and corrupts cursor/deletion

1 participant