Handle undefined theme the right way

Sorry for the confusion.
This is the right way to do #10236.
Yeah, I meant that the issue you are fixing with your changes below is a good find :)   It is an edge case that only really happens when you uninstall a theme.