lentschi / ngx-ellipsis

Multiline text with ellipsis for angular 9+
MIT License
96 stars 22 forks source link

Window resize event leak #49

Closed bjarketrux closed 3 years ago

bjarketrux commented 3 years ago

There seems to be an event leak which results in exponential calls to applyEllipsis() when window is resized. It is only when using ellipsis-resize-detection="window"!

Steps to reproduce

  1. Go to 'official stackblitz' for ngx-ellipsis
  2. Add ellipsis-resize-detection="window" to any of the ellipsis DIVs
  3. Resize the preview window some times

Observe: The browser will slow down and resizing will become more sluggish. Debug: (Using chrome) navigate to "source" in DevTools and add a "logpoint" in the ellipsis.directive.ts in applyEllipsis(). This will log a message in the console every time the function is called. Observe that the function is executed exponentially on each resize of the window.

image

lentschi commented 3 years ago

Thank you @bjarketrux for finding this major issue and for the concise description. (It even affected the default resize detection too: applyEllipsis wasn't called "exponentially", but the callback within addElementResizeListener was. The performance impact was smaller than with window detection, but still there.)

Fixed in ngx-ellipsis@3.1.1