Skip to content

fix(core): ignore keydown events whose key is undefined - #3311

Open
itisrmk wants to merge 1 commit into
TypeCellOS:mainfrom
itisrmk:fix/keydown-guard-undefined-event-key
Open

itisrmk wants to merge 1 commit into
TypeCellOS:mainfrom
itisrmk:fix/keydown-guard-undefined-event-key

Conversation

@itisrmk

@itisrmk itisrmk commented Nov 6, 2026 •

Copy link
Copy Markdown

Summary

Safari dispatches trusted keydown events (autofill, dictation, and similar) whose key is undefined. Three @blocknote/core handlers read event.key.length on those events and throw TypeError.

keyboardEventKey returns undefined when key is not a string. InlineContentBoundaryEdit, NodeSelectionKeyboard, and SourceBlockWithPreview no-op in that case, without preventing the event. Inserted text still arrives through beforeinput.

This does not overlap with #3299 (node-view / mobile editing).

Fixes #3302

Test plan

  • pnpm exec vp test --run src/extensions/InlineContentBoundaryEdit/undefinedEventKey.test.ts src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.test.ts
  • Safari: autofill or dictation in a normal document no longer throws from InlineContentBoundaryEdit

Summary by CodeRabbit

  • Bug Fixes
    • Improved keyboard handling when key information is unavailable, avoiding errors and allowing the event’s default behavior to continue.

Safari can dispatch trusted keydown events (autofill, dictation) with
event.key unset. The handlers that read event.key.length now no-op
instead of throwing.

Fixes TypeCellOS#3302

Co-authored-by: Rahul Kashyap <itisrmk@users.noreply.github.com>
@vercel

vercel Bot commented Nov 6, 2026

Copy link
Copy Markdown

@cursoragent 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 Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Three keyboard handlers now use a shared helper to check whether an event key is a string. When the key is unavailable, each handler returns without handling the event. Tests cover undefined-key events in three editor states.

Changes: Undefined Keyboard Key Handling

Layer / File(s) Summary
Key normalization
packages/core/src/util/keyboardEventKey.ts
Adds keyboardEventKey, which returns the event key when it is a string and otherwise returns undefined.
Handler guards and tests
packages/core/src/extensions/InlineContentBoundaryEdit/InlineContentBoundaryEdit.ts, packages/core/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts, packages/core/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts, packages/core/src/extensions/InlineContentBoundaryEdit/undefinedEventKey.test.ts
The three handlers use the normalized key and return when it is unavailable. Tests check undefined-key events from a text cursor, node selection, and closed source preview.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

Suggested reviewers: nperez0111

Merge Risk: Minimal · up to 869ee

The guards avoid undefined-key exceptions while preserving normal keyboard behavior. No actionable merge-blocking defect remains; Safari autofill and dictation validation is still outstanding.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly describes the main change.
Description check Passed The description covers the problem, changes, impact, and test plan. It omits the template checklist, and Safari validation remains unchecked.
Linked Issues check Passed [#3302] The three affected handlers use keyboardEventKey and return without preventing events when the key is not a string. Tests cover undefined keys with a text cursor, a node selection, and a clo…
Out of Scope Changes check Passed [#3302] The shared key helper, handler changes, and tests support the Safari undefined-key fix. The summary shows no unrelated changes.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

[#3302] The three affected handlers use keyboardEventKey and return without preventing events when the key is not a string. Tests cover undefined keys with a text cursor, a node selection, and a closed source preview. They check for errors, default prevention, and document changes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 5 files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

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

A rabbit taps a key, then waits,
No string? The handler safely states:
“I’ll leave this event untouched,”
The editor stays as such.
Three paths are checked, tests agree,
And carrots wait for victory.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 63fecbe8-9bb2-46ea-bf44-952581f701c1
Commits

Reviewing files that changed from the base of the PR and between 262fb81 and 869ee8a.

Files selected for processing: 5

  • packages/core/src/extensions/InlineContentBoundaryEdit/InlineContentBoundaryEdit.ts
  • packages/core/src/extensions/InlineContentBoundaryEdit/undefinedEventKey.test.ts
  • packages/core/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts
  • packages/core/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts
  • packages/core/src/util/keyboardEventKey.ts

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

@itisrmk

itisrmk commented Nov 6, 2026

Copy link
Copy Markdown
Author

Hi! Could a maintainer approve the CI workflows for this PR when you have a moment? Thanks.

@pkg-pr-new

pkg-pr-new Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

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

@blocknote/code-block

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

@blocknote/core

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

@blocknote/diagram-block

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

@blocknote/mantine

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

@blocknote/math-block

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

@blocknote/react

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

@blocknote/server-util

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

@blocknote/shadcn

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

@blocknote/xl-ai

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

@blocknote/xl-docx-exporter

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

@blocknote/xl-email-exporter

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

@blocknote/xl-multi-column

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

@blocknote/xl-odt-exporter

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

@blocknote/xl-pdf-exporter

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

@blocknote/xl-typst-exporter

npm i https://pkg.pr.new/@blocknote/xl-typst-exporter@3311

commit: 869ee8a

This branch has not been deployed

No deployments
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.

TypeError on Safari: keydown handlers read event.key.length when event.key is undefined

2 participants