Skip to content

TableHandles: TypeError reading 'id' on undefined #2847

Description

@shehabelhariry

What’s broken?

On table hover/mouse-move the editor intermittently throws:

  • Chrome: Cannot read properties of undefined (reading 'id')
  • Firefox: can't access property "id", this.state.block is undefined

Both from TableHandles.ts:301, function querySelector.

Repro notes

Happens on documents containing tables when the hovered table block is cleared while the handles are being positioned. Non-fatal, the editor keeps working, but it surfaces as an uncaught window.onerror.

What did you expect to happen?

No console error.

Steps to reproduce

I haven't found a reliable manual repro this shows up in our production error reporting, not from a known click path. So I'm reporting it as a latent unsafe access with a clear throw site rather than a sequence of steps.

Throw siteTableHandles.ts:301:

const hideHandles =
  this.state?.block.id !== tableBlock.id || ...

The optional chain guards this.state but not this.state.block, so this throws whenever this.state is set while this.state.block is undefined.

Likely how block becomes undefined (unconfirmed — I couldn't trigger it on demand): update() does

this.state.block = this.editor.getBlock(this.state.block.id)!;

and getBlock can return undefined (the ! hides it) when the table block was removed/replaced by a doc update. That leaves state defined with block undefined; the next mouseMove hits line 301.

Suggested fix

this.state?.block?.id !== tableBlock.id

BlockNote version

v0.51.4

Environment

Firefox 150.0, Chrome 148.0

Additional context

No response

Contribution

  • I'd be interested in contributing a fix for this issue

Sponsor

  • I'm a sponsor and would appreciate if you could look into this sooner than later 💖

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions