Skip to content

Commit eaff541

Browse files
ci: apply automated fixes
1 parent 5d93245 commit eaff541

7 files changed

+71
-52
lines changed

SSR_ALT_NEXTJS_EXAMPLE.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ export const getAccountCollection = defineCollection(
6666
export const getCatalogGridLiveQuery = defineLiveQuery((scope) =>
6767
liveQueryCollectionOptions({
6868
id: `catalog-grid`,
69-
query: (q) => q.from({ c: getCatalogCollection(scope) }).orderBy(({ c }) => c.name),
69+
query: (q) =>
70+
q.from({ c: getCatalogCollection(scope) }).orderBy(({ c }) => c.name),
7071
ssr: { serializes: true },
7172
}),
7273
)
@@ -75,7 +76,8 @@ export const getAccountSummaryLiveQuery = defineLiveQuery(
7576
({ userId }: { userId: string }, scope: DbScope) =>
7677
liveQueryCollectionOptions({
7778
id: `account-summary:${userId}`,
78-
query: (q) => q.from({ a: getAccountCollection({ userId }, scope) }).findOne(),
79+
query: (q) =>
80+
q.from({ a: getAccountCollection({ userId }, scope) }).findOne(),
7981
ssr: { serializes: true },
8082
}),
8183
{ scope: 'required' },
@@ -164,10 +166,7 @@ export function StorePageClient({ userId }: { userId: string }) {
164166
import type { GetServerSideProps } from 'next'
165167
import { createDbScope } from '@tanstack/db/ssr'
166168
import { ProvideDbScope } from '@tanstack/react-db/ssr'
167-
import {
168-
getAccountCollection,
169-
getAccountSummaryLiveQuery,
170-
} from '@/db/getters'
169+
import { getAccountCollection, getAccountSummaryLiveQuery } from '@/db/getters'
171170
import { StorePageClient } from '@/app/store/StorePageClient'
172171

173172
export const getServerSideProps: GetServerSideProps = async (ctx) => {

SSR_ALT_REACT_ROUTER_REMIX_EXAMPLE.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export const getAccountCollection = defineCollection(
4141
export const getCatalogGridLiveQuery = defineLiveQuery((scope?: DbScope) =>
4242
liveQueryCollectionOptions({
4343
id: `catalog-grid`,
44-
query: (q) => q.from({ c: getCatalogCollection(scope) }).orderBy(({ c }) => c.name),
44+
query: (q) =>
45+
q.from({ c: getCatalogCollection(scope) }).orderBy(({ c }) => c.name),
4546
ssr: { serializes: true },
4647
}),
4748
)
@@ -50,7 +51,8 @@ export const getAccountSummaryLiveQuery = defineLiveQuery(
5051
({ userId }: { userId: string }, scope: DbScope) =>
5152
liveQueryCollectionOptions({
5253
id: `account-summary:${userId}`,
53-
query: (q) => q.from({ a: getAccountCollection({ userId }, scope) }).findOne(),
54+
query: (q) =>
55+
q.from({ a: getAccountCollection({ userId }, scope) }).findOne(),
5456
ssr: { serializes: true },
5557
}),
5658
{ scope: 'required' },

SSR_ALT_TANSTACK_START_EXAMPLE.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export const getAccountCollection = defineCollection(
3939
export const getCatalogGridLiveQuery = defineLiveQuery((scope?: DbScope) =>
4040
liveQueryCollectionOptions({
4141
id: `catalog-grid`,
42-
query: (q) => q.from({ c: getCatalogCollection(scope) }).orderBy(({ c }) => c.name),
42+
query: (q) =>
43+
q.from({ c: getCatalogCollection(scope) }).orderBy(({ c }) => c.name),
4344
ssr: { serializes: true },
4445
}),
4546
)
@@ -48,7 +49,8 @@ export const getAccountSummaryLiveQuery = defineLiveQuery(
4849
({ userId }: { userId: string }, scope: DbScope) =>
4950
liveQueryCollectionOptions({
5051
id: `account-summary:${userId}`,
51-
query: (q) => q.from({ a: getAccountCollection({ userId }, scope) }).findOne(),
52+
query: (q) =>
53+
q.from({ a: getAccountCollection({ userId }, scope) }).findOne(),
5254
ssr: { serializes: true },
5355
}),
5456
{ scope: 'required' },
@@ -104,13 +106,15 @@ TanStack Start calls `createRouter()` per server request, so `dbScope` is reques
104106
// src/start/middleware/db-scope.ts
105107
import { createMiddleware } from '@tanstack/start'
106108

107-
export const dbScopeMiddleware = createMiddleware().server(async ({ next, context }) => {
108-
try {
109-
return await next()
110-
} finally {
111-
await context.dbScope.cleanup()
112-
}
113-
})
109+
export const dbScopeMiddleware = createMiddleware().server(
110+
async ({ next, context }) => {
111+
try {
112+
return await next()
113+
} finally {
114+
await context.dbScope.cleanup()
115+
}
116+
},
117+
)
114118
```
115119

116120
Cleanup runs after the full response lifecycle, not inside individual loaders.

SSR_DESIGN.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,16 @@ export interface DbSharedEnvironment {
114114
export interface DbRequestScope<TCollections extends CollectionMap> {
115115
readonly id: string
116116
readonly collections: TCollections
117-
readonly collectionScopes: Partial<Record<keyof TCollections, ServerCollectionScope>>
117+
readonly collectionScopes: Partial<
118+
Record<keyof TCollections, ServerCollectionScope>
119+
>
118120
readonly prefetchedQueries: Map<string, DehydratedQueryRecord>
119121
cleanup(): Promise<void>
120122
}
121123

122-
export interface CreateDbRequestScopeOptions<TCollections extends CollectionMap> {
124+
export interface CreateDbRequestScopeOptions<
125+
TCollections extends CollectionMap,
126+
> {
123127
shared?: DbSharedEnvironment
124128
createCollections: (ctx: { shared: DbSharedEnvironment }) => TCollections
125129
collectionScopes?: Partial<Record<keyof TCollections, ServerCollectionScope>>
@@ -228,7 +232,9 @@ export interface DehydrateDbScopeOptions<TCollections extends CollectionMap> {
228232
transform?: Partial<
229233
Record<
230234
keyof TCollections,
231-
(snapshot: CollectionSnapshot<unknown>) => CollectionSnapshot<unknown>
235+
(
236+
snapshot: CollectionSnapshot<unknown>,
237+
) => CollectionSnapshot<unknown>
232238
>
233239
>
234240
}
@@ -381,7 +387,8 @@ Then bind scopes explicitly in request creation:
381387
```ts
382388
const scope = createDbRequestScope({
383389
shared: sharedEnv,
384-
createCollections: ({ shared }) => createServerCollections({ request, shared }),
390+
createCollections: ({ shared }) =>
391+
createServerCollections({ request, shared }),
385392
collectionScopes: {
386393
catalog: `process`,
387394
account: `request`,

SSR_NEXTJS_EXAMPLE.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,19 @@ import { queryCollectionOptions } from '@tanstack/query-db-collection'
3535

3636
type CreateServerCollectionsArgs = {
3737
request: Request
38-
shared: ReturnType<typeof import('@tanstack/db/ssr').createDbSharedEnvironment>
38+
shared: ReturnType<
39+
typeof import('@tanstack/db/ssr').createDbSharedEnvironment
40+
>
3941
}
4042

41-
export function createServerCollections({ request, shared }: CreateServerCollectionsArgs) {
42-
const sharedQueryClient = shared.getOrCreate(`catalog-query-client`, () => new QueryClient())
43+
export function createServerCollections({
44+
request,
45+
shared,
46+
}: CreateServerCollectionsArgs) {
47+
const sharedQueryClient = shared.getOrCreate(
48+
`catalog-query-client`,
49+
() => new QueryClient(),
50+
)
4351
const catalogCollection = shared.getOrCreate(`catalog-collection`, () =>
4452
createCollection(
4553
queryCollectionOptions({
@@ -210,7 +218,10 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
210218
const scope = createDbRequestScope({
211219
shared: sharedDbEnv,
212220
createCollections: ({ shared }) =>
213-
createServerCollections({ request: ctx.req as unknown as Request, shared }),
221+
createServerCollections({
222+
request: ctx.req as unknown as Request,
223+
shared,
224+
}),
214225
collectionScopes: {
215226
catalog: `process`,
216227
account: `request`,

SSR_REACT_ROUTER_REMIX_EXAMPLE.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ export default createRequestHandler({
5656

5757
```ts
5858
// app/routes/store.tsx
59-
import {
60-
prefetchDbQuery,
61-
dehydrateDbScope,
62-
} from '@tanstack/db/ssr'
59+
import { prefetchDbQuery, dehydrateDbScope } from '@tanstack/db/ssr'
6360

6461
export async function loader({ context }: LoaderFunctionArgs) {
6562
const { dbScope } = context

SSR_TANSTACK_START_EXAMPLE.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,36 @@ import { createDbRequestScope } from '@tanstack/db/ssr'
2020
import { sharedDbEnv } from '@/db/server-shared'
2121
import { createServerCollections } from '@/db/createServerCollections'
2222

23-
export const dbScopeMiddleware = createMiddleware().server(async ({ request, next }) => {
24-
const dbScope = createDbRequestScope({
25-
shared: sharedDbEnv,
26-
createCollections: ({ shared }) =>
27-
createServerCollections({ request, shared }),
28-
collectionScopes: {
29-
catalog: `process`,
30-
account: `request`,
31-
},
32-
})
33-
34-
try {
35-
return await next({
36-
context: {
37-
dbScope,
23+
export const dbScopeMiddleware = createMiddleware().server(
24+
async ({ request, next }) => {
25+
const dbScope = createDbRequestScope({
26+
shared: sharedDbEnv,
27+
createCollections: ({ shared }) =>
28+
createServerCollections({ request, shared }),
29+
collectionScopes: {
30+
catalog: `process`,
31+
account: `request`,
3832
},
3933
})
40-
} finally {
41-
await dbScope.cleanup()
42-
}
43-
})
34+
35+
try {
36+
return await next({
37+
context: {
38+
dbScope,
39+
},
40+
})
41+
} finally {
42+
await dbScope.cleanup()
43+
}
44+
},
45+
)
4446
```
4547

4648
## 3) Route Loader: Prefetch with Request Scope
4749

4850
```tsx
4951
// src/routes/store.tsx
50-
import {
51-
prefetchDbQuery,
52-
dehydrateDbScope,
53-
} from '@tanstack/db/ssr'
52+
import { prefetchDbQuery, dehydrateDbScope } from '@tanstack/db/ssr'
5453
import { createFileRoute } from '@tanstack/react-router'
5554
import { HydrationBoundary } from '@tanstack/react-db/hydration'
5655

0 commit comments

Comments
 (0)