Skip to content

fix: guard hideMenuIfNotFrozen against undefined view state (#2694, BLO-1171) #2699

Merged
YousefED merged 1 commit intomainfrom
fix/sidemenu-hide-menu-undefined-state-2694
May 1, 2026
Merged

fix: guard hideMenuIfNotFrozen against undefined view state (#2694, BLO-1171) #2699
YousefED merged 1 commit intomainfrom
fix/sidemenu-hide-menu-undefined-state-2694

Conversation

@YousefED
Copy link
Copy Markdown
Collaborator

@YousefED YousefED commented May 1, 2026

Summary

Fixes #2694. SideMenuExtension.hideMenuIfNotFrozen was throwing TypeError: Cannot read properties of undefined (reading 'show') when a queued floating-ui scroll callback fired after the underlying EditorView had been re-created (e.g. toggling editable).

Rationale

The plugin's view.state may already have not been initialized while hideMenuIfNotFrozen is still called in some sort of race condition.

A larger revisit of the side menu is planned — this is the minimal fix to stop the production noise for now.

Changes

  • SideMenu.ts:788 — use view.state?.show instead of view.state!.show in the freshness guard.

Impact

No behavior change on the happy path; only suppresses the error when the view has been torn down.

Testing

x

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature (n/a)

Additional Notes

Quick fix ahead of a broader side-menu revisit.

Summary by CodeRabbit

  • Bug Fixes
    • Resolved potential instability with the side menu display by adding defensive checks to handle edge cases safely.

When the EditorView is re-created (e.g. toggling editable) while the
side menu is visible, a queued floating-ui scroll callback can fire
after view.state has been cleared, causing a TypeError. Use optional
chaining so the early return covers that case.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blocknote Ready Ready Preview May 1, 2026 5:42am
blocknote-website Ready Ready Preview May 1, 2026 5:42am

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

📝 Walkthrough

Walkthrough

A defensive programming fix to the hideMenuIfNotFrozen function in the SideMenu extension that replaces non-null assertions with optional chaining to safely handle cases where view.state may be undefined when the EditorView is recreated while the side menu is visible.

Changes

Cohort / File(s) Summary
SideMenu State Guard
packages/core/src/extensions/SideMenu/SideMenu.ts
Added optional chaining (view!.state?.show) to guard against undefined state access in hideMenuIfNotFrozen, replacing unsafe non-null assertions that caused runtime errors when EditorView was re-created.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • #2630 — Main PR that tweaks the SideMenuExtension.hideMenuIfNotFrozen implementation to safely handle undefined view.state using optional chaining.

Suggested reviewers

  • nperez0111
  • matthewlipski

Poem

🐰 A menu state once threw its hands up high,
When views got recreated—oh my, oh my!
But with optional chaining, we've saved the day,
Now undefined won't make the rabbit's code fray! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR successfully addresses the core objective of #2694 by fixing the TypeError through optional chaining on view.state, preventing the error when the view has been torn down.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective of fixing the TypeError in hideMenuIfNotFrozen; only 2 lines changed in SideMenu.ts with no scope creep.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed PR description is well-structured and covers all major sections: Summary, Rationale, Changes, Impact, Testing, Checklist, and Additional Notes. All required elements are present and clearly explained.
Title check ✅ Passed The title accurately describes the main change: guarding hideMenuIfNotFrozen against undefined view state, with relevant issue references.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sidemenu-hide-menu-undefined-state-2694

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 and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 1, 2026

Open in StackBlitz

@blocknote/ariakit

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

@blocknote/code-block

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

@blocknote/core

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

@blocknote/mantine

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

@blocknote/react

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

@blocknote/server-util

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

@blocknote/shadcn

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

@blocknote/xl-ai

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

@blocknote/xl-docx-exporter

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

@blocknote/xl-email-exporter

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

@blocknote/xl-multi-column

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

@blocknote/xl-odt-exporter

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

@blocknote/xl-pdf-exporter

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

commit: 20fc32d

@YousefED YousefED changed the title fix: guard hideMenuIfNotFrozen against undefined view state (#2694) fix: guard hideMenuIfNotFrozen against undefined view state (#2694, BLO-1171) May 1, 2026
@YousefED YousefED requested a review from nperez0111 May 1, 2026 05:46
@YousefED YousefED merged commit e9497e3 into main May 1, 2026
41 checks passed
@YousefED YousefED deleted the fix/sidemenu-hide-menu-undefined-state-2694 branch May 1, 2026 06:01
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.

hideMenuIfNotFrozen throws "Cannot read properties of undefined (reading 'show')

2 participants