Skip to content

Conversation

@dfsmania
Copy link
Contributor

Refactor layout transition handling and initialization logic

This PR refactors the AdminLTE v4 layout logic to fix incorrect transition handling, remove duplicated event listeners, and clearly separate responsibilities between initialization and runtime behavior.

Summary of changes

1. Removed duplicated resize listeners

  • The resize event listener was previously:

    • registered inside Layout.holdTransition()
    • invoked from multiple entry points
  • This caused:

    • duplicated listeners
    • unpredictable execution order
    • unnecessary re-registration on each call

The resize listener is now registered once, during layout initialization.

2. Fixed incorrect holdTransition() logic

The previous implementation had a critical flaw:

  • resizeTimer was defined as a local variable
  • clearTimeout(resizeTimer) was ineffective across calls
  • Each resize created a new timer reference, defeating its purpose

New behavior:

  • Layout now owns a persistent _holdTransitionTimer
  • Any pending timer is properly cleared before starting a new one
  • Transitions are reliably held and released

This makes holdTransition() deterministic and correct.

3. Clear responsibility for holdTransition()

holdTransition() now does exactly one thing:

  • Temporarily disables layout transitions for a given duration

It no longer:

  • registers event listeners
  • depends on resize side effects
  • mixes setup with behavior

This makes the method reusable and predictable.

4. Resize logic moved to initialization phase

  • Window resize handling is now defined in the Data API section
  • Resize simply calls layout.holdTransition(200)
  • The layout class no longer manages global events

This keeps lifecycle concerns outside the core class.

5. Layout initialization cleaned up in adminlte.ts

  • Removed duplicated layout initialization logic
  • Layout setup now happens in a single place (layout.ts)
  • Avoids creating multiple layout instances with overlapping responsibilities

6. App loaded state handled consistently

  • The app-loaded class is now applied from the layout initialization logic
  • Prevents scattered timing logic across multiple files
  • Makes layout readiness easier to reason about

Why this change?

The previous layout implementation:

  • mixed event registration and behavior
  • contained broken timeout logic
  • created multiple resize listeners
  • duplicated layout initialization across files

This refactor:

  • fixes real bugs
  • simplifies the mental model
  • improves maintainability
  • aligns layout behavior with a clean, instance-based design

No visual or behavioral regressions are expected—only more predictable and correct transition handling.

@netlify
Copy link

netlify bot commented Dec 26, 2025

Deploy Preview for adminlte-v4 ready!

Name Link
🔨 Latest commit 2c76db2
🔍 Latest deploy log https://app.netlify.com/projects/adminlte-v4/deploys/694f1129d4e91900083d87b7
😎 Deploy Preview https://deploy-preview-5956--adminlte-v4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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.

1 participant