Skip to content

A full-featured download manager.

fix(downloads): refresh inspector inset after inner layout changes (#2290)

Dr_rOot47c049939fb5
diff --git a/src/renderer/routes/downloads/downloads-page.test.tsx b/src/renderer/routes/downloads/downloads-page.test.tsx
index da8ea3a6..d15810bf 100644
--- a/src/renderer/routes/downloads/downloads-page.test.tsx
+++ b/src/renderer/routes/downloads/downloads-page.test.tsx
@@ -194,6 +194,104 @@ beforeEach(() => {
})
describe('DownloadsPage', () => {
+ it('updates inspector scroll space when the grid or footer resizes independently', () => {
+ const observers = new Set<{
+ targets: Set<Element>
+ callback: ResizeObserverCallback
+ }>()
+ vi.stubGlobal(
+ 'ResizeObserver',
+ class {
+ targets = new Set<Element>()
+ constructor(readonly callback: ResizeObserverCallback) {
+ observers.add(this)
+ }
+ observe(target: Element) {
+ this.targets.add(target)
+ }
+ unobserve(target: Element) {
+ this.targets.delete(target)
+ }
+ disconnect() {
+ observers.delete(this)
+ }
+ }
+ )
+ let gridHeight = 382
+ let footerHeight = 44
+ const rect = vi
+ .spyOn(HTMLElement.prototype, 'getBoundingClientRect')
+ .mockImplementation(function (this: HTMLElement) {
+ const height = this.hasAttribute('data-downloads-grid')
+ ? gridHeight
+ : this.dataset.slot === 'panel-shell-footer'
+ ? footerHeight
+ : 500
+ return new DOMRect(0, 0, 700, height)
+ })
+ const notifyResize = (target: Element) => {
+ act(() => {
+ for (const observer of observers) {
+ if (observer.targets.has(target)) {
+ observer.callback(
+ [
+ { target, contentRect: target.getBoundingClientRect() },
+ ] as ResizeObserverEntry[],
+ observer as unknown as ResizeObserver
+ )
+ }
+ }
+ })
+ }
+ let view: ReturnType<typeof renderAt> | undefined
+ try {
+ setTaskList({ tasks: [task('a', TaskStatus.Paused)] })
+ useDownloadsView.setState({ inspectorSnap: 'expanded' })
+ view = renderAt('/downloads/all')
+ act(() => {
+ useDownloadsSelection.getState().select('a')
+ useDownloadsView.getState().setInspectorVisible(true)
+ })
+ const inset = () => {
+ const content = screen
+ .getByTestId('virtual-list-container')
+ .querySelector('[data-slot="scroll-area-content"]')
+ return (content?.lastElementChild as HTMLElement | undefined)?.style
+ .height
+ }
+ expect(inset()).toBe('310px')
+
+ // The compact header finishes animating after the page root stops resizing.
+ gridHeight = 418
+ const grid = screen.getByRole('grid', { name: 'Downloads' })
+ notifyResize(grid)
+ expect(inset()).toBe('331px')
+
+ footerHeight = 56
+ notifyResize(screen.getByRole('contentinfo'))
+ expect(inset()).toBe('319px')
+
+ // Type filters remount the keyed task panel even when its row count is unchanged.
+ fireEvent.click(screen.getByTestId('navigate-type'))
+ const replacementGrid = screen.getByRole('grid', { name: 'Downloads' })
+ expect(replacementGrid).not.toBe(grid)
+ gridHeight = 382
+ notifyResize(replacementGrid)
+ expect(inset()).toBe('310px')
+
+ view.unmount()
+ expect(
+ [...observers].some(
+ (observer) =>
+ observer.targets.has(grid) || observer.targets.has(replacementGrid)
+ )
+ ).toBe(false)
+ } finally {
+ view?.unmount()
+ rect.mockRestore()
+ }
+ })
+
it('keeps the toolbar in sync with empty selection and requires an explicit reopen', async () => {
setTaskList({
tasks: [task('a', TaskStatus.Paused), task('b', TaskStatus.Paused)],
diff --git a/src/renderer/routes/downloads/downloads-page.tsx b/src/renderer/routes/downloads/downloads-page.tsx
index d3e6fa5f..2b986696 100644
--- a/src/renderer/routes/downloads/downloads-page.tsx
+++ b/src/renderer/routes/downloads/downloads-page.tsx
@@ -286,6 +286,7 @@ export function DownloadsPage() {
])
const [container, setContainer] = useState<HTMLElement | null>(null)
+ const taskListKey = `${filter}:${serializeTypeParam(types)}`
// The inspector drawer overlays the page root without resizing the list, so
// the list must reserve scroll space for the band the drawer covers;
@@ -311,19 +312,19 @@ export function DownloadsPage() {
footer: 0,
grid: 0,
})
- // biome-ignore lint/correctness/useExhaustiveDependencies: the list swaps between skeleton, grid, and empty states without resizing the page root; re-running re-queries the footer and grid elements
+ // biome-ignore lint/correctness/useExhaustiveDependencies: rebind when loading/empty states or the keyed task panel replace the observed elements without resizing the page root
useEffect(() => {
if (!container) return
+ const footerElement = container.querySelector<HTMLElement>(
+ '[data-slot="panel-shell-footer"]'
+ )
+ const gridElement = container.querySelector<HTMLElement>(
+ '[data-downloads-grid]'
+ )
const measure = () => {
const page = container.getBoundingClientRect().height
- const footer =
- container
- .querySelector<HTMLElement>('[data-slot="panel-shell-footer"]')
- ?.getBoundingClientRect().height ?? 0
- const grid =
- container
- .querySelector<HTMLElement>('[data-downloads-grid]')
- ?.getBoundingClientRect().height ?? 0
+ const footer = footerElement?.getBoundingClientRect().height ?? 0
+ const grid = gridElement?.getBoundingClientRect().height ?? 0
setInspectorMetrics((previous) =>
previous.page === page &&
previous.footer === footer &&
@@ -336,8 +337,12 @@ export function DownloadsPage() {
if (typeof ResizeObserver === 'undefined') return
const observer = new ResizeObserver(measure)
observer.observe(container)
+ // Header animations and footer content can resize the grid after the
+ // bounded page root has stopped resizing.
+ if (footerElement) observer.observe(footerElement)
+ if (gridElement) observer.observe(gridElement)
return () => observer.disconnect()
- }, [container, status, hasReadySnapshot, filtered.length])
+ }, [container, status, hasReadySnapshot, filtered.length, taskListKey])
const inspectorInset = resolveInspectorInset({
pageHeight: inspectorMetrics.page,
footerHeight: inspectorMetrics.footer,
@@ -353,7 +358,7 @@ export function DownloadsPage() {
<TaskListUnavailable onRetry={() => void retry()} />
) : (
<TaskListPanel
- key={`${filter}:${serializeTypeParam(types)}`}
+ key={taskListKey}
tasks={filtered}
hasAnyTasks={counts.all > 0}
selection={useDownloadsSelection}