Fix a bug where templateContext becomes globally changed