From 4cad71932256c11a2f6426424b912fdb29d03371 Mon Sep 17 00:00:00 2001 From: Kevin Mulhern Date: Sun, 25 Jun 2023 23:47:46 +0100 Subject: [PATCH] Fix: JS error with toc item on page navigation. (#3880) 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. --- app/javascript/controllers/lesson_toc_controller.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/javascript/controllers/lesson_toc_controller.js b/app/javascript/controllers/lesson_toc_controller.js index d4309a81d0..9dcd1b2ca9 100644 --- a/app/javascript/controllers/lesson_toc_controller.js +++ b/app/javascript/controllers/lesson_toc_controller.js @@ -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 = ''; }