Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

fix: icon picker suspense issue (#1533)

Meier Lukasecf299e03b59
diff --git a/apps/nextjs/src/components/icons/picker/icon-picker.tsx b/apps/nextjs/src/components/icons/picker/icon-picker.tsx
index bd77a27d5..8a514f8a5 100644
--- a/apps/nextjs/src/components/icons/picker/icon-picker.tsx
+++ b/apps/nextjs/src/components/icons/picker/icon-picker.tsx
@@ -15,6 +15,7 @@ import {
UnstyledButton,
useCombobox,
} from "@mantine/core";
+import { useDebouncedValue } from "@mantine/hooks";
import { clientApi } from "@homarr/api/client";
import { useScopedI18n } from "@homarr/translation/client";
@@ -34,16 +35,19 @@ export const IconPicker = ({ initialValue, onChange, error, onFocus, onBlur }: I
const tCommon = useScopedI18n("common");
- const [data] = clientApi.icon.findIcons.useSuspenseQuery({
- searchText: search,
+ const [debouncedSearch] = useDebouncedValue(search, 100);
+
+ // We use not useSuspenseQuery as it would cause an above Suspense boundary to trigger and so searching for something is bad UX.
+ const { data } = clientApi.icon.findIcons.useQuery({
+ searchText: debouncedSearch,
});
const combobox = useCombobox({
onDropdownClose: () => combobox.resetSelectedOption(),
});
- const totalOptions = data.icons.reduce((acc, group) => acc + group.icons.length, 0);
- const groups = data.icons.map((group) => {
+ const totalOptions = data?.icons.reduce((acc, group) => acc + group.icons.length, 0) ?? 0;
+ const groups = data?.icons.map((group) => {
const options = group.icons.map((item) => (
<UnstyledButton
onClick={() => {
@@ -92,8 +96,12 @@ export const IconPicker = ({ initialValue, onChange, error, onFocus, onBlur }: I
<Combobox.Target>
<InputBase
rightSection={<Combobox.Chevron />}
- // eslint-disable-next-line @next/next/no-img-element
- leftSection={previewUrl ? <img src={previewUrl} alt="" style={{ width: 20, height: 20 }} /> : null}
+ leftSection={
+ previewUrl ? (
+ // eslint-disable-next-line @next/next/no-img-element
+ <img src={previewUrl} alt="" style={{ width: 20, height: 20 }} />
+ ) : null
+ }
value={search}
onChange={(event) => {
combobox.openDropdown();
@@ -118,7 +126,7 @@ export const IconPicker = ({ initialValue, onChange, error, onFocus, onBlur }: I
withAsterisk
error={error}
label={tCommon("iconPicker.label")}
- placeholder={tCommon("iconPicker.header", { countIcons: data.countIcons })}
+ placeholder={tCommon("iconPicker.header", { countIcons: data?.countIcons ?? 0 })}
/>
</Combobox.Target>