Since Herbert Hoover I believe.
“Since Herbert Hoover...”
Since Herbert Hoover, Nixon was challenged in the primary and won reelection. Truman was challenged in 1948 (although this was when the conventions still mattered, before things were fully decided during the primaries) and won reelection. And FDR withstood a challenge by his own vice-president prior to the 1940 election. Conservative Democrats as well as conservative Republicans were deeply worried about FDR flouting the George Washington precedent, and with the economy still not responding, the packing of the Supreme Court, and doubts about the New Deal the challenge was very serious. But FDR was a master politician and was reelected.
So, there is precedent for a sitting president to withstand challenges from within his own party and still be reelected.