diff --git a/CONTEXT.md b/CONTEXT.md index 10f61a5..873e202 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -61,7 +61,7 @@ _Avoid_: Vertical owner, product slice - The **Chapters** vertical owns chapter framing and status language, including section headers and status indicators. - The **Landing** vertical owns home-page presentation and consumes the **Chapters** vertical for the table of contents. - The **Design System** vertical owns primitive UI components, CSS files, styling tokens, utility class merging, and the theme toggle. -- The **Demo** vertical owns console cards and panel frames used by the interactive demo surface. +- The **Demo** vertical owns demo cards and panel frames used by the interactive demo surface. - Small implementation helpers used only by one vertical belong to that vertical; for example, the lazy component helper belongs to **Demo** while only the demo table uses it. - **Framework adapters** may remain in TanStack Start, TanStack Router, or Vite+ default locations even when they register behavior for a vertical. - API shape route files are **Framework adapters**; **Demo** owns the Electric collections that depend on those route URLs. diff --git a/DESIGN.md b/DESIGN.md index 2453291..cbfeeb4 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -56,7 +56,7 @@ Current scale: - `--text-xs`: dense labels, table headings, badges. - `--text-sm`: default body and controls. - `--text-base`: landing descriptions and prominent card titles. -- `--text-lg`: console card headings. +- `--text-lg`: demo card headings. - `--text-xl` and above: section headings and hero headings. Uppercase labels should be short. Avoid long uppercase prose because it harms scan speed. @@ -68,12 +68,12 @@ The app uses a compact, document-like structure: - Sticky horizontal navigation at the top. - Landing page with a concise intro and grouped example links. - Example pages with `max-w-7xl`, 24px page padding, a section header, then a strategy/content split. -- Console cards for data tables, filters, skeletons, and controls. +- Demo cards for data tables, filters, skeletons, and controls. The strategy route layout uses: - Left column: explanation panel through `StrategyArticle`. -- Right column: interactive console content through `ConsoleCard`. +- Right column: interactive demo content through `DemoCard`. - Desktop split: `minmax(0,0.9fr)` and `minmax(34rem,1.1fr)`. Keep table areas dimensionally stable while loading. Existing examples reserve height with `min-h-125` and skeleton rows; preserve that pattern to prevent layout jump. @@ -94,7 +94,7 @@ Keep table areas dimensionally stable while loading. Existing examples reserve h - The recommended starting example uses `--accent-surface` and an uppercase badge. - Keep card copy short and behavior-specific. -**ConsoleCard** +**DemoCard** - Primary framed work surface. - White or dark card background via `--bg-card`. diff --git a/package.json b/package.json index 25154aa..b4b2ff9 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "postgres": "^3.4.9", "react": "^19.2.5", "react-dom": "^19.2.5", + "react-error-boundary": "^6.1.1", "rehype-raw": "^7.0.0", "rehype-react": "^8.0.0", "remark-gfm": "^4.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 81b6483..41ebdef 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -78,6 +78,9 @@ importers: react-dom: specifier: ^19.2.5 version: 19.2.5(react@19.2.5) + react-error-boundary: + specifier: ^6.1.1 + version: 6.1.1(react@19.2.5) rehype-raw: specifier: ^7.0.0 version: 7.0.0 @@ -4705,6 +4708,11 @@ packages: peerDependencies: react: ^19.2.5 + react-error-boundary@6.1.1: + resolution: {integrity: sha512-BrYwPOdXi5mqkk5lw+Uvt0ThHx32rCt3BkukS4X23A2AIWDPSGX6iaWTc0y9TU/mHDA/6qOSGel+B2ERkOvD1w==} + peerDependencies: + react: ^18.0.0 || ^19.0.0 + react@19.2.5: resolution: {integrity: sha512-llUJLzz1zTUBrskt2pwZgLq59AemifIftw4aB7JxOqf1HY2FDaGDxgwpAPVzHU1kdWabH7FauP4i1oEeer2WCA==} engines: {node: '>=0.10.0'} @@ -10166,6 +10174,10 @@ snapshots: react: 19.2.5 scheduler: 0.27.0 + react-error-boundary@6.1.1(react@19.2.5): + dependencies: + react: 19.2.5 + react@19.2.5: {} read-package-up@11.0.0: diff --git a/src/articles/article.functions.tsx b/src/articles/article.functions.tsx index 13cc54b..d39efb2 100644 --- a/src/articles/article.functions.tsx +++ b/src/articles/article.functions.tsx @@ -1,6 +1,8 @@ import { createServerFn } from "@tanstack/react-start"; +import { queryOptions } from "@tanstack/react-query"; import { renderServerComponent } from "@tanstack/react-start/rsc"; import * as v from "valibot"; + import { ArticleShell } from "~/articles/article-shell.server"; const articlesContent: Record Promise> = { @@ -15,15 +17,22 @@ const articlesContent: Record Promise> = { "live-query-filters": () => import("./content/live-query-filters.md?raw").then((m) => m.default), }; -export const getArticle = createServerFn({ method: "GET" }) +const getServerArticle = createServerFn({ method: "GET" }) .inputValidator(v.object({ title: v.string(), slug: v.string() })) .handler(async ({ data }) => { const markdown = await (articlesContent[data.slug]?.() ?? Promise.resolve("Content coming soon.")); - const Renderable = await renderServerComponent( + const article = await renderServerComponent( , ); - return { Renderable }; + return { article }; + }); + +export const getArticleQueryOptions = ({ title, slug }: { title: string; slug: string }) => + queryOptions({ + queryKey: ["article", { title, slug }], + structuralSharing: false, + queryFn: () => getServerArticle({ data: { title, slug } }), }); diff --git a/src/demos/components/console-card.tsx b/src/demos/components/demo-card.tsx similarity index 73% rename from src/demos/components/console-card.tsx rename to src/demos/components/demo-card.tsx index 19821f6..31728b5 100644 --- a/src/demos/components/console-card.tsx +++ b/src/demos/components/demo-card.tsx @@ -1,7 +1,7 @@ import { cn } from "~/design-system/utils/cn"; import type { ReactNode } from "react"; -interface ConsoleCardProps { +interface DemoCardProps { children: ReactNode; className?: string; hover?: boolean; @@ -10,15 +10,15 @@ interface ConsoleCardProps { /** * Primary content container with hairline border. * - * The console aesthetic uses zero border-radius and visible borders + * The demo aesthetic uses zero border-radius and visible borders * to create a technical, information-dense feel. * * @example - * + * *

Content

- *
+ * */ -export function ConsoleCard({ children, className, hover = false }: ConsoleCardProps) { +export function DemoCard({ children, className, hover = false }: DemoCardProps) { return (
+
+

+ Failed to load Pokémon data +

+

+ {getErrorMessage(error)} +

+
+ +
+ ); +} + +function getErrorMessage(error: unknown): string { + if (error instanceof Error) return error.message; + return "An unknown error occurred"; +} diff --git a/src/demos/components/pokedex-table-section.tsx b/src/demos/components/pokedex-table-section.tsx index 9112bed..ddd2eea 100644 --- a/src/demos/components/pokedex-table-section.tsx +++ b/src/demos/components/pokedex-table-section.tsx @@ -1,7 +1,10 @@ import * as React from "react"; +import { ErrorBoundary } from "react-error-boundary"; +import { useQueryErrorResetBoundary } from "@tanstack/react-query"; import { POKEMON_LIMIT } from "~/demos/pokemon-listing/constants"; import { lazily } from "~/vendor/lazily"; import { PaginationNav } from "~/demos/components/pagination-nav"; +import { DemoErrorFallback } from "./demo-error-fallback"; import { PokemonTableSkeleton } from "./pokemon-table-skeleton"; const { PokemonTable } = lazily(() => import("./pokemon-table")); @@ -21,6 +24,7 @@ interface PokedexTableSectionProps { export function PokedexTableSection(props: PokedexTableSectionProps) { const { children, currentOffset, fallbackPagination, nameFilter } = props; + const { reset } = useQueryErrorResetBoundary(); return ( <> @@ -30,18 +34,20 @@ export function PokedexTableSection(props: PokedexTableSectionProps) { (filtered: "{nameFilter}") )} - - - - - {fallbackPagination} - - } - > - {children} - + + + + + + {fallbackPagination} + + } + > + {children} + + ); } diff --git a/src/routes/_chapters/basic.tsx b/src/routes/_chapters/basic.tsx index f9e2e5e..933a498 100644 --- a/src/routes/_chapters/basic.tsx +++ b/src/routes/_chapters/basic.tsx @@ -1,14 +1,14 @@ import { createFileRoute } from "@tanstack/react-router"; import { useSuspenseQuery } from "@tanstack/react-query"; import * as v from "valibot"; -import { ConsoleCard } from "~/demos/components/console-card"; +import { DemoCard } from "~/demos/components/demo-card"; import { PokedexPagination, PokedexTableResults, PokedexTableSection, } from "~/demos/components/pokedex-table-section"; import { getPokemonListQueryFn, getPokemonListQueryKey } from "~/demos/query/pokemon-query"; -import { getArticle } from "~/articles/article.functions"; +import { getArticleQueryOptions } from "~/articles/article.functions"; import { ChapterSplitColumn } from "~/chapters/chapter-split"; const searchParamsSchema = v.object({ @@ -20,25 +20,33 @@ export const Route = createFileRoute("/_chapters/basic")({ routeTitle: "01_basic", routeSubtitle: "// Baseline fetching", }, - validateSearch: searchParamsSchema, - loader: async () => { - const { Renderable: Article } = await getArticle({ - data: { title: "No prefetching", slug: "basic" }, + context: () => { + const noPrefetchArticleQueryOptions = getArticleQueryOptions({ + title: "No prefetching", + slug: "basic", }); - return { Article }; + return { noPrefetchArticleQueryOptions }; + }, + validateSearch: searchParamsSchema, + loader: async ({ context: { queryClient, noPrefetchArticleQueryOptions } }) => { + await queryClient.ensureQueryData(noPrefetchArticleQueryOptions); }, component: RouteComponent, }); function RouteComponent() { const { offset: currentOffset } = Route.useSearch(); - const { Article } = Route.useLoaderData(); + const { noPrefetchArticleQueryOptions } = Route.useRouteContext(); + + const { + data: { article }, + } = useSuspenseQuery(noPrefetchArticleQueryOptions); return ( + - + } /> ); diff --git a/src/routes/_chapters/debounced-preload-filters.tsx b/src/routes/_chapters/debounced-preload-filters.tsx index 6b539a1..e14303f 100644 --- a/src/routes/_chapters/debounced-preload-filters.tsx +++ b/src/routes/_chapters/debounced-preload-filters.tsx @@ -4,7 +4,7 @@ import { queryOptions, useQueryClient, useSuspenseQuery } from "@tanstack/react- import * as v from "valibot"; import { FilterForm } from "~/demos/components/filter-form"; import { ChapterSplitColumn } from "~/chapters/chapter-split"; -import { ConsoleCard } from "~/demos/components/console-card"; +import { DemoCard } from "~/demos/components/demo-card"; import { PokedexPagination, PokedexTableResults, @@ -14,7 +14,7 @@ import { getFilteredPokemonListQueryKey, getFilteredPokemonListQueryFn, } from "~/demos/query/pokemon-query"; -import { getArticle } from "~/articles/article.functions"; +import { getArticleQueryOptions } from "~/articles/article.functions"; const searchParamsSchema = v.object({ offset: v.optional(v.number(), 0), @@ -43,25 +43,34 @@ export const Route = createFileRoute("/_chapters/debounced-preload-filters")({ queryFn: getFilteredPokemonListQueryFn, }); + const debouncedArticleQueryOptions = getArticleQueryOptions({ + title: "Debounced filter prefetch", + slug: "debounced-preload-filters", + }); + return { pokemonListOptions, + debouncedArticleQueryOptions, }; }, - loader: async ({ context }) => { - void context.queryClient.prefetchQuery(context.pokemonListOptions); - const { Renderable: Article } = await getArticle({ - data: { title: "Debounced filter prefetch", slug: "debounced-preload-filters" }, - }); - return { Article }; + loader: async ({ + context: { queryClient, pokemonListOptions, debouncedArticleQueryOptions }, + }) => { + void queryClient.prefetchQuery(pokemonListOptions); + await queryClient.ensureQueryData(debouncedArticleQueryOptions); }, component: RouteComponent, }); function RouteComponent() { const { offset: currentOffset, name: nameFilter } = Route.useSearch(); - const { Article } = Route.useLoaderData(); + const { debouncedArticleQueryOptions, pokemonListOptions: serverPokemonListOptions } = + Route.useRouteContext(); const queryClient = useQueryClient(); - const { pokemonListOptions: serverPokemonListOptions } = Route.useRouteContext(); + + const { + data: { article }, + } = useSuspenseQuery(debouncedArticleQueryOptions); const navigate = Route.useNavigate(); const debouncedNameFilter = useDebouncedCallback( (newNameFilter: string) => { @@ -81,10 +90,10 @@ function RouteComponent() { return ( - + - + - + - + } /> diff --git a/src/routes/_chapters/filters.tsx b/src/routes/_chapters/filters.tsx index c9a8a07..1f51976 100644 --- a/src/routes/_chapters/filters.tsx +++ b/src/routes/_chapters/filters.tsx @@ -3,7 +3,7 @@ import { queryOptions, useSuspenseQuery } from "@tanstack/react-query"; import * as v from "valibot"; import { FilterForm } from "~/demos/components/filter-form"; import { ChapterSplitColumn } from "~/chapters/chapter-split"; -import { ConsoleCard } from "~/demos/components/console-card"; +import { DemoCard } from "~/demos/components/demo-card"; import { PokedexPagination, PokedexTableResults, @@ -13,7 +13,7 @@ import { getFilteredPokemonListQueryKey, getFilteredPokemonListQueryFn, } from "~/demos/query/pokemon-query"; -import { getArticle } from "~/articles/article.functions"; +import { getArticleQueryOptions } from "~/articles/article.functions"; const searchParamsSchema = v.object({ offset: v.optional(v.number(), 0), @@ -38,31 +38,38 @@ export const Route = createFileRoute("/_chapters/filters")({ queryFn: getFilteredPokemonListQueryFn, }); + const filtersArticleQueryOptions = getArticleQueryOptions({ + title: "Submitted filter prefetch", + slug: "filters", + }); + return { pokemonListOptions, + filtersArticleQueryOptions, }; }, - loader: async ({ context }) => { - void context.queryClient.prefetchQuery(context.pokemonListOptions); - const { Renderable: Article } = await getArticle({ - data: { title: "Submitted filter prefetch", slug: "filters" }, - }); - return { Article }; + loader: async ({ context: { queryClient, pokemonListOptions, filtersArticleQueryOptions } }) => { + void queryClient.prefetchQuery(pokemonListOptions); + await queryClient.ensureQueryData(filtersArticleQueryOptions); }, component: RouteComponent, }); function RouteComponent() { const { offset: currentOffset, name: nameFilter } = Route.useSearch(); - const { Article } = Route.useLoaderData(); + const { filtersArticleQueryOptions } = Route.useRouteContext(); const navigate = Route.useNavigate(); + const { + data: { article }, + } = useSuspenseQuery(filtersArticleQueryOptions); + return ( - + { @@ -71,9 +78,9 @@ function RouteComponent() { }); }} /> - + - + - + } /> diff --git a/src/routes/_chapters/intent-preloading.tsx b/src/routes/_chapters/intent-preloading.tsx index 18458fa..0abe70b 100644 --- a/src/routes/_chapters/intent-preloading.tsx +++ b/src/routes/_chapters/intent-preloading.tsx @@ -2,14 +2,14 @@ import { createFileRoute, useRouteContext } from "@tanstack/react-router"; import { queryOptions, useSuspenseQuery } from "@tanstack/react-query"; import * as v from "valibot"; import { ChapterSplitColumn } from "~/chapters/chapter-split"; -import { ConsoleCard } from "~/demos/components/console-card"; +import { DemoCard } from "~/demos/components/demo-card"; import { PokedexPagination, PokedexTableResults, PokedexTableSection, } from "~/demos/components/pokedex-table-section"; import { getPokemonListQueryKey, getPokemonListQueryFn } from "~/demos/query/pokemon-query"; -import { getArticle } from "~/articles/article.functions"; +import { getArticleQueryOptions } from "~/articles/article.functions"; const searchParamsSchema = v.object({ offset: v.optional(v.number(), 0), @@ -32,29 +32,36 @@ export const Route = createFileRoute("/_chapters/intent-preloading")({ queryFn: getPokemonListQueryFn, }); + const intentArticleQueryOptions = getArticleQueryOptions({ + title: "Hover and focus preloading", + slug: "intent-preloading", + }); + return { pokemonListOptions, + intentArticleQueryOptions, }; }, - loader: async ({ context }) => { - void context.queryClient.prefetchQuery(context.pokemonListOptions); - const { Renderable: Article } = await getArticle({ - data: { title: "Hover and focus preloading", slug: "intent-preloading" }, - }); - return { Article }; + loader: async ({ context: { queryClient, pokemonListOptions, intentArticleQueryOptions } }) => { + void queryClient.prefetchQuery(pokemonListOptions); + await queryClient.ensureQueryData(intentArticleQueryOptions); }, component: RouteComponent, }); function RouteComponent() { const { offset: currentOffset } = Route.useSearch(); - const { Article } = Route.useLoaderData(); + const { intentArticleQueryOptions } = Route.useRouteContext(); + + const { + data: { article }, + } = useSuspenseQuery(intentArticleQueryOptions); return ( + - + } /> ); diff --git a/src/routes/_chapters/live-query-filters.tsx b/src/routes/_chapters/live-query-filters.tsx index efd2c33..3cadbff 100644 --- a/src/routes/_chapters/live-query-filters.tsx +++ b/src/routes/_chapters/live-query-filters.tsx @@ -1,8 +1,9 @@ import { createFileRoute } from "@tanstack/react-router"; +import { useSuspenseQuery } from "@tanstack/react-query"; import { useLiveSuspenseQuery, eq, ilike, toArray } from "@tanstack/react-db"; import * as v from "valibot"; import { ChapterSplitColumn } from "~/chapters/chapter-split"; -import { ConsoleCard } from "~/demos/components/console-card"; +import { DemoCard } from "~/demos/components/demo-card"; import { FilterForm } from "~/demos/components/filter-form"; import { PokedexPagination, @@ -19,7 +20,7 @@ import { normalizePokemonNameFilter, toPokemonListing, } from "~/demos/pokemon-listing/pokemon-listing"; -import { getArticle } from "~/articles/article.functions"; +import { getArticleQueryOptions } from "~/articles/article.functions"; const searchParamsSchema = v.object({ offset: v.optional(v.number(), 0), @@ -33,26 +34,34 @@ export const Route = createFileRoute("/_chapters/live-query-filters")({ }, ssr: false, validateSearch: searchParamsSchema, - loader: async () => { - const { Renderable: Article } = await getArticle({ - data: { title: "Reactive filtered data", slug: "live-query-filters" }, + context: () => { + const liveQueryFiltersArticleQueryOptions = getArticleQueryOptions({ + title: "Reactive filtered data", + slug: "live-query-filters", }); - return { Article }; + return { liveQueryFiltersArticleQueryOptions }; + }, + loader: async ({ context: { queryClient, liveQueryFiltersArticleQueryOptions } }) => { + await queryClient.ensureQueryData(liveQueryFiltersArticleQueryOptions); }, component: RouteComponent, }); function RouteComponent() { const { offset: currentOffset, name: nameFilter } = Route.useSearch(); - const { Article } = Route.useLoaderData(); + const { liveQueryFiltersArticleQueryOptions } = Route.useRouteContext(); const navigate = Route.useNavigate(); + const { + data: { article }, + } = useSuspenseQuery(liveQueryFiltersArticleQueryOptions); + return ( - + { @@ -61,9 +70,9 @@ function RouteComponent() { }); }} /> - + - + - + } /> diff --git a/src/routes/_chapters/live-query.tsx b/src/routes/_chapters/live-query.tsx index d1edef8..aea6103 100644 --- a/src/routes/_chapters/live-query.tsx +++ b/src/routes/_chapters/live-query.tsx @@ -1,14 +1,15 @@ import { createFileRoute } from "@tanstack/react-router"; +import { useSuspenseQuery } from "@tanstack/react-query"; import { useLiveSuspenseQuery, eq, toArray } from "@tanstack/react-db"; import * as v from "valibot"; import { ChapterSplitColumn } from "~/chapters/chapter-split"; -import { ConsoleCard } from "~/demos/components/console-card"; +import { DemoCard } from "~/demos/components/demo-card"; import { PokedexPagination, PokedexTableResults, PokedexTableSection, } from "~/demos/components/pokedex-table-section"; -import { getArticle } from "~/articles/article.functions"; +import { getArticleQueryOptions } from "~/articles/article.functions"; import { pokemonCollection, typesCollection, @@ -30,24 +31,32 @@ export const Route = createFileRoute("/_chapters/live-query")({ }, ssr: false, validateSearch: searchParamsSchema, - loader: async () => { - const { Renderable: Article } = await getArticle({ - data: { title: "Synced collection", slug: "live-query" }, + context: () => { + const liveQueryArticleQueryOptions = getArticleQueryOptions({ + title: "Synced collection", + slug: "live-query", }); - return { Article }; + return { liveQueryArticleQueryOptions }; + }, + loader: async ({ context: { queryClient, liveQueryArticleQueryOptions } }) => { + await queryClient.ensureQueryData(liveQueryArticleQueryOptions); }, component: RouteComponent, }); function RouteComponent() { const { offset: currentOffset } = Route.useSearch(); - const { Article } = Route.useLoaderData(); + const { liveQueryArticleQueryOptions } = Route.useRouteContext(); + + const { + data: { article }, + } = useSuspenseQuery(liveQueryArticleQueryOptions); return ( + - + } /> ); diff --git a/src/routes/_chapters/pagination.tsx b/src/routes/_chapters/pagination.tsx index 531ba75..0e07fd5 100644 --- a/src/routes/_chapters/pagination.tsx +++ b/src/routes/_chapters/pagination.tsx @@ -2,14 +2,14 @@ import { createFileRoute, useRouteContext } from "@tanstack/react-router"; import { queryOptions, useSuspenseQuery } from "@tanstack/react-query"; import * as v from "valibot"; import { ChapterSplitColumn } from "~/chapters/chapter-split"; -import { ConsoleCard } from "~/demos/components/console-card"; +import { DemoCard } from "~/demos/components/demo-card"; import { PokedexPagination, PokedexTableResults, PokedexTableSection, } from "~/demos/components/pokedex-table-section"; import { getPokemonListQueryKey, getPokemonListQueryFn } from "~/demos/query/pokemon-query"; -import { getArticle } from "~/articles/article.functions"; +import { getArticleQueryOptions } from "~/articles/article.functions"; const searchParamsSchema = v.object({ offset: v.optional(v.number(), 0), @@ -32,29 +32,38 @@ export const Route = createFileRoute("/_chapters/pagination")({ queryFn: getPokemonListQueryFn, }); + const paginationArticleQueryOptions = getArticleQueryOptions({ + title: "Viewport pagination preload", + slug: "pagination", + }); + return { pokemonListOptions, + paginationArticleQueryOptions, }; }, - loader: async ({ context }) => { - void context.queryClient.prefetchQuery(context.pokemonListOptions); - const { Renderable: Article } = await getArticle({ - data: { title: "Viewport pagination preload", slug: "pagination" }, - }); - return { Article }; + loader: async ({ + context: { queryClient, pokemonListOptions, paginationArticleQueryOptions }, + }) => { + void queryClient.prefetchQuery(pokemonListOptions); + await queryClient.ensureQueryData(paginationArticleQueryOptions); }, component: RouteComponent, }); function RouteComponent() { const { offset: currentOffset } = Route.useSearch(); - const { Article } = Route.useLoaderData(); + const { paginationArticleQueryOptions } = Route.useRouteContext(); + + const { + data: { article }, + } = useSuspenseQuery(paginationArticleQueryOptions); return ( + - + } /> ); diff --git a/src/routes/_chapters/preloading.tsx b/src/routes/_chapters/preloading.tsx index ad7064a..b425c2e 100644 --- a/src/routes/_chapters/preloading.tsx +++ b/src/routes/_chapters/preloading.tsx @@ -2,14 +2,14 @@ import { createFileRoute, useRouteContext } from "@tanstack/react-router"; import { queryOptions, useSuspenseQuery } from "@tanstack/react-query"; import * as v from "valibot"; import { ChapterSplitColumn } from "~/chapters/chapter-split"; -import { ConsoleCard } from "~/demos/components/console-card"; +import { DemoCard } from "~/demos/components/demo-card"; import { PokedexPagination, PokedexTableResults, PokedexTableSection, } from "~/demos/components/pokedex-table-section"; import { getPokemonListQueryKey, getPokemonListQueryFn } from "~/demos/query/pokemon-query"; -import { getArticle } from "~/articles/article.functions"; +import { getArticleQueryOptions } from "~/articles/article.functions"; const searchParamsSchema = v.object({ offset: v.optional(v.number(), 0), @@ -32,29 +32,38 @@ export const Route = createFileRoute("/_chapters/preloading")({ queryFn: getPokemonListQueryFn, }); + const preloadingArticleQueryOptions = getArticleQueryOptions({ + title: "Route-level prefetch", + slug: "preloading", + }); + return { pokemonListOptions, + preloadingArticleQueryOptions, }; }, - loader: async ({ context }) => { - void context.queryClient.prefetchQuery(context.pokemonListOptions); - const { Renderable: Article } = await getArticle({ - data: { title: "Route-level prefetch", slug: "preloading" }, - }); - return { Article }; + loader: async ({ + context: { queryClient, pokemonListOptions, preloadingArticleQueryOptions }, + }) => { + void queryClient.prefetchQuery(pokemonListOptions); + await queryClient.ensureQueryData(preloadingArticleQueryOptions); }, component: RouteComponent, }); function RouteComponent() { const { offset: currentOffset } = Route.useSearch(); - const { Article } = Route.useLoaderData(); + const { preloadingArticleQueryOptions } = Route.useRouteContext(); + + const { + data: { article }, + } = useSuspenseQuery(preloadingArticleQueryOptions); return ( + - + } /> );