refactor(superdoc): guard nullable toolbar accesses (SD-2867 phase B)#3069
Conversation
d4a6699 to
e07e9c9
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
🎉 This PR is included in superdoc-cli v0.8.0 The release is available on GitHub release |
|
🎉 This PR is included in superdoc-sdk v1.8.0 |
|
🎉 This PR is included in @superdoc-dev/mcp v0.3.0 The release is available on GitHub release |
|
🎉 This PR is included in superdoc v1.31.0 The release is available on GitHub release |
|
🎉 This PR is included in @superdoc-dev/mcp v0.3.0-next.33 The release is available on GitHub release |
|
🎉 This PR is included in @superdoc-dev/react v1.2.0-next.75 The release is available on GitHub release |
|
🎉 This PR is included in vscode-ext v2.3.0-next.77 |
|
🎉 This PR is included in superdoc-sdk v1.8.0-next.37 |
|
🎉 This PR is included in vscode-ext v2.3.0 |
|
🎉 This PR is included in @superdoc-dev/react v1.3.0 The release is available on GitHub release |
Stacked on #3068. Closes two TS2533 errors on
this.toolbaraccesses; the field is typedSuperToolbar | nullbecause#addToolbarwritesnullbefore reassigning the new instance, so every later read needs a strict-null guard.editorCreatecallback inside#addToolbarreadsthis.toolbarlazily, 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 ifdestroy()cleared it between scheduling and emission the chain skips instead of throwing.#setModeViewingwritesthis.toolbar.activeEditor = null, which can't be optional-chained on the LHS. Wrapped the assignment inif (this.toolbar)so the same null-guard semantics apply.Both call paths run after
#initinvokes#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:jsdocclean;pnpm --filter superdoc build:esdeclaration audit clean;node tests/consumer-typecheck/typecheck-matrix.mjs33 passed, 0 failed.