IvanSmiths's post in Infinite Scroll working on React but not with Next.js was marked as the answer
Thank you to both! In fact i haven`t tried to use useLayoutEffect.
But i think i found a solution!
I tried to call ScrollTrigger.create instead of a timeline, and now is working.
So the code now is:
ScrollTrigger.create({
start: 1,
end: () => ScrollTrigger.maxScroll(window) - 1,
onLeaveBack: self => self.scroll(ScrollTrigger.maxScroll(window) - 1),
onLeave: self => self.scroll(1)
}).scroll(1);
Hope this can help someone!