Skip to content

refactor(superdoc): guard nullable toolbar accesses (SD-2867 phase B)#3069

Merged
caio-pizzol merged 2 commits into
mainfrom
caio/SD-2867-phase-b-toolbar-guards
May 1, 2026
Merged

refactor(superdoc): guard nullable toolbar accesses (SD-2867 phase B)#3069
caio-pizzol merged 2 commits into
mainfrom
caio/SD-2867-phase-b-toolbar-guards

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

Stacked on #3068. Closes two TS2533 errors on this.toolbar accesses; the field is typed SuperToolbar | null because #addToolbar writes null before reassigning the new instance, so every later read needs a strict-null guard.

  • The editorCreate callback inside #addToolbar reads this.toolbar lazily, after the closure captures the live reference. Optional-chain (this.toolbar?.updateToolbarState()) is the natural form: at call time toolbar is the constructed instance, but if destroy() cleared it between scheduling and emission the chain skips instead of throwing.
  • #setModeViewing writes this.toolbar.activeEditor = null, which can't be optional-chained on the LHS. Wrapped the assignment in if (this.toolbar) so the same null-guard semantics apply.

Both call paths run after #init invokes #addToolbar, so in practice the guards are no-ops. Inline comments call out the runtime invariant so future readers don't go looking for a missing toolbar.

Verified: pnpm --filter superdoc check:jsdoc clean; pnpm --filter superdoc build:es declaration audit clean; node tests/consumer-typecheck/typecheck-matrix.mjs 33 passed, 0 failed.

@caio-pizzol caio-pizzol requested a review from a team as a code owner May 1, 2026 21:36
@linear
Copy link
Copy Markdown

linear Bot commented May 1, 2026

Base automatically changed from caio/SD-2867-phase-b-optional-callables to main May 1, 2026 21:57
@caio-pizzol caio-pizzol force-pushed the caio/SD-2867-phase-b-toolbar-guards branch from d4a6699 to e07e9c9 Compare May 1, 2026 22:01
@caio-pizzol caio-pizzol merged commit 6209f70 into main May 1, 2026
61 checks passed
@caio-pizzol caio-pizzol deleted the caio/SD-2867-phase-b-toolbar-guards branch May 1, 2026 22:12
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 1, 2026

🎉 This PR is included in superdoc-cli v0.8.0

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 1, 2026

🎉 This PR is included in superdoc-sdk v1.8.0

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 1, 2026

🎉 This PR is included in @superdoc-dev/mcp v0.3.0

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 1, 2026

🎉 This PR is included in superdoc v1.31.0

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 2, 2026

🎉 This PR is included in @superdoc-dev/mcp v0.3.0-next.33

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 2, 2026

🎉 This PR is included in @superdoc-dev/react v1.2.0-next.75

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 2, 2026

🎉 This PR is included in vscode-ext v2.3.0-next.77

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 2, 2026

🎉 This PR is included in superdoc-sdk v1.8.0-next.37

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in vscode-ext v2.3.0

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 7, 2026

🎉 This PR is included in @superdoc-dev/react v1.3.0

The release is available on GitHub release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants