ShinyChang/React-Text-Truncate

Infinite loop when width is too small to display truncateText

kaiw opened this issue · 2 comments

kaiw commented

When the available width is less than the width of truncateText, the do-while loop spins infinitely because the width check will never succeed. In this case, I think that the only reasonably thing to do is to give up. The patch below works in my testing.

+++ src/TextTruncate.js	2016-11-10 10:58:06.400619073 +1000
@@ -120,7 +120,7 @@
                             }
                         }
                         width = this.measureWidth(truncatedText + ext);
-                    } while (width >= scopeWidth);
+                    } while (width >= scopeWidth && truncatedText.length > 0);
                     startPos += currentPos;
                     break;
                 }

@kaiw ,
Confirmed.

#41 fixed this issue