Twitter's 'Nah Still Too Long' Bug
Twitter has a new funny bug on the web where you write a tweet that’s too long, then shorten it, but the red indicator does not go away. Learn more about this issue and how to trigger it.
дэн
the results are always perfect
-
twitter has a new funny bug on the web where you write a tweet that’s too long, then shorten it, but the red indicator does not go away. it’s like “nah still too long”. but the char counter is yellow (you have more chars). eventually you figure it out
— дэн (@dan_abramov) March 15, 2023 -
i’ve been playing with it for a little bit (almost ten minutes), and it seems like to trigger it, it is sufficient to:
— дэн (@dan_abramov) March 16, 2023
1. write a longer tweet than ok
2. put the selection anywhere before the red stuff
3. select N chars where N >= red_char_count
4. press backspace -
it’s specifically (3) that’s curious to me. why does it only break when you delete enough characters at once to push it back under the normal count?
— дэн (@dan_abramov) March 16, 2023 -
maybe it’s literally something like
— дэн (@dan_abramov) March 16, 2023
function handleChange(e) {
const newText = https://t.co/UCqWdOVr4T.value
setText(newText)
if (newText.length > limit) {
setRedCount(newText.length - limit)
}
}
the bug being that it doesn’t call setRedCount when it’s <= limit. -
testing the behavior in more detail, i suspect it is closer to this. you can notice that it “comes alive” when you get to –2 left.
— дэн (@dan_abramov) March 16, 2023
function handleChange(e) {
setText(https://t.co/UCqWdOVr4T.value)
if (text.length > limit) {
setRedCount(text.length - limit + 1)
}
} -
if that were the cause of the bug, the fix would be:
— дэн (@dan_abramov) March 16, 2023
const redCount = Math.max(0, text.length - limit)
function handleChange(e) {
setText(https://t.co/UCqWdOVr4T.value)
}
no need to put redCount into state — calculate it during render. then it’s always up-to-date!