Handle undefined theme the right way

Sorry for the confusion.
This is the right way to do #10236.
Ah, reverted the change in this PR (as it's not necessary) to not cause any unnecessary conflicts with your PR.