Skip to content

Commit

Permalink
Fix empty index
Browse files Browse the repository at this point in the history
Resolves #2514
  • Loading branch information
Gerrit0 committed Mar 6, 2024
1 parent b0796cb commit 9124254
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Unreleased

### Bug Fixes

- Fixed an issue introduced with 0.25.10 which causes the page index to initially render empty, #2514.

## v0.25.10 (2024-03-03)

### Bug Fixes
Expand Down
31 changes: 30 additions & 1 deletion src/lib/output/themes/default/assets/typedoc/Application.ts
Expand Up @@ -39,9 +39,11 @@ export class Application {
this.ensureFocusedElementVisible(),
);

// We're on a *really* slow network connection.
// We're on a *really* slow network connection and the inline JS
// has already made the page display.
if (!document.body.style.display) {
this.scrollToHash();
this.updateIndexVisibility();
}
}

Expand All @@ -67,6 +69,7 @@ export class Application {
if (!document.body.style.display) return;
document.body.style.removeProperty("display");
this.scrollToHash();
this.updateIndexVisibility();
}

public scrollToHash() {
Expand Down Expand Up @@ -102,6 +105,32 @@ export class Application {
}
}

public updateIndexVisibility() {
const indexAccordion =
document.querySelector<HTMLDetailsElement>(".tsd-index-content");
const oldOpen = indexAccordion?.open;
if (indexAccordion) {
indexAccordion.open = true;
}

// Hide index headings where all index items are hidden.
// offsetParent == null checks for display: none
document
.querySelectorAll<HTMLElement>(".tsd-index-section")
.forEach((el) => {
el.style.display = "block";
const allChildrenHidden = Array.from(
el.querySelectorAll<HTMLElement>(".tsd-index-link"),
).every((child) => child.offsetParent == null);

el.style.display = allChildrenHidden ? "none" : "block";
});

if (indexAccordion) {
indexAccordion.open = oldOpen!;
}
}

/**
* Ensures that if a user was linked to a reflection which is hidden because of filter
* settings, that reflection is still shown.
Expand Down
30 changes: 2 additions & 28 deletions src/lib/output/themes/default/assets/typedoc/components/Filter.ts
Expand Up @@ -30,7 +30,7 @@ export class Filter extends Component {
this.setLocalStorage(this.fromLocalStorage());

style.innerHTML += `html:not(.${this.key}) .tsd-is-${this.el.name} { display: none; }\n`;
this.updateIndexHeadingVisibility();
this.app.updateIndexVisibility();
}

/**
Expand Down Expand Up @@ -60,32 +60,6 @@ export class Filter extends Component {
document.documentElement.classList.toggle(this.key, this.value);

this.app.filterChanged();
this.updateIndexHeadingVisibility();
}

private updateIndexHeadingVisibility() {
const indexAccordion =
document.querySelector<HTMLDetailsElement>(".tsd-index-content");
const oldOpen = indexAccordion?.open;
if (indexAccordion) {
indexAccordion.open = true;
}

// Hide index headings where all index items are hidden.
// offsetParent == null checks for display: none
document
.querySelectorAll<HTMLElement>(".tsd-index-section")
.forEach((el) => {
el.style.display = "block";
const allChildrenHidden = Array.from(
el.querySelectorAll<HTMLElement>(".tsd-index-link"),
).every((child) => child.offsetParent == null);

el.style.display = allChildrenHidden ? "none" : "block";
});

if (indexAccordion) {
indexAccordion.open = oldOpen!;
}
this.app.updateIndexVisibility();
}
}
2 changes: 1 addition & 1 deletion src/lib/output/themes/default/layouts/default.tsx
Expand Up @@ -44,7 +44,7 @@ export const defaultLayout = (
{/* settings, this appears to be a reasonable tradeoff between displaying page content without the */}
{/* navigation on exceptionally slow connections and not having the navigation obviously repaint. */}
<Raw html='document.body.style.display="none";' />
<Raw html='setTimeout(() => document.body.style.removeProperty("display"),500)' />
<Raw html='setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)' />
</script>
{context.toolbar(props)}

Expand Down

0 comments on commit 9124254

Please sign in to comment.