fix(code-block)!: errors following a full review of the component (#DS-5482) - #1988
Draft
artembelik wants to merge 2 commits into
Draft
fix(code-block)!: errors following a full review of the component (#DS-5482)#1988artembelik wants to merge 2 commits into
artembelik wants to merge 2 commits into
Conversation
`maxHeight` was published as `InputSignal<number>` over an `undefined!` default, so a code block with no `[maxHeight]` binding reported `undefined` from a non-nullable type — an assignment to a `number` held `undefined`, and any arithmetic on it produced NaN. It reports `number | undefined` now. `KbqCodeBlockHighlight.file` was a write-only required input: a setter with no getter that kicked off highlighting as a side effect. It is a required signal input driven by an effect now, so it can finally be read. The `max-height` applied while `viewAll` is off is a `computed`. It was a getter read from a `[style.max-height.px]` binding, so it only re-evaluated when something else marked the view dirty. `softWrap`, `viewAll`, `canDownload`, `activeFileIndex` and `files` are backed by signals. They stay accessor inputs with the same types and the same two-way outputs: the component writes them as well as the binding, and a `model()` cannot carry the `booleanAttribute` / `numberAttribute` transform they need. BREAKING CHANGE: `KbqCodeBlock.maxHeight` reports `number | undefined` instead of `number`, and `KbqCodeBlockHighlight.file` is a readable required signal input rather than a write-only setter. Reported by the `code-block-optional-max-height` schematic. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`files.length < activeFileIndex` left the first out-of-range index in place: three files with an active index of 2, shrunk to two, kept index 2 and the template rendered `files[2].content` from undefined. The new test fails against the old comparison and passes against `<=`. The review's own narrowing fix hoisted the `maxHeight` read out of `checkOverflow`, freezing the threshold at `ngAfterViewInit` so the resize observer compared against a stale value. The read is back inside the callback. `KbqCodeBlockHighlight` started a second highlight.js import for any `file` that arrived while the first was still loading, registering the line-numbers plugin twice, and neither continuation was cancelled on teardown. Deduped behind `loadOnce()` with an `onCleanup` guard, and the promise is cleared on failure so a later file change can still retry. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A full review of
code-block, in the same shape as the 20.3.0 component reviews.maxHeightlied about being requiredA code block with no
[maxHeight]binding reportedundefinedfrom a non-nullable type: an assignment to anumberheldundefined, andmaxHeight() > 0was a NaN comparison that never matched. It reportsnumber | undefinednow — the same pathology, and the same fix, asKbqSplitButton.disabledin the first review wave.KbqCodeBlockHighlight.filewas write-onlyA required input with no getter, whose setter kicked off highlighting as a side effect — which is exactly why the automated signal migration skipped it. It is
input.required()driven by an effect now, so it can finally be read.The max-height binding never re-evaluated on its own
calculatedMaxHeightwas a getter read from[style.max-height.px], so it only recomputed when something else marked the view dirty. It is acomputedovermaxHeightandviewAllnow.That binding turned out to have no test coverage at all — the new test caught a mistake I made in the very same change (binding the computed without calling it), which is worth knowing about the component.
What deliberately stays an accessor input
softWrap,viewAll,canDownload,activeFileIndexandfilesare backed by signals now, but stay accessor inputs with the same types and the same two-way…Changeoutputs. They are written by the component (toggleSoftWrap(),onSelectedTabChange()) as well as by the binding, and amodel()cannot carry thebooleanAttribute/numberAttributetransform a valueless attribute needs — the same conclusioncheckboxand the reviewedbutton-togglereached.No call site changes for those five. What does change is that a template reading them re-renders on its own instead of waiting for change detection, and the
// TODO: Skipped for migrationcomments are gone.Migration
code-block-optional-max-heightruns fromng update @koobiq/components@20. It is warn-only: narrowingnumber | undefinedback tonumberis a decision the call site owns, and turning afilewrite into a[file]binding is a template edit.Documented in
docs/guides/migration.{en,ru}.md, section 18.Testing
code-block.spec.ts: 50 → 53 tests. New coverage for the unboundmaxHeight, themax-heightstyle the component applies and drops onviewAll, and the now-readablefileon the highlight directive.code-block-optional-max-height/index.spec.ts: 4 tests.packages/components(4996 tests) andpackages/schematics(438 tests) suites pass.check-apiis in sync.BREAKING CHANGE
🤖 Generated with Claude Code