Skip to content

Commit da68b01

Browse files
committed
Use onMount to ensure category lists are only fetched from the client.
This is not ideal, since it prevents no-JS clients from filtering by category, but it fixes the dev server for now.
1 parent 18dd826 commit da68b01

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

webserver/src/components/CategoryList.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import { escapeRegExp, filterListWithInitialMatchesFirst } from '@lib/util';
22
import type { Category } from '@prisma/client';
3-
import { type Accessor, type Component, createMemo, createResource, createSignal, For, type Resource, type Setter, Suspense } from 'solid-js';
3+
import {
4+
type Accessor,
5+
type Component,
6+
createMemo,
7+
createResource,
8+
createSignal,
9+
For,
10+
onMount,
11+
type Resource,
12+
type Setter,
13+
Suspense,
14+
} from "solid-js";
415
import { OneRecipe, type RecipeTitleWithLinkFields } from './OneRecipe';
516
import { QueryDrivenTextField } from './QueryDrivenTextField';
617

@@ -57,10 +68,12 @@ export const CategoryList: Component<{
5768
}
5869

5970
// Ensure default-open categories load their recipes.
60-
const initialCategories = filteredCategories();
61-
if (initialCategories.length === 1) {
62-
recipesByCategory().get(initialCategories[0]!.id)?.setNeedRecipes(true);
63-
}
71+
onMount(() => {
72+
const initialCategories = filteredCategories();
73+
if (initialCategories.length === 1) {
74+
recipesByCategory().get(initialCategories[0]!.id)?.setNeedRecipes(true);
75+
}
76+
});
6477

6578
return <>
6679
<QueryDrivenTextField queryParam='filter' value={filter()} onInput={setFilter}>Filter</QueryDrivenTextField>

webserver/src/components/IngredientList.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import { escapeRegExp, filterListWithInitialMatchesFirst } from '@lib/util';
2-
import { type Accessor, type Component, createMemo, createResource, createSignal, For, type Resource, type Setter, Suspense } from 'solid-js';
2+
import {
3+
type Accessor,
4+
type Component,
5+
createMemo,
6+
createResource,
7+
createSignal,
8+
For,
9+
onMount,
10+
type Resource,
11+
type Setter,
12+
Suspense,
13+
} from "solid-js";
314
import { OneRecipe, type RecipeTitleWithLinkFields } from './OneRecipe';
415
import { QueryDrivenTextField } from './QueryDrivenTextField';
516

@@ -53,10 +64,14 @@ export const IngredientList: Component<{
5364
function onToggleIngredient(ingredient: string) {
5465
recipesByIngredient().get(ingredient)?.setNeedRecipes(true);
5566
}
56-
const initialIngredients = filteredIngredients();
57-
if (initialIngredients.length === 1) {
58-
recipesByIngredient().get(initialIngredients[0]!.name)?.setNeedRecipes(true);
59-
}
67+
onMount(() => {
68+
const initialIngredients = filteredIngredients();
69+
if (initialIngredients.length === 1) {
70+
recipesByIngredient()
71+
.get(initialIngredients[0]!.name)
72+
?.setNeedRecipes(true);
73+
}
74+
});
6075

6176
return <>
6277
<section id="ingredients">

0 commit comments

Comments
 (0)