Skip to content

refactor(theme-controller): Document and simplify theme application logic#2115

Merged
rkaraivanov merged 4 commits intomasterfrom
rkaraivanov/theming-controller
Feb 26, 2026
Merged

refactor(theme-controller): Document and simplify theme application logic#2115
rkaraivanov merged 4 commits intomasterfrom
rkaraivanov/theming-controller

Conversation

@rkaraivanov
Copy link
Member

Description

  • This commit cleans up some of the internal logic of the ThemingController, particularly around how themes are applied when context changes. It removes some redundant state management.
  • The commit also adds documentation of the ThemingController class and the exported factory function, explaining their purpose and usage.

Type of Change

  • Documentation update
  • Refactoring (code improvements without functional changes)

Checklist

  • My code follows the project's coding standards
  • I have tested my changes locally

…ogic

- This commit cleans up some of the internal logic of the ThemingController,
particularly around how themes are applied when context changes.
It removes some redundant state management.
- The commit also adds documentation of the ThemingController
class and the exported factory function, explaining their purpose and usage.
Copy link
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 and documents the ThemingController class to improve code clarity and maintainability. The changes focus on simplifying theme application logic by consolidating redundant code paths and adding comprehensive JSDoc documentation.

Changes:

  • Added detailed JSDoc documentation for the ThemingController class and addThemingController factory function
  • Refactored theme application logic by extracting common code into a new _applyTheme method
  • Simplified _adoptStyles method by removing the intermediate _getStyles method

Copy link
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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

…ogic

Simplifies the theme provider and controller lifecycle management to improve
reliability when components are dynamically added or moved in the DOM tree.

Theme Provider Changes:
- Move ContextProvider initialization from constructor to class field initializer
- Remove constructor entirely (no longer needed)
- Remove firstUpdated lifecycle method that redundantly set provider value
- Consolidate theme/variant updates in the update() lifecycle method

Theming Controller Changes:
- Simplify hostConnected to always apply global theme first
  - Context providers synchronously invoke callbacks before first update cycle
  - This ensures correct theme resolution for dynamically created components
- Add proper state cleanup in hostDisconnected:
  - Reset _themeSource to 'uninitialized'
  - Clear _contextConsumer value
  - Allows components to properly re-resolve theme when reconnected elsewhere
- Improve inline documentation explaining the theme resolution logic

Test Improvements:
- Add comprehensive variant assertions throughout all test cases
- Enhance component reconnection test with proper validation:
  - Tests moving component from inside provider to outside
  - Tests moving component back inside provider
  - Verifies theme source switches correctly in both directions

These changes ensure that components correctly pick up theme context when:
- Created inside an existing theme provider
- Moved between different parts of the DOM tree
- Moved in or out of theme provider scope
Copy link
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@rkaraivanov rkaraivanov merged commit d2be843 into master Feb 26, 2026
6 checks passed
@rkaraivanov rkaraivanov deleted the rkaraivanov/theming-controller branch February 26, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants