Thanks to @mplungjan I was able to fix the issue by adding a timeout
setTimeout(() => {
history.pushState(
{ guard: true, html: pageContent.innerHTML },
null,
window.location.href
);
console.debug("Guard state reinserted");
}, 0);