Anchor Link scroll not working correctly when Javascript component included in page

I have a page that is mostly HTML/CSS with one Javascript component in the middle.

I am having an issue with using anchor links to jump to specific parts on the page.
For now I made a section titles Test to test the scrolling behavior.

So when I type in the URL: …/contact#Test it should jump to the Test section.

When I disable Javascript on the page it works as intended.

Also when I go into the CSS and change the Javascript Component’s display to none or set a manual height it works as well. But I don’t want to set a manual height because the component is dynamic.

But with the component enabled as it is, the page scrolls down to the bottom every time.

screenshot of the page