diff --git a/services/site/src/client/islands/changelog.ts b/services/site/src/client/islands/changelog.ts index e36be5ba9c8..1653ba3d5d9 100644 --- a/services/site/src/client/islands/changelog.ts +++ b/services/site/src/client/islands/changelog.ts @@ -14,6 +14,49 @@ export default function changelog(root: HTMLElement) { if (list) timelineRail(list) $$('[data-component="changelog-entry"] > [data-slot="media"]', root).forEach(media) copyLinks(root) + deferredLists(root) +} + +// A collapsed list the changelog leaves out of its HTML (NoteGroup's `defer`) holds a link to the +// entry's page. Opening it moves the list in from that page, loaded once per entry, as soon as the +// pointer reaches the heading. While it loads the group is busy; if loading fails, the link stays. +function deferredLists(root: HTMLElement) { + const pages = new Map>() + const load = (href: string) => { + if (!pages.has(href)) + pages.set( + href, + fetch(href) + .then((response) => (response.ok ? response.text() : Promise.reject(new Error(String(response.status))))) + .then((html) => new DOMParser().parseFromString(html, "text/html")) + .catch(() => void pages.delete(href)), + ) + return pages.get(href)! + } + const link = (group: HTMLElement) => $(':scope > [data-slot="show-more"]', group) + const open = (group: HTMLElement) => { + const more = link(group) + if (!more || group.hasAttribute("aria-busy")) return + group.setAttribute("aria-busy", "true") + void load(more.href).then((page) => { + group.removeAttribute("aria-busy") + const list = page?.querySelector(`[data-slot="group"][data-kind="${group.dataset.kind}"] > ul`) + if (list) more.replaceWith(list) + }) + } + const group = (event: Event) => + target(event).closest('details[data-slot="group"] > summary')?.parentElement as HTMLDetailsElement | null + // A click (Enter and Space too) on the heading comes before the group opens, so the link never shows. + root.addEventListener("click", (event) => { + const details = group(event) + if (details && !details.open) open(details) + }) + root.addEventListener("pointerover", (event) => { + const details = group(event) + const more = details && link(details) + if (more) void load(more.href) + }) + $$('details[data-slot="group"][open]', root).forEach(open) } // An entry's media (EntryCarousel): with several slides, dragged or swiped sideways (changelog-motion.ts), diff --git a/services/site/src/component/site/changelog-entry.css b/services/site/src/component/site/changelog-entry.css index 0fdbb537790..f5fc8c3eaac 100644 --- a/services/site/src/component/site/changelog-entry.css +++ b/services/site/src/component/site/changelog-entry.css @@ -399,10 +399,21 @@ rotate: 0deg; } - > ul { + > ul, + > [data-slot="show-more"] { margin-top: 0.875rem; } + /* A deferred list (NoteGroup) shows its link to the entry's page only if loading it takes a while. */ + > [data-slot="show-more"] { + display: inline-block; + margin-inline-start: 0; + } + + &[aria-busy] > [data-slot="show-more"] { + animation: changelog-loading 1s step-end; + } + @media (prefers-reduced-motion: reduce) { > summary [data-slot="chevron"] { transition: none; @@ -934,6 +945,12 @@ } } +@keyframes changelog-loading { + from { + visibility: hidden; + } +} + @keyframes changelog-slide-progress { from { transform: scaleX(0); diff --git a/services/site/src/component/site/changelog-entry.tsx b/services/site/src/component/site/changelog-entry.tsx index 47f5b02e18b..ecea28f4e5d 100644 --- a/services/site/src/component/site/changelog-entry.tsx +++ b/services/site/src/component/site/changelog-entry.tsx @@ -226,6 +226,8 @@ export function ChangelogTimeline(props: { limit: number /** Product pages link the rest of a long list to the entry's page. */ more?: boolean + /** A collapsed list holds only a link to the entry's page, which the changelog's script loads it from. */ + defer?: boolean }) { const language = useLanguage() let list!: HTMLOListElement @@ -278,6 +280,7 @@ export function ChangelogTimeline(props: { media={entryMedia(entry)} limit={props.limit} more={props.more ? language.route(entryPath(entry)) : undefined} + defer={props.defer ? language.route(entryPath(entry)) : undefined} /> ) @@ -587,7 +590,14 @@ const areaNames = { } as const satisfies Record /** An entry's title and notes: the summary, the other highlights, then breaking changes, improvements and fixes. */ -function EntryBody(props: { entry: ChangelogEntry; level: 1 | 2 | 3; media?: Slide[]; limit: number; more?: string }) { +function EntryBody(props: { + entry: ChangelogEntry + level: 1 | 2 | 3 + media?: Slide[] + limit: number + more?: string + defer?: string +}) { const i18n = useI18n() const language = useLanguage() const page = () => language.route(entryPath(props.entry)) @@ -699,17 +709,21 @@ function EntryBody(props: { entry: ChangelogEntry; level: 1 | 2 | 3; media?: Sli