On a rainbow extremal problem for color-critical graphs