Skip to content

Web Components Lifecycle#405

Merged
cubap merged 35 commits intomainfrom
401-auth-permissions-render
Feb 2, 2026
Merged

Web Components Lifecycle#405
cubap merged 35 commits intomainfrom
401-auth-permissions-render

Conversation

@thehabes
Copy link
Member

@thehabes thehabes commented Jan 28, 2026

Summary

This PR standardizes the web component lifecycle across 70+ components and introduces a comprehensive memory leak prevention system. It addresses three related issues:

Changes

New Utilities

  • utilities/CleanupRegistry.js - Centralized event listener and resource cleanup management

    • cleanup.onEvent() - TPEN eventDispatcher listeners
    • cleanup.onWindow() - Window event listeners
    • cleanup.onDocument() - Document event listeners
    • cleanup.onElement() - DOM element listeners
    • cleanup.addObserver() - ResizeObserver cleanup
    • cleanup.addMutationObserver() - MutationObserver cleanup
    • cleanup.add() - Custom cleanup functions (timers, etc.)
  • utilities/projectReady.js - Unified project loading handler that works whether project is already loaded or loads later

Standardized Component Lifecycle

All components now follow this pattern:

connectedCallback() → onProjectReady() → authgate() →  render() → addEventListeners() → disconnectedCallback()

Key Conventions:

  1. connectedCallback(), render(), and authgate() are synchronous
  2. Async work delegated to separate methods like initializeAsync()
  3. All event listeners use CleanupRegistry for automatic cleanup
  4. TPEN.attachAuthentication(this) called in connectedCallback()
  5. Permission checks via CheckPermissions in authgate()

Dual Cleanup Pattern

Components that re-render use two registries:

  • cleanup - For persistent listeners (window, document, eventDispatcher)
  • renderCleanup - For render-specific listeners, cleared before each re-render
addEventListeners() {
    this.renderCleanup.run()  // Clear previous listeners
    this.renderCleanup.onElement(btn, 'click', handler)
}

Memory Leak Prevention

  • All addEventListener calls now tracked for cleanup
  • setTimeout/setInterval tracked where applicable
  • onProjectReady subscriptions properly unsubscribed
  • Observers (Resize, Mutation) disconnected on component removal
  • Guard patterns prevent duplicate listener registration

Permission-Based Rendering

  • Components check permissions before rendering
  • renderPermissionError() utility for consistent error display
  • Features hidden/disabled based on user permissions
  • Navigation links only shown to users with appropriate access

Files Changed

Category Count
Components updated 66
Interfaces updated 4
New utilities 2
Documentation 1

Testing

  • Manual testing of component lifecycle
  • Verify no console errors on page navigation
  • Check memory usage doesn't grow on repeated actions
  • Verify permission-based UI changes work correctly

Documentation

Updated .claude/CLAUDE.md with:

  • Standard component template
  • CleanupRegistry usage guide
  • Dual cleanup pattern explanation
  • When to use renderCleanup vs guards

🤖 Generated with Claude Code

@thehabes thehabes self-assigned this Jan 28, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 28, 2026

This comment was marked as resolved.

@thehabes thehabes added enhancement New feature or request core functionality component web component interface for users labels Jan 28, 2026

This comment was marked as resolved.

@thehabes thehabes requested a review from Copilot January 29, 2026 00:31

This comment was marked as resolved.

This comment was marked as resolved.

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

This comment was marked as resolved.

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 77 out of 77 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@thehabes thehabes marked this pull request as ready for review January 30, 2026 16:37
@thehabes thehabes requested a review from cubap January 30, 2026 16:37
@cubap cubap merged commit 7529cd8 into main Feb 2, 2026
2 checks passed
@cubap cubap deleted the 401-auth-permissions-render branch February 2, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component web component interface for users core functionality enhancement New feature or request

Projects

None yet

2 participants