Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@rokotyan
Copy link
Owner

@rokotyan rokotyan commented Jun 25, 2025

Summary

  • narrow ts package build scope to utils to make type-checking feasible
  • refine type handling in data utilities and axis rendering
  • add global types to tsconfig includes

Testing

  • npx tsc --noEmit -p packages/ts/tsconfig.json

https://chatgpt.com/codex/tasks/task_e_685c68a4001483268dda8e048ed7848f

Summary by CodeRabbit

  • New Features

    • Added TypeScript type declarations for external modules and global variables to improve type safety.
  • Bug Fixes

    • Improved handling of undefined or null values across components, containers, data models, and utility functions to prevent runtime errors.
    • Enhanced default value fallbacks for colors, styles, and text utilities, ensuring consistent behavior when global variables or properties are missing.
    • Fixed potential errors in annotation rendering and SVG text processing by adding defensive checks and safe defaults.
  • Refactor

    • Updated public property and method types to explicitly allow undefined or null values where appropriate.
    • Refined type guards and utility function signatures for better type safety and clarity.
    • Clarified style application logic and rendering flow in annotation and container components.
  • Chores

    • Enabled strict null checks and added skipLibCheck in TypeScript configuration for stronger type safety.
    • Added type declarations for external modules and global variables.

@coderabbitai
Copy link

coderabbitai bot commented Jun 25, 2025

Walkthrough

This update introduces comprehensive null and undefined safety across the codebase. It adjusts type annotations, adds defensive programming patterns, and ensures default values are provided where necessary. Several utility and core classes now handle missing data more gracefully. TypeScript configuration is tightened with strictNullChecks, and new type declarations are added for global variables and third-party modules.

Changes

File(s) Change Summary
components/annotations/index.ts Improved null safety and explicit defaulting in annotation rendering and subject handling.
containers/xy-container/index.ts Added explicit generic types and nullish coalescing for margin and array cleaning logic.
core/component/index.ts Made element property possibly undefined; added guard in attribute setter.
core/container/index.ts Updated property types to allow null, added null checks for DOM and animation frame handling, and improved margin safety.
core/xy-component/index.ts Added explicit type assertions for extent calculations.
data-models/core.ts Allowed data property to be undefined in getter/setter; adjusted constructor assignment.
data-models/graph.ts Made getNodeById return possibly undefined; improved defaulting and type assertions in node/link handling.
data-models/map-graph.ts Getter for data now returns {} if falsy; improved link array typing and spreading.
data-models/map.ts Ensured getDataLatLngBounds always receives a defined array.
styles/colors.ts, styles/index.ts Replaced optional chaining and logical OR with nullish coalescing for global variable fallbacks; added explicit type annotations.
types/d3-interpolate-path.d.ts Added module declaration for d3-interpolate-path.
types/globals.d.ts Introduced global variable type declarations for configuration and color arrays.
utils/color.ts Improved type safety and fallback logic in color utilities; updated return types for RGBA conversion.
utils/data.ts Refined type guards, widened return types, and improved null safety in utility functions.
utils/html.ts Clarified control flow for 2D/3D transform parsing; improved defaulting.
utils/map.ts Added nullish coalescing to ensure numeric bounds are always defined.
utils/misc.ts Updated return types of utility functions to allow null.
utils/path.ts Ensured polygon always returns a string by defaulting to empty string.
utils/text.ts Added defensive checks and default values in SVG text utilities to prevent errors from missing nodes or properties.
tsconfig.json Enabled strictNullChecks, added skipLibCheck, and specified included files.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Component
  participant DOM
  participant Utility
  participant Global

  User->>Component: Render or update component
  Component->>Utility: Request data, config, or color
  Utility->>Global: Access global config (with nullish coalescing)
  Utility-->>Component: Return value (with safe defaults)
  Component->>DOM: Manipulate DOM nodes (with null checks)
  DOM-->>Component: DOM node or null
  Component-->>User: Rendered output or safe fallback
Loading

Poem

In the warren of code, where nulls used to creep,
Now safety abounds, and the rabbits all leap!
With types more precise and defaults in tow,
No undefined burrows, just clear paths to go.
🐇✨
Hooray for the patch—let the safe coding flow!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
npm error node_modules/eslint
npm error dev eslint@"^8.26.0" from the root project
npm error peer eslint@"^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0" from @eslint-community/[email protected]
npm error node_modules/@eslint-community/eslint-plugin-eslint-comments
npm error @eslint-community/eslint-plugin-eslint-comments@"^4.4.1" from @antfu/[email protected]
npm error packages/vue/node_modules/@antfu/eslint-config
npm error dev @antfu/eslint-config@"^3.9.1" from @unovis/[email protected]
npm error packages/vue
npm error @unovis/[email protected]
npm error node_modules/@unovis/vue
npm error 31 more (@eslint-community/eslint-utils, ...)
npm error
npm error Could not resolve dependency:
npm error peer eslint@"^7.12.1" from [email protected]
npm error node_modules/eslint-config-standard
npm error dev eslint-config-standard@"^16.0.3" from the root project
npm error
npm error Conflicting peer dependency: [email protected]
npm error node_modules/eslint
npm error peer eslint@"^7.12.1" from [email protected]
npm error node_modules/eslint-config-standard
npm error dev eslint-config-standard@"^16.0.3" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /.npm/_logs/2025-06-26T22_17_07_272Z-eresolve-report.txt
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-26T22_17_07_272Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c703d6 and b91e9ba.

📒 Files selected for processing (2)
  • packages/ts/src/containers/xy-container/index.ts (5 hunks)
  • packages/ts/src/utils/data.ts (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/ts/src/containers/xy-container/index.ts
  • packages/ts/src/utils/data.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (2)
packages/ts/src/core/xy-component/index.ts (2)

81-81: Duplicate type assertion concern - verify getExtent safety.

Same concern as line 75 - the type assertion assumes getExtent will never return undefined values. Consider adding proper null handling instead of type assertions.


89-89: Duplicate type assertion concern - verify getExtent safety.

Same concern as lines 75 and 81 - the type assertion may not be safe if getExtent can actually return undefined values.

🧹 Nitpick comments (2)
packages/ts/src/core/container/index.ts (1)

132-135: Consider using optional chaining for cleaner code.

The null check is correct, but you could use optional chaining for more concise code:

-  while (this.element && this.element.firstChild) {
-    this.element.removeChild(this.element.firstChild)
-  }
+  while (this.element?.firstChild) {
+    this.element.removeChild(this.element.firstChild)
+  }
packages/ts/src/utils/data.ts (1)

321-321: Non-null assertions may be risky - consider safer alternatives.

The non-null assertion operators (!) assume that values[index - 1] and values[index] are never undefined. While this is likely true given the logic, it could cause runtime errors if the assumptions are incorrect.

Consider a safer approach:

-  return value - values[index - 1]! > values[index]! - value ? data[index] : data[index - 1]
+  const prevValue = values[index - 1] ?? 0
+  const nextValue = values[index] ?? 0
+  return value - prevValue > nextValue - value ? data[index] : data[index - 1]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7a208c0 and 8c703d6.

📒 Files selected for processing (21)
  • packages/ts/src/components/annotations/index.ts (4 hunks)
  • packages/ts/src/containers/xy-container/index.ts (4 hunks)
  • packages/ts/src/core/component/index.ts (2 hunks)
  • packages/ts/src/core/container/index.ts (6 hunks)
  • packages/ts/src/core/xy-component/index.ts (1 hunks)
  • packages/ts/src/data-models/core.ts (1 hunks)
  • packages/ts/src/data-models/graph.ts (3 hunks)
  • packages/ts/src/data-models/map-graph.ts (2 hunks)
  • packages/ts/src/data-models/map.ts (1 hunks)
  • packages/ts/src/styles/colors.ts (1 hunks)
  • packages/ts/src/styles/index.ts (1 hunks)
  • packages/ts/src/types/d3-interpolate-path.d.ts (1 hunks)
  • packages/ts/src/types/globals.d.ts (1 hunks)
  • packages/ts/src/utils/color.ts (2 hunks)
  • packages/ts/src/utils/data.ts (7 hunks)
  • packages/ts/src/utils/html.ts (1 hunks)
  • packages/ts/src/utils/map.ts (1 hunks)
  • packages/ts/src/utils/misc.ts (2 hunks)
  • packages/ts/src/utils/path.ts (1 hunks)
  • packages/ts/src/utils/text.ts (13 hunks)
  • packages/ts/tsconfig.json (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (7)
packages/ts/src/core/xy-component/index.ts (3)
packages/ts/src/utils/data.ts (3)
  • getExtent (309-311)
  • filterDataByRange (324-331)
  • isArray (13-13)
packages/ts/src/types/accessor.ts (1)
  • NumericAccessor (1-1)
packages/ts/src/data-models/core.ts (2)
  • data (4-6)
  • data (8-10)
packages/ts/src/styles/index.ts (1)
packages/ts/src/types/text.ts (1)
  • UnovisText (24-43)
packages/ts/src/data-models/map.ts (1)
packages/ts/src/utils/map.ts (1)
  • getDataLatLngBounds (9-29)
packages/ts/src/components/annotations/index.ts (4)
packages/ts/src/components/annotations/style.ts (1)
  • annotation (28-30)
packages/ts/src/styles/index.ts (1)
  • UNOVIS_TEXT_DEFAULT (11-18)
packages/ts/src/utils/misc.ts (1)
  • parseUnit (60-66)
packages/ts/src/utils/text.ts (1)
  • renderTextIntoFrame (556-597)
packages/ts/src/types/globals.d.ts (1)
packages/ts/src/styles/index.ts (3)
  • UNOVIS_TEXT_SEPARATOR_DEFAULT (9-9)
  • UNOVIS_TEXT_HYPHEN_CHARACTER_DEFAULT (10-10)
  • UNOVIS_TEXT_DEFAULT (11-18)
packages/ts/src/utils/misc.ts (1)
packages/ts/src/types/accessor.ts (1)
  • StringAccessor (2-2)
packages/ts/src/utils/color.ts (3)
packages/ts/src/utils/data.ts (2)
  • isNumber (8-8)
  • getString (184-186)
packages/ts/src/types/accessor.ts (1)
  • StringAccessor (2-2)
packages/ts/src/styles/colors.ts (1)
  • getCSSColorVariable (9-11)
🪛 Biome (1.9.4)
packages/ts/src/core/container/index.ts

[error] 132-132: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (55)
packages/ts/tsconfig.json (3)

19-19: LGTM! Enabling strictNullChecks aligns with PR objectives.

This change enables strict null checking which is the primary goal of this PR.


24-24: Good addition of skipLibCheck option.

This option helps avoid type-checking issues with third-party libraries while maintaining strict checks for the project code.


26-29: Appropriate scope narrowing for type checking.

Limiting the include scope to utils and types directories makes the strict null checking more manageable and aligns with the PR's strategy of gradually enabling strict checks.

packages/ts/src/utils/path.ts (1)

127-127: Excellent null safety improvement.

The nullish coalescing operator ensures the function always returns a string as declared, preventing potential runtime errors when path(data) returns null or undefined.

packages/ts/src/types/d3-interpolate-path.d.ts (1)

1-3: Well-structured type declaration.

The type declaration correctly defines the interpolatePath function signature with appropriate parameter types and return type for SVG path interpolation functionality.

packages/ts/src/types/globals.d.ts (3)

1-1: Appropriate ESLint disable for global declarations.

The no-var rule disable is necessary since global variable declarations require the var keyword in TypeScript.


2-2: Good module export pattern.

The empty export ensures this file is treated as a module rather than a script, which is the correct approach for global type declarations.


4-12: Excellent null-safe global variable declarations.

All global variables are properly typed with | undefined unions, which aligns perfectly with the strictNullChecks requirement. The consistent UNOVIS_* naming convention and comprehensive coverage of theme-related globals is well-structured.

packages/ts/src/core/xy-component/index.ts (1)

75-75: ```shell
#!/bin/bash
set -e

Locate and display the implementation of getExtent, getMin, and getMax

rg -n "export function getExtent" -C5
rg -n "export function getMin" -C5
rg -n "export function getMax" -C5


</details>
<details>
<summary>packages/ts/src/data-models/map.ts (1)</summary>

`16-16`: **LGTM: Proper null safety implementation.**

The nullish coalescing operator ensures `getDataLatLngBounds` always receives a defined array, preventing potential runtime errors when `this.data` is null or undefined. This aligns perfectly with the `strictNullChecks` objectives.

</details>
<details>
<summary>packages/ts/src/core/component/index.ts (2)</summary>

`25-25`: **LGTM: Explicit undefined type annotation.**

Adding `| undefined` to the element property type makes the potential undefined state explicit, which is essential for strict null checking. This aligns with the pattern used throughout the codebase for better type safety.

---

`116-116`: **LGTM: Proper guard clause for null safety.**

The early return when `attributeMap` is falsy prevents attempting to iterate over `undefined` or `null` values, which would cause runtime errors. This defensive programming pattern is exactly what's needed for `strictNullChecks`.

</details>
<details>
<summary>packages/ts/src/data-models/map-graph.ts (2)</summary>

`27-27`: **LGTM: Safe fallback for undefined data.**

The nullish coalescing operator ensures the getter always returns a defined object, preventing undefined values from propagating through the system. This is essential for `strictNullChecks` compliance.

---

`37-44`: **LGTM: Improved type safety in link processing.**

The explicit typing of the accumulator and the conditional check for valid source/target points prevent invalid links from being added to the array. The object spreading preserves original link properties while safely adding resolved points, which is exactly the right approach for strict null checking.

</details>
<details>
<summary>packages/ts/src/utils/map.ts (1)</summary>

`16-17`: **LGTM: Safe numeric fallbacks for coordinate calculations.**

Adding `?? 0` to the `max` and `min` results ensures numeric values are always returned, even when the data array is empty or contains no valid numbers. This prevents `undefined` values from propagating into the bounding box calculations, which is essential for `strictNullChecks` compliance.



Also applies to: 21-22

</details>
<details>
<summary>packages/ts/src/data-models/core.ts (2)</summary>

`4-4`: **LGTM: Explicit undefined handling in core data model.**

Making `undefined` explicit in both getter and setter signatures establishes the foundation for proper null safety throughout the data model hierarchy. This is essential for `strictNullChecks` and ensures all extending classes handle undefined data appropriately.



Also applies to: 8-8

---

`13-13`: **LGTM: Direct assignment in constructor.**

Assigning data directly to `_data` instead of using the setter prevents potential complications with setter logic during initialization. This is a safer approach when establishing the base data model behavior.

</details>
<details>
<summary>packages/ts/src/utils/html.ts (1)</summary>

`17-24`: **Excellent control flow improvement for strictNullChecks.**

The refactored control flow with explicit `else if` structure and final fallback return ensures all code paths are handled correctly. This eliminates potential undefined returns and aligns well with strict null checking requirements.

</details>
<details>
<summary>packages/ts/src/styles/index.ts (1)</summary>

`7-18`: **Proper use of nullish coalescing for strictNullChecks compliance.**

The change from `globalThis?.PROP || default` to `globalThis.PROP ?? default` is more precise for strict null checking, as nullish coalescing only triggers for `null`/`undefined` values rather than all falsy values.

Note: The removal of optional chaining on `globalThis` assumes it's always available, which is safe in modern JavaScript environments.

</details>
<details>
<summary>packages/ts/src/styles/colors.ts (1)</summary>

`5-6`: **Good strictNullChecks improvements with explicit typing.**

The combination of nullish coalescing and explicit `string[]` type annotations properly handles the global color variables while ensuring type safety under strict null checking.

</details>
<details>
<summary>packages/ts/src/data-models/graph.ts (3)</summary>

`32-34`: **Correct return type for strictNullChecks.**

The updated return type `OutNode | undefined` accurately reflects that the node may not be found, improving type safety.

---

`36-38`: **Good defensive programming pattern.**

Returning a default object with empty nodes array prevents undefined access issues under strict null checking.

---

`55-56`: **Safer accessor handling for strictNullChecks.**

Using inline functions with nullish coalescing (`?? ''`) is safer than passing method references directly, as it handles potential undefined returns from the accessor functions.

</details>
<details>
<summary>packages/ts/src/containers/xy-container/index.ts (3)</summary>

`379-381`: **Proper generic typing for nullable array filtering.**

The explicit generic type annotations help TypeScript understand that the input array may contain `null` or `undefined` elements while the output is strongly typed. This is essential for strictNullChecks compliance.

---

`393-395`: **Consistent nullable array handling.**

Good use of explicit generics for filtering potentially nullable component arrays, maintaining type safety throughout the container logic.

---

`412-415`: **Safe margin calculations with nullish coalescing.**

Using nullish coalescing (`?? 0`) prevents potential NaN results from undefined margin values, ensuring robust layout calculations under strict null checking.



Also applies to: 425-428

</details>
<details>
<summary>packages/ts/src/utils/misc.ts (2)</summary>

`29-29`: **LGTM: Correct return type update for null safety.**

The return type change to `number | null` accurately reflects that `toPx()` can return `null`, improving type safety under `strictNullChecks`.

---

`55-58`: **LGTM: Accurate return type and null handling.**

The function correctly returns `null` when no valid identifier is found, and the return type `string | null` properly reflects this behavior.

</details>
<details>
<summary>packages/ts/src/utils/color.ts (3)</summary>

`20-27`: **LGTM: Improved null safety and explicit return handling.**

The changes enhance type safety by:
- Using `isNumber()` instead of `isFinite()` for more precise type checking
- Adding explicit null returns with clear conditional logic
- Properly handling the fallback to CSS variables

---

`49-49`: **LGTM: Safe fallback using nullish coalescing.**

The nullish coalescing operator (`??`) provides a safe fallback to an empty string when color parsing fails, preventing potential runtime errors.

---

`52-56`: **LGTM: Enhanced return type and null handling.**

The function now:
- Explicitly includes `undefined` in the return type
- Safely handles nullish RGB values 
- Returns early for fully opaque colors or invalid inputs
- Uses nullish coalescing for robust background color parsing

</details>
<details>
<summary>packages/ts/src/components/annotations/index.ts (5)</summary>

`44-44`: **LGTM: Safe data binding with null coalescing.**

Using `config.items ?? []` ensures the data binding always has a valid array, preventing runtime errors when items is undefined.

---

`61-61`: **LGTM: Explicit null handling for cursor attribute.**

Using `d.cursor ?? null` ensures the cursor attribute is explicitly set to null when undefined, which is important for proper DOM attribute management.

---

`65-75`: **LGTM: Comprehensive null safety for positioning and DOM operations.**

The changes add robust null safety by:
- Using nullish coalescing for position/dimension properties with appropriate defaults
- Checking for DOM node existence before calling `renderTextIntoFrame`

This prevents runtime errors when annotation properties are undefined or when DOM nodes are not available.

---

`99-121`: **LGTM: Thorough null safety for subject rendering.**

Excellent defensive programming with:
- Early return when subject is undefined
- Null coalescing for all subject properties with appropriate defaults
- Safe handling of function vs. direct value properties for x/y coordinates

---

`122-167`: **LGTM: Safe DOM operations with explicit null attribute handling.**

The changes ensure robust rendering by:
- Checking for content node existence before accessing `getBBox()`
- Explicitly handling null values for SVG style attributes
- Using conditional style setting to properly clear or set attributes

This prevents runtime errors and ensures proper SVG attribute management.

</details>
<details>
<summary>packages/ts/src/core/container/index.ts (5)</summary>

`15-21`: **LGTM: Appropriate type updates for null safety.**

The type changes to allow `null` values for `element` and `_renderAnimationFrameId` properly reflect the actual runtime behavior and support `strictNullChecks`.

---

`62-79`: **LGTM: Comprehensive null handling for configuration.**

The changes properly handle potentially null/undefined values:
- Safe SVG defs content management
- Conditional aria-label attribute setting with explicit null handling

---

`102-102`: **LGTM: Defensive animation frame management.**

Adding null checks before `cancelAnimationFrame` calls prevents potential runtime errors and ensures safe cleanup.



Also applies to: 169-169

---

`111-111`: **LGTM: Safe element dimension access.**

The null checks ensure safe access to `clientWidth` and `clientHeight`, returning 0 when the element is null instead of throwing runtime errors.



Also applies to: 117-117

---

`122-128`: **LGTM: Robust margin handling with null coalescing.**

Using nullish coalescing operators ensures safe access to potentially undefined margin properties, preventing runtime errors during width/height calculations.

</details>
<details>
<summary>packages/ts/src/utils/text.ts (7)</summary>

`40-42`: **LGTM: Safe regex match handling.**

Using nullish coalescing (`|| []`) ensures the function continues safely even when the regex match returns null, preventing runtime errors in the subsequent `filter` and `map` operations.

---

`160-161`: **LGTM: Defensive DOM node access.**

Adding null checks before calling DOM methods like `getComputedTextLength()` prevents runtime errors when SVG nodes don't exist, providing safe fallbacks (0 for dimensions).



Also applies to: 196-197, 274-275

---

`190-190`: **LGTM: Safe attribute and style handling.**

The changes ensure robust handling of:
- Font size extraction with safe fallback to 0
- Font family attribute setting with empty string fallback




Also applies to: 237-237

---

`390-391`: **LGTM: Comprehensive null safety for text properties.**

Using nullish coalescing throughout ensures safe access to optional text properties like `lineHeight`, `marginTop`, `marginBottom`, preventing undefined access errors during text layout calculations.



Also applies to: 399-405, 454-456

---

`510-518`: **LGTM: Safe attribute retrieval and text alignment.**

The changes provide robust attribute handling:
- Safe retrieval of x/y coordinates with numeric fallbacks
- Explicit text alignment setting with proper defaults

---

`540-542`: **LGTM: Safe DOM manipulation.**

Adding existence checks before `appendChild` operations prevents runtime errors when parsed SVG content is null, ensuring robust text rendering.



Also applies to: 594-596

---

`563-578`: **LGTM: Comprehensive frame options null safety.**

Using nullish coalescing for frame dimensions and alignment options ensures safe text positioning calculations and proper SVG attribute generation, preventing undefined value errors.



Also applies to: 583-583

</details>
<details>
<summary>packages/ts/src/utils/data.ts (7)</summary>

`8-20`: **Excellent type safety improvements in type guard functions.**

The conversion from generic conditional types to explicit type guards with `unknown` inputs is well-executed. The `isAClassInstance` function's rewrite with optional chaining and type assertions provides safer constructor checking. All type guards now follow consistent patterns and provide better type narrowing for strict null checks.

---

`178-178`: **Good addition of explicit null/undefined to return type.**

The `getValue` function now correctly reflects that accessors can return `null` or `undefined`, which aligns with the strict null checking requirements. This makes the nullable nature of the return value explicit to consumers.

---

`228-242`: **Excellent simplification of getStackedExtent function.**

The rewrite with explicit variable initialization and nullish coalescing (`|| 0`) provides much cleaner and more readable code. The logic correctly handles null/undefined values from `getNumber` by defaulting to 0, which is appropriate for stacking calculations.

---

`270-272`: **Good use of nullish coalescing for safer null handling.**

The use of `?? 0` and `?? false` provides appropriate defaults when dealing with potentially undefined values from `mean()` and array access. This handles the strict null checking requirements well.

---

`275-275`: **Type casting for array initialization is appropriate.**

The cast `[] as unknown as StackValuesRecord` is necessary due to the complex type structure and the map operation creating arrays that will be populated later. This is a reasonable workaround for TypeScript's type system limitations.

---

`316-316`: **Appropriate null handling in getNearest function.**

Using nullish coalescing (`?? 0`) to replace null/undefined values with 0 before sorting is a good approach for numerical operations. This ensures the sort operation works correctly with the bisector.

---

`327-327`: **Excellent explicit null check before range comparison.**

The addition of `value != null` provides proper null safety before performing range comparisons. This prevents potential runtime errors and aligns well with strict null checking requirements.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Comment on lines +72 to +73
link.source = this.findNode(nodes, link.source)!
link.target = this.findNode(nodes, link.target)!
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Risky non-null assertions could cause runtime errors.

The non-null assertion operators (!) assume that findNode will always return a value, but findNode can return undefined (as seen in its implementation). This could lead to runtime errors if nodes are not found.

Consider adding explicit checks instead:

-      link.source = this.findNode(nodes, link.source)!
-      link.target = this.findNode(nodes, link.target)!
+      const source = this.findNode(nodes, link.source)
+      const target = this.findNode(nodes, link.target)
+      if (!source || !target) {
+        console.warn(`Unovis | Graph Data Model: Skipping link ${i} due to missing source or target node`)
+        return
+      }
+      link.source = source
+      link.target = target

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/ts/src/data-models/graph.ts around lines 72 to 73, the use of
non-null assertions on the results of findNode is risky because findNode can
return undefined, potentially causing runtime errors. Replace the non-null
assertions with explicit checks to verify that the returned nodes are not
undefined before assigning them to link.source and link.target. Handle the case
where a node is not found, for example by throwing an error or skipping the
assignment, to ensure safe and predictable behavior.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant