Inconsistent window.scrollTo(0, 0) Behavior

I’m using Barba.js for page transitions on my website, and I want the scroll position to always reset to the top of the page during transitions. I’ve added window.scrollTo(0, 0) in the afterEnter hook, but it doesn’t consistently work. For example, when transitioning from the homepage to the corporate page, it only works about 2 out of 10 times.

Here’s a simplified version of my code:

history.scrollRestoration = "manual"

barba.hooks.afterEnter(() => {
  console.log("window scrollTo 0, 0");
  window.scrollTo(0, 0);
});

barba.init({
  transitions: [{
    name: 'default',
    async afterEnter() {
      console.log("window scrollTo 0, 0");
      window.scrollTo(0, 0);
    },
  }]
});

Despite seeing the log message every time, indicating that the code is executed, the scroll position doesn’t always reset as expected.

What could be causing this inconsistent behavior? Thank you