Skip to content

Commit

Permalink
make sure component is mounted first
Browse files Browse the repository at this point in the history
  • Loading branch information
john-rock committed Sep 6, 2023
1 parent c94def4 commit ea858d8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions website/src/components/quickstartTOC/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ function QuickstartTOC() {
const steps = quickstartContainer.querySelectorAll("h2");
const snippetContainer = document.querySelectorAll(".snippet");

// Add snippet container to its parent step
snippetContainer.forEach((snippet) => {
const parent = snippet?.parentNode;
while (snippet?.firstChild && parent.className) {
if (parent) {
parent.insertBefore(snippet.firstChild, snippet);
}
}
});

// Create an array of objects with the id and title of each step
const data = Array.from(steps).map((step, index) => ({
id: step.id,
Expand All @@ -49,6 +39,16 @@ function QuickstartTOC() {

// Wrap all h2 (steps), along with all of their direct siblings, in a div until the next h2
if (mounted) {
// Add snippet container to its parent step
snippetContainer.forEach((snippet) => {
const parent = snippet?.parentNode;
while (snippet?.firstChild && parent.className) {
if (parent) {
parent.insertBefore(snippet.firstChild, snippet);
}
}
});

steps.forEach((step, index) => {
const wrapper = document.createElement("div");
wrapper.classList.add(style.stepWrapper);
Expand Down

0 comments on commit ea858d8

Please sign in to comment.