tscanlin / tocbot

Build a table of contents from headings in an HTML document.
MIT License
1.37k stars 114 forks source link

skipRendering true throws exception #309

Closed ayZagen closed 8 months ago

ayZagen commented 9 months ago

If skipRendering is true tocbot throws following error:

build-html.js:199 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'querySelector')
    at Object.updateToc (build-html.js:199:41)
    at Object.<anonymous> (index.js:197:17)
    at Object._scrollListener (index.js:79:12)
    at tocbot.init (index.js:207:10)
    at AsyncFunction.OnThisPage_component_useVisibleTask_JUUUE8xYwDo [as resolved] (on-this-page.tsx:106:12)
    at AsyncFunction.invoke (use-core.js:59:26)
    at qrl-class.js:70:35
    at then (promises.js:20:56)
    at qrl-class.js:56:20
    at use-task.js:439:27

It throws this error in this line

var oldActiveTocLink = tocElement.querySelector('.' + options.activeLinkClass)

It seems tocElement is undefined, however I am sure it is defined and I can see it successfully resolved in the tocbot.init function.

Do I miss something? Thanks.

tscanlin commented 9 months ago

Hey, thanks for opening this issue! And apologies for my delay in getting back to you. I have a PR here that should address this. Let me know if that fix doesn't work or if you run into anything else. Thanks!

tscanlin commented 9 months ago

This should be fixed in 4.21.2