Making custom changes to the sidebar programmatically

Having looked into it a bit further, I am confident that this will work, yes! My challenge now is that the list of links is dynamic and can potentially change with each page change. My naive approach of calling api.addSidebarSection from within api.onPageChange does not work because (a) the sidebar is only refreshed when it is re-rendered by hiding and showing it again and (b) the sections are repeated because api.addSidebarSection does not care if the name key is reused.

Any chance I can achieve a sidebar section that is updated on each page transition with the new API?