Repository navigation
fix(storybook): make stories pass strict TypeScript - #392
Merged
Merged
Conversation
Reviewer's GuideThe PR enables strict TypeScript for File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
|
Preview is ready. |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="apps/storybook/src/stories/examples/imageByBlocks/imageByBlocks.stories.tsx" line_range="62-64" />
<code_context>
canvas.width = pic.width;
canvas.height = pic.height;
const ctx = canvas.getContext("2d");
+ if (!ctx) {
+ console.error("imageByBlocks: 2D canvas context is not available");
+ return;
+ }
</code_context>
<issue_to_address>
**Image story stays blank**
When `canvas.getContext("2d")` returns null, the `pic.onload` callback logs and returns without resolving or rejecting the promise created by `generateByImage`. The caller’s `.then` never sets the config, so `GraphApp` renders nothing and the story stays blank.
Resolve or reject the promise when the 2D canvas context is unavailable.
</issue_to_address>
### Comment 2
<location path="apps/storybook/src/stories/Playground/Editor/utils.ts" line_range="6" />
<code_context>
+
+export function findBlockPositionsMonaco(
+ model: editor.ITextModel,
+ blockId: TBlockId
+): { start: IPosition; end: IPosition } {
const configString = model.getValue();
</code_context>
<issue_to_address>
**Numeric IDs navigate incorrectly**
When a caller navigates to a block whose ID is numeric, `findBlockPositionsMonaco` searches for a quoted ID, but JSON serializes numeric IDs without quotes, so the search misses and returns positions that send the editor selection to the wrong location.
Build the search text using the ID’s JSON representation and return safely when the ID is not found.
Also at `apps/storybook/src/stories/Playground/Editor/index.tsx:46`.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: apps/storybook/src/stories/examples/imageByBlocks/imageByBlocks.stories.tsx:64, apps/storybook/src/stories/Playground/Editor/utils.ts:6
draedful
force-pushed
the
fix/v2-storybook-strict
branch
from
October 16, 2026 15:39
a15d82d to
bb1d448
Compare
Enable "strict": true in apps/storybook/tsconfig.json and fix the 179 strict diagnostics in 32 story files: null-safe ref access with early returns, explicit parameter types, spread before explicit props, story-local narrower generator types, and nullable refs instead of readonly ref assignment. No library types are changed. Part of #367 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- imageByBlocks: reject the generation promise when the 2D canvas context is unavailable instead of leaving it pending. - Playground editor: search block ids as JSON serializes them (numeric ids are unquoted), require a value boundary so `1` does not match `12`, and skip scroll/update when the id is not found instead of selecting from the document start. Part of #367 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Editor: keep findBlockPositionsMonaco typed only; drop the numeric-id search change (ids are strings by the editor schema), to be handled separately if needed. - Annotate generated configs instead of extracting local arrays. - Use optional chaining for graphRef in api and themeChange stories. - Simplify parseTheme and imageInsteadBlock narrowing. Part of #367 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
draedful
force-pushed
the
fix/v2-storybook-strict
branch
from
October 17, 2026 22:14
bb1d448 to
561391d
Compare
9 tasks done
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.
Part of #367 (epic #353).
Summary
The Storybook app (
apps/storybook) now type-checks under strict TypeScript, and"strict": trueis enabled inapps/storybook/tsconfig.json. Before this change the strict debt was visible only through the strict gate overlay.tsc -p tsconfig.json --noEmit --strict) reported 179 diagnostics in 32 files. By code: TS18048 ×89, TS7006 ×18, TS2322 ×17, TS2783 ×15, TS18047 ×14, TS2345 ×7, TS2540 ×4, TS2532 ×4, TS7053 ×4, others ×7.No
packages/*files change, so no library types are widened. The diff adds noany,@ts-ignore/@ts-expect-error, non-null!orascasts.Approach
graphRef.current?.…in handlers; layer and editor refs are typeduseRef<T | null>(null)and also accessed with?..main/GraphEditor.tsx: thegraphRefprop isMutableRefObject<Graph | undefined>, andrenderBlockmay returnnull. The wrapper already falls back toBlockStoryvia||.main/GraphEditor.stories.tsx:{...args}now comes beforeconfig=. Storybook args never containconfig, so rendering is unchanged.TGeneratedGraphConfig,{ blocks; connections },TGravityActionBlockWithAnchors), soblocks/connectionsare non-optional.any: fixed with explicit parameter types (TPoint,LayerProps, monacoeditor.ITextModel, …).Behavior notes
TypeErroron a missing ref, model, meta or context now return early or use?..GraphPlayground: the selection-change handler skips ids missing from the store. Before, it sent partial{ selected }objects that produced a wrong editor edit.updateGraphSizegetsdefault: return;instead of callingsetEntities(undefined).ToolboxLayer: the unknownhtml.classNamekey, whichLayerignored, becameclassNames: ["custom-control"], so the class is now actually applied. No CSS targets it, so nothing renders differently.CustomLayerConfig.tsand thelayersblock ofminimap.stories.tsxare untouched; a separate PR changes them.Verification
All of the following exit 0:
pnpm run build, thenpnpm --filter @gravity-ui/graph-storybook exec tsc -p tsconfig.json --noEmit→ 0 diagnosticspnpm run typecheckpnpm run test:type-configspnpm test(graph 379 passed, graph-react 167 passed, devtools 11 passed)pnpm run lintnode scripts/strict-diagnostics.mjs→apps/storybook/tsconfig.json: 0 existing diagnostics(baseline not edited; stale entries are retired later)pnpm run build-storybookIndependent review rounds, including an architectural one that checked every hunk against the origin/v2 strict baseline, reported no unresolved P2+ findings. A Sourcery-suggested change to the editor id search was dropped from this PR: numeric ids are not reachable, because the editor schema types
idas a string.🤖 Generated with Claude Code
Summary by Sourcery
Enable strict TypeScript checking for Storybook and make its stories type-safe without weakening shared library types.
Bug Fixes:
Enhancements: