Skip to content

Commit cea7d7d

Browse files
authored
fix(examples): tanstack-start build issues (#2248)
* fix(examples): move server function in another file This fixes a build issue when using macro in a file that uses server-side function * fix(examples): use i18n instead of macro in server-side function
1 parent 7a8256c commit cea7d7d

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createServerFn } from "@tanstack/react-start"
2+
3+
export const personServerFn = createServerFn({ method: "GET" })
4+
.validator((d: string) => d)
5+
.handler(({ data: name }) => {
6+
return { name, randomNumber: Math.floor(Math.random() * 100) }
7+
})
8+
9+
export const slowServerFn = createServerFn({ method: "GET" })
10+
.validator((d: string) => d)
11+
.handler(async ({ data: name }) => {
12+
await new Promise((r) => setTimeout(r, 1000))
13+
return { name, randomNumber: Math.floor(Math.random() * 100) }
14+
})

examples/tanstack-start/src/routes/deferred.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
import { Trans } from "@lingui/react/macro"
22
import { Await, createFileRoute } from "@tanstack/react-router"
3-
import { createServerFn } from "@tanstack/react-start"
43
import { Suspense, useState } from "react"
5-
6-
const personServerFn = createServerFn({ method: "GET" })
7-
.validator((d: string) => d)
8-
.handler(({ data: name }) => {
9-
return { name, randomNumber: Math.floor(Math.random() * 100) }
10-
})
11-
12-
const slowServerFn = createServerFn({ method: "GET" })
13-
.validator((d: string) => d)
14-
.handler(async ({ data: name }) => {
15-
await new Promise((r) => setTimeout(r, 1000))
16-
return { name, randomNumber: Math.floor(Math.random() * 100) }
17-
})
4+
import { personServerFn, slowServerFn } from "~/functions/deferred"
185

196
export const Route = createFileRoute("/deferred")({
207
loader: async () => {

examples/tanstack-start/src/routes/users.$userId.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { i18n } from "@lingui/core"
12
import { Trans } from "@lingui/react/macro"
23
import { createFileRoute } from "@tanstack/react-router"
34
import axios from "redaxios"
45
import type { User } from "~/utils/users"
56
import { DEPLOY_URL } from "~/utils/users"
67
import { NotFound } from "~/components/NotFound"
78
import { UserErrorComponent } from "~/components/UserError"
8-
import { i18n } from "@lingui/core"
99

1010
export const Route = createFileRoute("/users/$userId")({
1111
loader: async ({ params: { userId } }) => {

0 commit comments

Comments
 (0)