A full page for [b2c-b2b.md](b2c-b2b.md): device detection, caches, a server page loader, the page entrypoint, streamed parts, and query hydration. Read it when you add a new page, or a part that reads server data in a way the repo doesn't have yet. Otherwise copy the shape of an existing page.
`platforms/<app>/src/shared/utils/get-device.ts`
```ts
import 'server-only';
import { headers } from 'next/headers';
import { userAgent } from 'next/server';
export async function getDevice(): Promise<'mobile' | 'desktop'> {
`apps/<app>/src/app/(shop)/product/[id]/page.tsx`. `generateMetadata` and the page both call `getProduct(id)`, and the cache sends one request. A page whose main read can answer 404 or 403 reads through `readOnServer` instead, as the seller page in [error-handling-code.md](error-handling-code.md) does.
The desktop template, a Server Component, renders the product at once and streams the two slower parts, each behind its own part boundary ([error-handling.md](error-handling.md#boundaries)):
```tsx
<ProductSummaryproduct={product}/>
<PartBoundaryname="related-products">
<Suspensefallback={<RelatedProductsSkeleton/>}>
<RelatedProductsproductId={product.id}/>
</Suspense>
</PartBoundary>
<PartBoundaryname="product-reviews">
<Suspensefallback={<ProductReviewsSkeleton/>}>
<ProductReviewsproductId={product.id}/>
</Suspense>
</PartBoundary>
```
`.../product/[id]/organisms/related-products/RelatedProducts.tsx`. The client only shows this part, so it stays a Server Component.
```tsx
import { getRelatedProducts } from '@project/<platform>/server';
import { ProductRail } from '@project/island/organisms/product-rail';
import type { RelatedProductsProps } from './types';
export async function RelatedProducts({ productId }: RelatedProductsProps) {
`.../product/[id]/organisms/product-reviews/ProductReviews.tsx`. The client pages through reviews, so this part hands its first page over through query hydration. `ReviewsList` is a client component that calls the part model.
```tsx
import { reviewKeys } from '@project/<platform>/features/catalog';
import { getProductReviews } from '@project/<platform>/server';
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
import { getQueryClient } from '../../../../../../configs';
import { ReviewsList } from './components/reviews-list';
import type { ProductReviewsProps } from './types';
export async function ProductReviews({ productId }: ProductReviewsProps) {
const queryClient = getQueryClient();
await queryClient.prefetchQuery({
queryKey: reviewKeys.list(productId, 1),
queryFn: () => getProductReviews(productId, 1),
});
return (
<HydrationBoundarystate={dehydrate(queryClient)}>
<ReviewsListproductId={productId}/>
</HydrationBoundary>
);
}
```
`platforms/<app>/src/features/catalog/models/product/use-product-reviews-part.ts`. Page 1 comes from the server; later pages load in the browser while the current page stays visible.
```ts
import { keepPreviousData, useQuery } from '@tanstack/react-query';
import { useState } from 'react';
import { productsRepository, reviewKeys } from '../../repositories/products';
export function useProductReviewsPart(productId: string) {
const [page, setPage] = useState(1);
const reviews = useQuery({
queryKey: reviewKeys.list(productId, page),
queryFn: ({ signal }) => productsRepository.listReviews({ id: productId, page }, { signal }),
placeholderData: keepPreviousData,
});
return { reviews, page, setPage };
}
```
`apps/<app>/src/configs/react-query.ts`. The app's root client component passes `getQueryClient()` to `QueryClientProvider`. Older TanStack Query v5 releases use the `isServer` constant instead of `environmentManager.isServer()`. The error settings are explained in [error-handling.md](error-handling.md#reads).
```ts
import { handleError } from '@project/libs/error-handler';
import {
defaultShouldDehydrateQuery,
environmentManager,
QueryCache,
QueryClient,
} from '@tanstack/react-query';
function makeQueryClient(): QueryClient {
return new QueryClient({
queryCache: new QueryCache({
onError: (error, query) => {
if (query.state.data !== undefined) handleError(error, { where: 'refetch' });