Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Quickstart component to prevent error #4030

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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