Skip to content

refactor: remove unused imports, NgClass cleanup#43

Merged
kathari00 merged 1 commit intokeycloakify:mainfrom
lekhmanrus:refactor/no-ref/remove-unused-imports-and-ngclass-cleanup
Oct 16, 2025
Merged

refactor: remove unused imports, NgClass cleanup#43
kathari00 merged 1 commit intokeycloakify:mainfrom
lekhmanrus:refactor/no-ref/remove-unused-imports-and-ngclass-cleanup

Conversation

@lekhmanrus
Copy link
Copy Markdown
Contributor

@lekhmanrus lekhmanrus commented Oct 16, 2025

Summary by CodeRabbit

  • Refactor

    • Optimized import statements across account and login modules for better tree-shaking and reduced bundle size.
    • Removed unused component dependencies and directives, streamlining component metadata.
    • Improved component dependency injection with enhanced type safety.
  • Style

    • Simplified template binding syntax for conditional CSS class application, improving code consistency and maintainability.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Oct 16, 2025

Walkthrough

This PR refactors the codebase to improve tree-shaking and type safety by converting regular type imports to TypeScript type-only imports, replacing NgClass directive usage with direct class bindings, removing unused directives and pipes, and adding generic type parameters to dependency injection calls for stricter type narrowing.

Changes

Cohort / File(s) Summary
Type-only import conversions (i18n and context types)
src/account/i18n/i18n.ts, src/login/i18n/i18n.ts, src/account/providers/keycloakify-angular/keycloakify-angular.providers.ts, src/login/providers/keycloakify-angular/keycloakify-angular.providers.ts, src/login/services/login-resource-injector/login-resource-injector.service.ts
Converts imports to use TypeScript's type-only syntax (e.g., import type { MessageKey } instead of import { type MessageKey }), enabling better tree-shaking by preventing runtime imports of types.
Type-only imports in login components
src/login/components/add-remove-buttons-multi-valued-attribute/..., src/login/components/field-errors/..., src/login/components/group-label/..., src/login/components/input-field-by-type/..., src/login/components/input-tag-selects/..., src/login/components/input-tag/..., src/login/components/password-wrapper/..., src/login/components/select-tag/..., src/login/components/textarea-tag/...
Converts Attribute, FormFieldError, and FormAction imports to type-only form across multiple form components.
Type-only Script imports
src/login/pages/login-passkeys-conditional-authenticate/..., src/login/pages/webauthn-authenticate/..., src/login/pages/webauthn-register/...
Changes Script import from runtime to type-only form for authentication-related pages.
NgClass removal from component decorators
src/account/pages/account/..., src/account/pages/applications/..., src/account/pages/federatedIdentity/..., src/account/pages/log/..., src/account/pages/password/..., src/account/pages/sessions/..., src/account/pages/totp/..., src/login/pages/login-username/..., src/login/pages/login/..., src/login/pages/select-authenticator/...
Removes NgClass from component imports arrays, reducing directive dependencies.
NgClass template binding replacement
src/account/pages/account/account.component.html, src/account/template/template.component.html
Replaces [ngClass]="{ active: condition }" with [class.active]="condition" and similar direct class bindings for form validation error states and active navigation states.
KcClassDirective removal
src/account/template/template.component.ts, src/login/pages/login-idp-link-email/..., src/login/pages/login-verify-email/...
Removes KcClassDirective imports and usage from component metadata.
Unused pipe/component removals
src/login/components/password-wrapper/... (AsyncPipe), src/login/pages/webauthn-authenticate/... (LogoutOtherSessionsComponent), src/login/pages/webauthn-error/... (LogoutOtherSessionsComponent)
Removes unused AsyncPipe and LogoutOtherSessionsComponent imports from specific pages.
Empty imports array cleanup
src/login/pages/login-page-expired/..., src/login/pages/saml-post-form/...
Removes empty imports: [] property from @component decorators.
Inject type parameter additions
src/bin/initialize-account-theme/boilerplate/KcPageStory.ts, stories/account/KcPageStory.ts, stories/account/pages/KcPageStory.ts
Adds generic type parameter to inject calls: inject<KcContext>(KC_ACCOUNT_CONTEXT) for stricter type narrowing on dependency injection.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

The changes are highly homogeneous and repetitive across the codebase—primarily import syntax conversions, directive removals, and template binding replacements. Each modification follows a consistent pattern with no complex logic changes, branching conditions, or state management alterations. The scope spans multiple files, but the uniform nature of changes (template binding swaps, type-only imports, decorator cleanup) reduces cognitive load per file.

Poem

🐰 A hop through the code, so clean and so bright,
Type-only imports make the bundle light,
NgClass says goodbye, class bindings take flight,
Dependencies trimmed, the tree-shake's just right!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "refactor: remove unused imports, NgClass cleanup" accurately reflects the primary focus of the changeset. The PR demonstrates a comprehensive refactoring effort centered on two main themes: (1) removing NgClass from multiple component imports and replacing ngClass template bindings with modern Angular class bindings across account and login modules, and (2) removing various unused imports including AsyncPipe, KcClassDirective, and LogoutOtherSessionsComponent from specific components. Additionally, numerous type-only import conversions are applied throughout to optimize the import statements. The title is concise, clear, and directly captures the core refactoring objectives without unnecessary noise.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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: 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 7d16c4b and 2918b1a.

📒 Files selected for processing (38)
  • src/account/i18n/i18n.ts (1 hunks)
  • src/account/pages/account/account.component.html (4 hunks)
  • src/account/pages/account/account.component.ts (1 hunks)
  • src/account/pages/applications/applications.component.ts (2 hunks)
  • src/account/pages/federatedIdentity/federatedIdentity.component.ts (0 hunks)
  • src/account/pages/log/log.component.ts (2 hunks)
  • src/account/pages/password/password.component.ts (1 hunks)
  • src/account/pages/sessions/sessions.component.ts (1 hunks)
  • src/account/pages/totp/totp.component.ts (1 hunks)
  • src/account/providers/keycloakify-angular/keycloakify-angular.providers.ts (2 hunks)
  • src/account/template/template.component.html (1 hunks)
  • src/account/template/template.component.ts (1 hunks)
  • src/bin/initialize-account-theme/boilerplate/KcPageStory.ts (2 hunks)
  • src/login/components/add-remove-buttons-multi-valued-attribute/add-remove-buttons-multi-valued-attribute.component.ts (1 hunks)
  • src/login/components/field-errors/field-errors.component.ts (1 hunks)
  • src/login/components/group-label/group-label.component.ts (1 hunks)
  • src/login/components/input-field-by-type/input-field-by-type.component.ts (1 hunks)
  • src/login/components/input-tag-selects/input-tag-selects.component.ts (1 hunks)
  • src/login/components/input-tag/input-tag.component.ts (1 hunks)
  • src/login/components/password-wrapper/password-wrapper.component.ts (1 hunks)
  • src/login/components/select-tag/select-tag.component.ts (1 hunks)
  • src/login/components/textarea-tag/textarea-tag.component.ts (1 hunks)
  • src/login/i18n/i18n.ts (1 hunks)
  • src/login/pages/login-idp-link-email/login-idp-link-email.component.ts (0 hunks)
  • src/login/pages/login-page-expired/login-page-expired.component.ts (0 hunks)
  • src/login/pages/login-passkeys-conditional-authenticate/login-passkeys-conditional-authenticate.component.ts (1 hunks)
  • src/login/pages/login-username/login-username.component.ts (1 hunks)
  • src/login/pages/login-verify-email/login-verify-email.component.ts (0 hunks)
  • src/login/pages/login/login.component.ts (2 hunks)
  • src/login/pages/saml-post-form/saml-post-form.component.ts (0 hunks)
  • src/login/pages/select-authenticator/select-authenticator.component.ts (1 hunks)
  • src/login/pages/webauthn-authenticate/webauthn-authenticate.component.ts (2 hunks)
  • src/login/pages/webauthn-error/webauthn-error.component.ts (1 hunks)
  • src/login/pages/webauthn-register/webauthn-register.component.ts (1 hunks)
  • src/login/providers/keycloakify-angular/keycloakify-angular.providers.ts (1 hunks)
  • src/login/services/login-resource-injector/login-resource-injector.service.ts (1 hunks)
  • stories/account/KcPageStory.ts (2 hunks)
  • stories/account/pages/KcPageStory.ts (2 hunks)
💤 Files with no reviewable changes (5)
  • src/login/pages/saml-post-form/saml-post-form.component.ts
  • src/account/pages/federatedIdentity/federatedIdentity.component.ts
  • src/login/pages/login-idp-link-email/login-idp-link-email.component.ts
  • src/login/pages/login-verify-email/login-verify-email.component.ts
  • src/login/pages/login-page-expired/login-page-expired.component.ts
🧰 Additional context used
🧬 Code graph analysis (1)
stories/account/KcPageStory.ts (2)
stories/account/KcContext.ts (1)
  • KcContext (11-11)
stories/login/KcContext.ts (1)
  • KcContext (11-11)
🔇 Additional comments (35)
src/login/components/textarea-tag/textarea-tag.component.ts (1)

6-8: Type-only import change looks good

Line 6 and Line 8 now correctly use import type, avoiding runtime bundles for pure typings and aligning with Angular 20/TS best practices.

src/login/components/group-label/group-label.component.ts (1)

8-8: LGTM! Type-only import improves tree-shaking.

Converting to import type is correct since Attribute is only used as a type annotation. This enables the TypeScript compiler to elide the import from the emitted JavaScript, improving bundle size and tree-shaking efficiency.

src/login/components/password-wrapper/password-wrapper.component.ts (1)

20-20: LGTM! AsyncPipe removal aligns with signals-based approach.

The removal of AsyncPipe from the imports is appropriate since the component uses signals (WritableSignal) for state management rather than observables. This reduces the runtime dependency surface without affecting functionality and aligns with modern Angular v20 patterns.

src/login/pages/login/login.component.ts (1)

19-19: Import cleanup looks good.

Pulling in CommonModule keeps the template directives/pipes available after dropping the individual AsyncPipe/NgClass imports. No issues spotted.

src/login/pages/webauthn-error/webauthn-error.component.ts (1)

13-13: Confirm removal of unused import: no <kc-logout-other-sessions> selector found in webauthn-error.component.html, so removing LogoutOtherSessionsComponent is safe.

src/login/pages/select-authenticator/select-authenticator.component.ts (1)

13-13: LGTM – select-authenticator.component.html has no [ngClass] usage; removing the NgClass import is safe.

src/account/pages/totp/totp.component.ts (1)

14-14: LGTM! NgClass removal is consistent with the refactor.

The removal of NgClass from the imports array aligns with the PR objectives to simplify class bindings and reduce the directive surface. KcClassDirective and KcSanitizePipe remain as the necessary dependencies for this component.

src/account/pages/password/password.component.ts (1)

13-13: LGTM! Consistent NgClass removal.

The removal of NgClass from the component's imports is consistent with the broader refactor across account pages, simplifying the dependency graph while retaining KcClassDirective for class management.

src/login/components/input-field-by-type/input-field-by-type.component.ts (1)

12-12: LGTM! Improved tree-shaking with type-only import.

Converting to import type { Attribute } correctly eliminates the runtime import since Attribute is only used as a type annotation (lines 35, 42-43). This change improves tree-shaking capabilities and aligns with TypeScript best practices.

src/login/components/input-tag/input-tag.component.ts (1)

15-15: LGTM! Type-only import for better tree-shaking.

The conversion to import type { Attribute } is correct since Attribute is used exclusively as a type annotation (lines 47, 42). This improves tree-shaking and follows the pattern established in other login components.

src/account/pages/sessions/sessions.component.ts (1)

13-13: LGTM! Consistent with the NgClass cleanup.

The removal of NgClass from the imports follows the same pattern as other account pages, reducing the directive surface while maintaining KcClassDirective for class management.

src/account/pages/applications/applications.component.ts (1)

1-1: LGTM! Selective import cleanup.

The removal of NgClass while retaining KeyValuePipe and IsArrayWithEmptyObjectPipe demonstrates selective cleanup of unused imports. This approach correctly targets only the unused NgClass directive while preserving the pipes that are actively used in the component.

Also applies to: 15-15

src/login/providers/keycloakify-angular/keycloakify-angular.providers.ts (1)

15-15: LGTM! Type-only import for provider configuration.

Converting to import type { KcContextLike } is correct since KcContextLike is used exclusively as a type constraint in the configuration interface (line 23). This improves tree-shaking for the provider configuration module.

src/account/pages/log/log.component.ts (1)

1-1: LGTM! Selective removal of unused NgClass.

The removal of NgClass while retaining DatePipe correctly targets only the unused directive. This completes the consistent pattern of NgClass cleanup across all account page components.

Also applies to: 14-14

src/login/components/input-tag-selects/input-tag-selects.component.ts (1)

5-5: LGTM! Type-only imports improve tree-shaking.

Converting these imports to type-only form is correct since FormAction, FormFieldError, and Attribute are only used in type positions. This ensures they won't appear in the runtime bundle.

Also applies to: 8-8

src/login/components/field-errors/field-errors.component.ts (1)

5-5: LGTM! Consistent type-only import pattern.

The conversion to type-only imports is appropriate and aligns with the pattern established across other login components.

Also applies to: 7-7

src/login/components/add-remove-buttons-multi-valued-attribute/add-remove-buttons-multi-valued-attribute.component.ts (1)

4-4: LGTM! Appropriate use of type-only import.

The Attribute type is correctly imported as type-only since it's used solely in the type position of the attribute input.

src/login/i18n/i18n.ts (1)

2-2: LGTM! Type-only import for type alias.

Correctly converted to type-only import since MessageKey_defaultSet is used exclusively in the type alias definition.

src/account/i18n/i18n.ts (1)

2-2: LGTM! Consistent pattern with login i18n.

This change mirrors the type-only import pattern applied in src/login/i18n/i18n.ts.

src/account/providers/keycloakify-angular/keycloakify-angular.providers.ts (2)

14-14: LGTM! Type-only import for interface.

KcContextLike is correctly imported as type-only since it's used only in the getI18n function signature.


42-42: LGTM! Generic type parameter improves type narrowing.

Using inject<KcContext>(KC_ACCOUNT_CONTEXT) provides stricter type narrowing compared to the annotation-style approach and is the preferred Angular pattern.

src/login/components/select-tag/select-tag.component.ts (1)

6-6: LGTM! Consistent type-only imports.

The conversion to type-only imports follows the established pattern across login components.

Also applies to: 9-9

src/account/template/template.component.ts (1)

34-34: LGTM! Removal aligns with NgClass cleanup.

Removing KcClassDirective from the component's imports is appropriate if the template has been updated to use direct class bindings instead. Based on the PR summary, the corresponding template changes have been made.

src/account/pages/account/account.component.ts (1)

14-14: LGTM! Improved tree-shaking by removing NgClass.

The removal of NgClass from imports aligns with the template's migration to [class.has-error] bindings, reducing the bundle size through better tree-shaking.

src/account/pages/account/account.component.html (1)

30-30: LGTM! Modern Angular class binding pattern.

The migration from [ngClass]="{ 'has-error': ... }" to [class.has-error]="..." is the recommended Angular approach for single-class conditionals, providing better performance and readability.

Also applies to: 59-59, 85-85, 110-110

stories/account/KcPageStory.ts (2)

3-3: LGTM! Type-only import improves tree-shaking.

The conversion to import type ensures KcContext is erased at runtime, resulting in a smaller bundle.


37-37: LGTM! Generic type parameter improves type safety.

Adding the generic type parameter inject<KcContext>(...) provides explicit type narrowing without relying on type inference, making the code more maintainable and catching type errors earlier.

stories/account/pages/KcPageStory.ts (1)

3-3: LGTM! Consistent refactoring pattern.

The type-only import and generic inject<KcContext>() follow the same improvement pattern applied across the codebase, providing better tree-shaking and type safety.

Also applies to: 58-58

src/account/template/template.component.html (1)

69-69: LGTM! Appropriate use of class binding patterns.

The migration to [class.active] for single-class conditionals is correct. Note that line 106 appropriately retains [ngClass] for the dynamic multi-class binding ['alert', 'alert-' + message.type], demonstrating good judgment on when each pattern is appropriate.

Also applies to: 73-73, 77-77, 81-81, 85-85, 88-88, 92-92, 97-97

src/bin/initialize-account-theme/boilerplate/KcPageStory.ts (1)

3-3: LGTM! Boilerplate reflects best practices.

These improvements in the boilerplate file ensure that newly initialized projects start with the latest best practices for tree-shaking and type safety.

Also applies to: 58-58

src/login/pages/login-passkeys-conditional-authenticate/login-passkeys-conditional-authenticate.component.ts (1)

2-2: LGTM! Type-only import improves tree-shaking.

The conversion to import type syntax correctly signals that Script is used only as a type annotation, enabling better tree-shaking by the bundler.

src/login/pages/webauthn-register/webauthn-register.component.ts (1)

2-2: LGTM! Type-only import improves tree-shaking.

The conversion to import type syntax correctly signals that Script is used only as a type annotation, enabling better tree-shaking by the bundler.

src/login/services/login-resource-injector/login-resource-injector.service.ts (1)

6-6: LGTM! Type-only import improves tree-shaking.

The conversion to import type syntax correctly signals that Script is used only as a type annotation, enabling better tree-shaking by the bundler.

src/login/pages/webauthn-authenticate/webauthn-authenticate.component.ts (2)

2-2: LGTM! Type-only import improves tree-shaking.

The conversion to import type syntax correctly signals that Script is used only as a type annotation, enabling better tree-shaking by the bundler.


15-15: Confirm removal of LogoutOtherSessionsComponent is correct
No kc-logout-other-sessions selector in webauthn-authenticate.component.html and no import in the component — removal is safe.

templateUrl: 'login-username.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [KcClassDirective, AsyncPipe, KcSanitizePipe, NgClass],
imports: [KcClassDirective, KcSanitizePipe],
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

LGTM! Verify the template doesn't reference removed imports.

The removal of AsyncPipe and NgClass aligns with the PR objectives. The component uses Signals (line 42) instead of Observables, making AsyncPipe unnecessary. The custom KcClassDirective appears to handle class bindings.

Run the following script to confirm the template doesn't use the removed imports:


🏁 Script executed:

#!/bin/bash
# Description: Verify that the template doesn't use async pipe or ngClass directive.

# Check for async pipe usage in the template
echo "Checking for async pipe usage..."
if fd -e html "login-username.component.html" --exec grep -n "| async" {}; then
  echo "WARNING: Found async pipe usage in template"
else
  echo "✓ No async pipe usage found"
fi

echo ""

# Check for ngClass directive usage in the template
echo "Checking for ngClass directive usage..."
if fd -e html "login-username.component.html" --exec grep -nE '\[ngClass\]|ngClass=' {}; then
  echo "WARNING: Found ngClass directive usage in template"
else
  echo "✓ No ngClass directive usage found"
fi

Length of output: 272



🏁 Script executed:

#!/bin/bash
# Verify the component's imports and see what changed
echo "Component imports at line 17:"
grep -A 2 "imports:" src/login/pages/login-username/login-username.component.ts | head -5

echo ""
echo "Searching for KcClassDirective definition..."
fd -e ts -e js --exec grep -l "KcClassDirective" {} \; 2>/dev/null | head -5

echo ""
echo "Checking full component decorator:"
sed -n '/@Component/,/^}\s*$/p' src/login/pages/login-username/login-username.component.ts | head -30

Length of output: 1807


🏁 Script executed:

#!/bin/bash
# Check if NgClass is required for [ngClass] bindings in Angular
# (This is general Angular knowledge that doesn't require repo access)
echo "Angular's [ngClass] directive requires NgClass import from @angular/common"
echo "ngClass bindings will fail at runtime if NgClass is not imported."

Length of output: 140


🏁 Script executed:

#!/bin/bash
# Verify the component's imports to see if NgClass was removed
echo "=== Component decorator section ==="
sed -n '/@Component/,/^}\s*$/p' src/login/pages/login-username/login-username.component.ts

echo ""
echo "=== Looking for KcClassDirective definition ==="
fd -e ts --exec grep -l "directive\|export.*class.*KcClassDirective" {} \; 2>/dev/null | head -3

echo ""
echo "=== Checking template file for full ngClass context ==="
sed -n '50,65p' src/login/pages/login-username/login-username.component.html

Length of output: 2428


Re-add NgClass to component imports
Template uses [ngClass] bindings (lines 54, 59); import NgClass from @angular/common in the component’s imports array (e.g. imports: [NgClass, KcClassDirective, KcSanitizePipe]).

🤖 Prompt for AI Agents
In src/login/pages/login-username/login-username.component.ts around line 17,
the component uses [ngClass] in the template but NgClass was not included in the
component's imports array; add NgClass imported from @angular/common to the
imports array alongside KcClassDirective and KcSanitizePipe (e.g. imports:
[NgClass, KcClassDirective, KcSanitizePipe]) and ensure the top-of-file import
statement imports NgClass from '@angular/common'.

@kathari00
Copy link
Copy Markdown
Collaborator

Thanks for cleaning up and keeping the syntax updated!

@kathari00 kathari00 merged commit 3dd6f8d into keycloakify:main Oct 16, 2025
1 check passed
@coderabbitai coderabbitai bot mentioned this pull request Nov 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants