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

Fix sheet height locking too early for filter help #10391

Merged
merged 6 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 21 additions & 3 deletions src/app/dim-ui/Sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,14 @@
if (sheetContents.current.clientHeight > 0) {
setFrozenHeight(sheetContents.current.clientHeight);
} else {
setTimeout(() => {
sheetContents.current && setFrozenHeight(sheetContents.current.clientHeight);
}, 500);
const setHeight = () => {
if (!sheetContents.current || sheetContents.current.clientHeight === 0) {
return false;
}
setFrozenHeight(sheetContents.current.clientHeight);
return true;
};
tryWithBackoff(setHeight);
ryan-rushton marked this conversation as resolved.
Show resolved Hide resolved
}
}
}, [freezeInitialHeight, frozenHeight]);
Expand Down Expand Up @@ -321,3 +326,16 @@
</Portal>
);
}

function tryWithBackoff(callback: () => boolean, timeout: number = 500, limit: number = 5_000) {

Check failure on line 330 in src/app/dim-ui/Sheet.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

src/app/dim-ui/Sheet.tsx#L330

[@typescript-eslint/no-inferrable-types] Type number trivially inferred from a number literal, remove type annotation.

Check failure on line 330 in src/app/dim-ui/Sheet.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

src/app/dim-ui/Sheet.tsx#L330

[@typescript-eslint/no-inferrable-types] Type number trivially inferred from a number literal, remove type annotation.
if (timeout > limit) {
return;
}
setTimeout(() => {
const res = callback();
if (res) {
return;
}
tryWithBackoff(callback, timeout * 1.25);
}, timeout);
}
32 changes: 18 additions & 14 deletions src/app/search/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -545,21 +545,25 @@ function SearchBar(
</LayoutGroup>

{filterHelpOpen && (
<Sheet
onClose={() => setFilterHelpOpen(false)}
header={
<>
<h1>{t('Header.Filters')}</h1>
<UserGuideLink topic="Item-Search" />
</>
}
freezeInitialHeight
sheetClassName={styles.filterHelp}
>
<Suspense fallback={<Loading message={t('Loading.FilterHelp')} />}>
<Suspense fallback={<Loading message={t('Loading.FilterHelp')} />}>
ryan-rushton marked this conversation as resolved.
Show resolved Hide resolved
{/* Because FilterHelp suspends, the entire sheet will suspend while it is loaded.
* This stops us having issues with incorrect frozen initial heights as it will
* get locked to the fallback height if we don't do this.
*/}
ryan-rushton marked this conversation as resolved.
Show resolved Hide resolved
<Sheet
onClose={() => setFilterHelpOpen(false)}
header={
<>
<h1>{t('Header.Filters')}</h1>
<UserGuideLink topic="Item-Search" />
</>
}
freezeInitialHeight
sheetClassName={styles.filterHelp}
>
<LazyFilterHelp />
</Suspense>
</Sheet>
</Sheet>
</Suspense>
)}

{autocompleteMenu}
Expand Down
Loading