I recently tweaked a bit my PS1. The code as follows:

PS1='$(if [[ $? != 0 ]]; then echo " \e[91m\e[0m"; fi) \u $(assemble_prompt)$ '

The missing char is from nerd-fonts and doesn't matter in my question (as well as assemble_prompt function).

The problem I encountered is a broken PS1 when I shrink terminal window size to the size of a prompt (approx.). Then it seem to ignore PS1 setting and sets PS1 to $ chars only (see screenshot). Note then when I start typing it simply overrides my custom prompt in this occasion.

I narrowed the problem to an if clause that adds "fail" char if previous command was unsuccessful. If I remove that part everything works as expected.

Is there a way to keep if clause part but fix the issue with PS1 reset when the window size is too small?