Updated fix for #22232 that handles multi-template circular extensions