Skip to content

Remove animation package#6812

Open
DerekLiang wants to merge 10 commits into
valor-software:developmentfrom
DerekLiang:remove-animation-package
Open

Remove animation package#6812
DerekLiang wants to merge 10 commits into
valor-software:developmentfrom
DerekLiang:remove-animation-package

Conversation

@DerekLiang
Copy link
Copy Markdown
Contributor

Summary

  • Per Angular official doc https://angular.dev/api/animations/animation, @angular/animations is deprecated.
  • Removes @angular/animations (and BrowserAnimationsModule) as a peer dependency entirely, eliminating the requirement to provide BrowserAnimationsModule in zoneless Angular applications
  • Replaces all Angular animation triggers in collapse, dropdown, datepicker, and typeahead with native CSS height transitions driven by requestAnimationFrame + transitionend — the same pattern Angular's own migration guide recommends
  • All transitionend handlers guard against bubbled child events (e.target + e.propertyName checks) and are properly cleaned up in ngOnDestroy
  • Schematics updated to no longer inject BrowserAnimationsModule on ng add
  • Fix animation issues (all animations are broken) that caused by zoneless migration

Motivation

@angular/animations is deprecated as of Angular v20.2 and is incompatible with zoneless change detection — components using AnimationBuilder trigger zone re-entry via internal setTimeout/requestAnimationFrame calls, breaking zoneless apps. This was reported in issues #6784 and #6808.

What changed (high level)

All Angular @angular/animations usage (AnimationBuilder, AnimationFactory, AnimationPlayer, trigger, state, transition, animate) has been removed. Every component now drives animation via the browser's native
CSS transition engine, set imperatively with Renderer2.


Component-by-component

  1. Collapse (collapse.directive.ts)

CSS transition on height.

  • AnimationBuilder/AnimationPlayer removed from the constructor.
  • animationRun() now applies transition: height 400ms cubic-bezier(0.4,0.0,0.2,1) directly to the element via Renderer2.
  • Three cases handled:
    • Mid-animation reversal — snapshots current rendered height with getBoundingClientRect(), forces a synchronous reflow (offsetHeight), then flips to the opposite target.
    • Expand (fresh) — sets height: 0, reflows, then one requestAnimationFrame defers setting height: scrollHeight so Chrome registers the 0px start state before the first paint.
    • Collapse (fresh) — two nested requestAnimationFrame calls: first pins at scrollHeight, second sets height: 0. Needed because a forced reflow inside a rAF callback is not a reliable transition "before-change"
      checkpoint across all browsers.
  • transitionend signals completion; a 450ms setTimeout fallback clears stuck state if the event never fires.
  1. Dropdown (bs-dropdown-container.component.ts)

CSS transition on height. No rAF.

  • AnimationBuilder/AnimationFactory removed.
  • height: 0; overflow: hidden are applied before the .show class is added, so Bootstrap's display: block never paints the element at its natural height (fixes the ~20px flash glitch).
  • _animateExpand() then applies the transition, forces a synchronous reflow (offsetHeight) to lock height: 0 as the "before-change" state, then immediately sets height: scrollHeight — the CSS engine animates
    from there.
  • No requestAnimationFrame — the synchronous reflow is sufficient here since the initial state is already painted.
  • transitionend (with { once: true }) + 270ms fallback setTimeout handles cleanup.
  1. Typeahead (typeahead-container.component.ts)

CSS transition on max-height. No rAF.

  • typeaheadAnimation trigger removed from @Component.animations and [@typeaheadAnimation] removed from the template.
  • Uses max-height (not height) to avoid conflict with the [style.height] host binding.
  • Constructor sets max-height: 0; overflow: hidden immediately so the element is hidden before the position service fires.
  • On the first position-service event, _animateExpand() applies the transition, forces a reflow (offsetHeight), then sets max-height: scrollHeight — CSS takes over.
  • No requestAnimationFrame — same reasoning as dropdown.
  • transitionend (with { once: true }) + 270ms fallback setTimeout handles cleanup.
  1. Datepicker (bs-datepicker-container, bs-daterangepicker-container, inline variants)

Angular animations removed from the animations metadata array — these components did not have a custom expand/collapse animation to replace, so no CSS transition logic was added.


rAF usage status

Component rAF present Why
Collapse — expand path 1 rAF Defers target height so browser paints 0px start state first
Collapse — collapse path 2 nested rAFs Cross-browser reliability: reflow inside rAF isn't a guaranteed "before-change" checkpoint
Dropdown None Synchronous offsetHeight reflow is sufficient
Typeahead None Synchronous offsetHeight reflow is sufficient

rAF is not driving any animation — in all cases the CSS transition engine owns the interpolation. rAF is purely a scheduling tool to ensure the browser has committed a concrete "before" paint state before the
target value is written.

DerekLiang and others added 10 commits November 1, 2024 23:59
* 20.0.2

* Upgrade angular 21 (valor-software#6788)

* chore: upgrade package

* chore(ngx-bootstrap-docs): updates Angular to v21

* refactor: migrate common-docs HTML templates to Angular control flow

* chore: update common-docs TypeScript configuration

* fix: add type guard for event target in ExamplesComponent

* chore(tsconfig): update compiler options for new build setup

* refactor(accordion): migrate HTML templates to new control flow syntax

* refactor(alerts): migrate HTML templates to new control flow syntax

* refactor(buttons): migrate HTML templates to new control flow syntax

* refactor(carousel): migrate HTML templates to new control flow syntax

* refactor(datepicker): migrate HTML templates to new control flow syntax

* refactor: update Angular template control flow syntax to `@for` and `@if`

* chore(tsconfig): update TypeScript configuration for modern Angular

* build: update root tsconfig for doc pages to support new module resolution

* build: standardize and update tsconfig.lib.json for doc pages libraries

* build: standardize and update tsconfig.spec.json for doc pages tests

* refactor: migrate doc page templates to Angular control flow syntax

* refactor(build): update TypeScript and Jest configurations

* refactor(buttons): widen HostListener event types to generic Event

* chore: migrate templates to  built-in control flow

* refactor: remove redundant @angular/common imports

* chore: migrate component templates to new Angular control flow syntax

* chore: modernize TypeScript and Jest configurations across libraries

* test: update jest-preset-angular serializer paths

* test: standardize Jest Zone.js test environment setup

* refactor(jest): update configuration for Nx and jest-preset-angular

* test(typeahead): update Jest 'toThrowError' to 'toThrow' matcher

* fix(typeahead): correct test file formatting and syntax

* chore: update package-lock.json dependencies and properties

* refactor: standardize TypeScript and Jest configurations across libraries

* refactor: improve event handling type safety and robustness

* chore: migrate Angular templates to new control flow syntax

* test(carousel): add CommonModule to carousel test component

* chore: bump version to 21.0.0

* chore(release): bump project version to 21.0.0

* fix(typeahead): prevents potential null reference

* fix(dependencies): fixed package.lock

* fix(dependencies): fixed app.component

* Update package.json

* Update package-lock.json

---------

Co-authored-by: Amine CHERGUI <chergui.amine@gmail.com>
…ropdown and collapse components

- Removed Angular animation imports and definitions from collapse and dropdown components.
- Implemented CSS transitions for collapse and dropdown animations using `requestAnimationFrame` and `setTimeout` for fallback handling.
- Updated tests to remove dependencies on `BrowserAnimationsModule`.
- Refactored datepicker and typeahead components to use similar CSS transition logic.
- Improved performance and reduced complexity by eliminating the need for Angular's animation builder.
@DerekLiang
Copy link
Copy Markdown
Contributor Author

@lexasq could you please provide feedback again. rAF is removed as much as possible. thx

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