Skip to content

Commit

Permalink
Fix: JS error with toc item on page navigation. (#3880)
Browse files Browse the repository at this point in the history
Because:
* We are removing the toc items so they won't be cached, but we are
still observing them with an intersection observer.

This commit:
* Unobserve all headings before destroying them on page navigation.
  • Loading branch information
KevinMulhern committed Jun 25, 2023
1 parent b85d2c3 commit 4cad719
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/javascript/controllers/lesson_toc_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default class LessonTocController extends Controller {
}

disconnect() {
this.lessonContentTarget.querySelectorAll('section[id]').forEach((section) => {
this.tocItemObserver().unobserve(section);
});

this.tocTarget.innerHTML = '';
}

Expand Down

0 comments on commit 4cad719

Please sign in to comment.