Skip to content

Refactor validators to reduce repeated conditionals#8032

Merged
deleonio merged 1 commit intorelease/2from
feature/optimize-duplicate-conditions-in-context
Jul 15, 2025
Merged

Refactor validators to reduce repeated conditionals#8032
deleonio merged 1 commit intorelease/2from
feature/optimize-duplicate-conditions-in-context

Conversation

@deleonio
Copy link
Copy Markdown
Contributor

@deleonio deleonio commented Jul 15, 2025

This pull request refactors validation logic across multiple files by introducing a more robust isObject utility function and replacing repetitive object validation code with calls to this function. Additionally, it introduces type refinements for better type safety and consistency.

Refactoring Object Validation Logic:

  • Introduction of a refined isObject utility function: Updated the isObject function to include type refinement, ensuring it checks whether a value is a non-null object and explicitly defines it as Record<string, unknown> for type safety. (packages/components/src/schema/validators/common.ts)

  • Replacement of manual object validation with isObject: Replaced repetitive object validation logic (e.g., typeof value === 'object' && value !== null) with calls to the isObject utility function across multiple files, including:

    • accordion-callbacks.ts
    • button-callbacks.ts
    • details-callbacks.ts
    • popover-callbacks.ts
    • table-callbacks.ts
    • icons.ts [1] [2]
    • options.ts
    • table-data.ts
    • table-data-foot.ts
    • toolbar-items.ts

Type Refinements and Code Consistency:

  • Improved type safety in icons.ts: Introduced KoliBriAllIcons type and updated logic to use this refined type for better clarity and type checking when handling icon properties. (packages/components/src/schema/props/icons.ts)
  • Streamlined validation logic: Consolidated and simplified validation functions by leveraging isObject, reducing redundancy and improving readability across all affected files.

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions
Copy link
Copy Markdown
Contributor

Hydration Benchmark Report (vs Baseline)

✅ Top 5 Improvements (Best Speedups)

Component Current Baseline Δ% Result
kol-logo 27ms 31.6ms -14.6%
kol-popover-button 78.5ms 89.2ms -12%
kol-modal 20.8ms 23.5ms -11.5%
kol-quote 21.9ms 24.7ms -11.3%
kol-input-text 67.9ms 74.8ms -9.2%

🔻 Flop 5 Regressions (Worst Slowdowns)

Component Current Baseline Δ% Result
kol-indented-text 26.6ms 21.4ms +24.3% 🔻
kol-button-group 24.8ms 20.3ms +22.2% 🔻
kol-drawer 25.6ms 21.4ms +19.6% 🔻
kol-avatar 27.5ms 23.2ms +18.5% 🔻
kol-link-group 25.3ms 22.3ms +13.5% 🔻
📋 Show all results
Component Current Baseline Δ% Result
kol-abbr 27.4ms 29.1ms -5.8%
kol-accordion 163.1ms 158.2ms +3.1%
kol-alert 125.3ms 113.7ms +10.2% 🔻
kol-avatar 27.5ms 23.2ms +18.5% 🔻
kol-badge 74.2ms 75.1ms -1.2%
kol-breadcrumb 89.6ms 93.6ms -4.3%
kol-button 75.6ms 77.7ms -2.7%
kol-button-group 24.8ms 20.3ms +22.2% 🔻
kol-button-link 70.5ms 62.3ms +13.2% 🔻
kol-card 34.6ms 31.1ms +11.3% 🔻
kol-details 150.7ms 159.9ms -5.8%
kol-drawer 25.6ms 21.4ms +19.6% 🔻
kol-form 37ms 37.2ms -0.5%
kol-heading 24.6ms 26ms -5.4%
kol-icon 66.2ms 68.5ms -3.4%
kol-image 21.4ms 20.1ms +6.5%
kol-indented-text 26.6ms 21.4ms +24.3% 🔻
kol-input-checkbox 145ms 148.7ms -2.5%
kol-input-color 69.9ms 72.8ms -4%
kol-input-date 74.8ms 75.1ms -0.4%
kol-input-email 69ms 73.2ms -5.7%
kol-input-file 64.4ms 66.6ms -3.3%
kol-input-number 70.3ms 72.7ms -3.3%
kol-input-password 70ms 71.1ms -1.5%
kol-input-radio 52.2ms 52.4ms -0.4%
kol-input-text 67.9ms 74.8ms -9.2%
kol-link 67.1ms 66.2ms +1.4%
kol-link-button 71ms 72.9ms -2.6%
kol-link-group 25.3ms 22.3ms +13.5% 🔻
kol-logo 27ms 31.6ms -14.6%
kol-modal 20.8ms 23.5ms -11.5%
kol-nav 28.1ms 29.9ms -6%
kol-pagination 528.8ms 525.6ms +0.6%
kol-popover-button 78.5ms 89.2ms -12%
kol-progress 30.7ms 32ms -4.1%
kol-quote 21.9ms 24.7ms -11.3%
kol-select 85.9ms 89.6ms -4.1%
kol-skip-nav 20.3ms 20.4ms -0.5%
kol-spin 24.6ms 23.2ms +6%
kol-split-button 198ms 202.4ms -2.2%
kol-table-stateful 94.6ms 98ms -3.5%
kol-table-stateless 79.4ms 84.1ms -5.6%
kol-tabs 37.5ms 35.4ms +5.9%
kol-textarea 69.1ms 70.4ms -1.8%
kol-toolbar 32.9ms 34.9ms -5.7%
kol-tree 28.6ms 26.6ms +7.5%
kol-tree-item 79.6ms 82.5ms -3.5%
kol-version 155.4ms 161.3ms -3.7%

@deleonio deleonio requested review from Copilot and laske185 July 15, 2025 11:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors common object checks into a single isObject type guard and applies it across multiple prop validators to eliminate repeated inline conditionals.

  • Updated isObject to be a type guard for better narrowing.
  • Replaced typeof value === 'object' && value !== null with isObject in various prop validators.
  • Streamlined multiple watchValidator and array validations.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/components/src/schema/validators/common.ts Changed isObject return type to a type guard
packages/components/src/schema/props/toolbar-items.ts Replaced inline object check with isObject
packages/components/src/schema/props/table-data.ts Replaced inline object check with isObject
packages/components/src/schema/props/table-data-foot.ts Replaced inline object check with isObject
packages/components/src/schema/props/table-callbacks.ts Inlined watchValidator call to use isObject
packages/components/src/schema/props/popover-callbacks.ts Swapped inline object check for isObject
packages/components/src/schema/props/options.ts Swapped inline object check for isObject
packages/components/src/schema/props/icons.ts Added KoliBriAllIcons type and swapped object checks
packages/components/src/schema/props/details-callbacks.ts Swapped inline object check for isObject
packages/components/src/schema/props/button-callbacks.ts Swapped inline object check for isObject
packages/components/src/schema/props/accordion-callbacks.ts Swapped inline object check for isObject
Comments suppressed due to low confidence (2)

packages/components/src/schema/validators/common.ts:1

  • Consider adding unit tests for the isObject type guard to verify correct narrowing behavior for various inputs (e.g., arrays, functions, primitives, null).
export const isObject = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null;

packages/components/src/schema/props/icons.ts:28

  • The code uses isObject (and later isString) but neither is imported in this file. Please add import { isObject, isString } from '../validators'; to avoid runtime errors.
	if (isObject(icon)) {

@deleonio deleonio marked this pull request as ready for review July 15, 2025 12:04
@deleonio deleonio merged commit 9aece38 into release/2 Jul 15, 2025
11 checks passed
@deleonio deleonio deleted the feature/optimize-duplicate-conditions-in-context branch July 15, 2025 14:08
@publicuibot publicuibot bot locked and limited conversation to collaborators Jul 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants