Fix theme concurrency issues (PR #9609)

(see commit messages)

GitHub

Added commits to master manually