Skip to content

Commit 757b46c

Browse files
committed
port to solid
1 parent 2262f8b commit 757b46c

File tree

22 files changed

+140
-151
lines changed

22 files changed

+140
-151
lines changed

examples/solid/start-basic-auth/package.json

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "tanstack-start-example-basic-auth",
2+
"name": "tanstack-solid-start-example-basic-auth",
33
"private": true,
44
"sideEffects": false,
55
"type": "module",
@@ -11,20 +11,17 @@
1111
},
1212
"dependencies": {
1313
"@prisma/client": "5.22.0",
14-
"@tanstack/react-router": "^1.133.20",
15-
"@tanstack/react-router-devtools": "^1.133.20",
16-
"@tanstack/react-start": "^1.133.20",
14+
"@tanstack/solid-router": "^1.133.20",
15+
"@tanstack/solid-router-devtools": "^1.133.20",
16+
"@tanstack/solid-start": "^1.133.20",
1717
"prisma": "^5.22.0",
18-
"react": "^19.0.0",
19-
"react-dom": "^19.0.0",
18+
"solid-js": "^1.9.5",
2019
"redaxios": "^0.5.1",
2120
"tailwind-merge": "^2.6.0"
2221
},
2322
"devDependencies": {
24-
"@vitejs/plugin-react": "^4.3.4",
23+
"vite-plugin-solid": "^2.11.9",
2524
"@types/node": "^22.5.4",
26-
"@types/react": "^19.0.8",
27-
"@types/react-dom": "^19.0.3",
2825
"postcss": "^8.5.1",
2926
"autoprefixer": "^10.4.20",
3027
"tailwindcss": "^3.4.17",

examples/solid/start-basic-auth/src/components/Auth.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
1+
import type { JSX } from 'solid-js'
2+
13
export function Auth({
24
actionText,
35
onSubmit,
46
status,
57
afterSubmit,
68
}: {
79
actionText: string
8-
onSubmit: (e: React.FormEvent<HTMLFormElement>) => void
10+
onSubmit: (e: HTMLFormElement) => void
911
status: 'pending' | 'idle' | 'success' | 'error'
10-
afterSubmit?: React.ReactNode
12+
afterSubmit?: JSX.Element
1113
}) {
1214
return (
13-
<div className="fixed inset-0 bg-white dark:bg-black flex items-start justify-center p-8">
14-
<div className="bg-white dark:bg-gray-900 p-8 rounded-lg shadow-lg">
15-
<h1 className="text-2xl font-bold mb-4">{actionText}</h1>
15+
<div class="fixed inset-0 bg-white dark:bg-black flex items-start justify-center p-8">
16+
<div class="bg-white dark:bg-gray-900 p-8 rounded-lg shadow-lg">
17+
<h1 class="text-2xl font-bold mb-4">{actionText}</h1>
1618
<form
17-
onSubmit={(e) => {
19+
onSubmit={(e: any) => {
1820
e.preventDefault()
1921
onSubmit(e)
2022
}}
21-
className="space-y-4"
23+
class="space-y-4"
2224
>
2325
<div>
24-
<label htmlFor="email" className="block text-xs">
26+
<label for="email" class="block text-xs">
2527
Email
2628
</label>
2729
<input
2830
type="email"
2931
name="email"
3032
id="email"
31-
className="px-2 py-1 w-full rounded border border-gray-500/20 bg-white dark:bg-gray-800"
33+
class="px-2 py-1 w-full rounded border border-gray-500/20 bg-white dark:bg-gray-800"
3234
/>
3335
</div>
3436
<div>
35-
<label htmlFor="password" className="block text-xs">
37+
<label for="password" class="block text-xs">
3638
Password
3739
</label>
3840
<input
3941
type="password"
4042
name="password"
4143
id="password"
42-
className="px-2 py-1 w-full rounded border border-gray-500/20 bg-white dark:bg-gray-800"
44+
class="px-2 py-1 w-full rounded border border-gray-500/20 bg-white dark:bg-gray-800"
4345
/>
4446
</div>
4547
<button
4648
type="submit"
47-
className="w-full bg-cyan-600 text-white rounded py-2 font-black uppercase"
49+
class="w-full bg-cyan-600 text-white rounded py-2 font-black uppercase"
4850
disabled={status === 'pending'}
4951
>
5052
{status === 'pending' ? '...' : actionText}

examples/solid/start-basic-auth/src/components/DefaultCatchBoundary.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
rootRouteId,
55
useMatch,
66
useRouter,
7-
} from '@tanstack/react-router'
8-
import type { ErrorComponentProps } from '@tanstack/react-router'
7+
} from '@tanstack/solid-router'
8+
import type { ErrorComponentProps } from '@tanstack/solid-router'
99

1010
export function DefaultCatchBoundary({ error }: ErrorComponentProps) {
1111
const router = useRouter()
@@ -17,28 +17,28 @@ export function DefaultCatchBoundary({ error }: ErrorComponentProps) {
1717
console.error(error)
1818

1919
return (
20-
<div className="min-w-0 flex-1 p-4 flex flex-col items-center justify-center gap-6">
20+
<div class="min-w-0 flex-1 p-4 flex flex-col items-center justify-center gap-6">
2121
<ErrorComponent error={error} />
22-
<div className="flex gap-2 items-center flex-wrap">
22+
<div class="flex gap-2 items-center flex-wrap">
2323
<button
2424
onClick={() => {
2525
router.invalidate()
2626
}}
27-
className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`}
27+
class={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`}
2828
>
2929
Try Again
3030
</button>
31-
{isRoot ? (
31+
{isRoot() ? (
3232
<Link
3333
to="/"
34-
className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`}
34+
class={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`}
3535
>
3636
Home
3737
</Link>
3838
) : (
3939
<Link
4040
to="/"
41-
className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`}
41+
class={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`}
4242
onClick={(e) => {
4343
e.preventDefault()
4444
window.history.back()

examples/solid/start-basic-auth/src/components/Login.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useRouter } from '@tanstack/react-router'
2-
import { useServerFn } from '@tanstack/react-start'
1+
import { useRouter } from '@tanstack/solid-router'
2+
import { useServerFn } from '@tanstack/solid-start'
33
import { useMutation } from '../hooks/useMutation'
44
import { loginFn } from '../routes/_authed'
55
import { Auth } from './Auth'
@@ -26,9 +26,9 @@ export function Login() {
2626
return (
2727
<Auth
2828
actionText="Login"
29-
status={loginMutation.status}
29+
status={loginMutation.status()}
3030
onSubmit={(e) => {
31-
const formData = new FormData(e.target as HTMLFormElement)
31+
const formData = new FormData(e.target as any as HTMLFormElement)
3232

3333
loginMutation.mutate({
3434
data: {
@@ -38,13 +38,13 @@ export function Login() {
3838
})
3939
}}
4040
afterSubmit={
41-
loginMutation.data ? (
41+
loginMutation.data() ? (
4242
<>
43-
<div className="text-red-400">{loginMutation.data.message}</div>
44-
{loginMutation.data.userNotFound ? (
43+
<div class="text-red-400">{loginMutation.data()?.message}</div>
44+
{loginMutation.data()?.userNotFound ? (
4545
<div>
4646
<button
47-
className="text-blue-500"
47+
class="text-blue-500"
4848
onClick={(e) => {
4949
const formData = new FormData(
5050
(e.target as HTMLButtonElement).form!,

examples/solid/start-basic-auth/src/components/NotFound.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { Link } from '@tanstack/react-router'
1+
import { Link } from '@tanstack/solid-router'
22

33
export function NotFound({ children }: { children?: any }) {
44
return (
5-
<div className="space-y-2 p-2">
6-
<div className="text-gray-600 dark:text-gray-400">
5+
<div class="space-y-2 p-2">
6+
<div class="text-gray-600 dark:text-gray-400">
77
{children || <p>The page you are looking for does not exist.</p>}
88
</div>
9-
<p className="flex items-center gap-2 flex-wrap">
9+
<p class="flex items-center gap-2 flex-wrap">
1010
<button
1111
onClick={() => window.history.back()}
12-
className="bg-emerald-500 text-white px-2 py-1 rounded uppercase font-black text-sm"
12+
class="bg-emerald-500 text-white px-2 py-1 rounded uppercase font-black text-sm"
1313
>
1414
Go back
1515
</button>
1616
<Link
1717
to="/"
18-
className="bg-cyan-600 text-white px-2 py-1 rounded uppercase font-black text-sm"
18+
class="bg-cyan-600 text-white px-2 py-1 rounded uppercase font-black text-sm"
1919
>
2020
Start Over
2121
</Link>

examples/solid/start-basic-auth/src/hooks/useMutation.ts

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
1-
import * as React from 'react'
1+
import * as Solid from 'solid-js'
22

33
export function useMutation<TVariables, TData, TError = Error>(opts: {
44
fn: (variables: TVariables) => Promise<TData>
55
onSuccess?: (ctx: { data: TData }) => void | Promise<void>
66
}) {
7-
const [submittedAt, setSubmittedAt] = React.useState<number | undefined>()
8-
const [variables, setVariables] = React.useState<TVariables | undefined>()
9-
const [error, setError] = React.useState<TError | undefined>()
10-
const [data, setData] = React.useState<TData | undefined>()
11-
const [status, setStatus] = React.useState<
7+
const [submittedAt, setSubmittedAt] = Solid.createSignal<number | undefined>()
8+
const [variables, setVariables] = Solid.createSignal<TVariables | undefined>()
9+
const [error, setError] = Solid.createSignal<TError | undefined>()
10+
const [data, setData] = Solid.createSignal<TData | undefined>()
11+
const [status, setStatus] = Solid.createSignal<
1212
'idle' | 'pending' | 'success' | 'error'
1313
>('idle')
1414

15-
const mutate = React.useCallback(
16-
async (variables: TVariables): Promise<TData | undefined> => {
17-
setStatus('pending')
18-
setSubmittedAt(Date.now())
19-
setVariables(variables)
20-
//
21-
try {
22-
const data = await opts.fn(variables)
23-
await opts.onSuccess?.({ data })
24-
setStatus('success')
25-
setError(undefined)
26-
setData(data)
27-
return data
28-
} catch (err: any) {
29-
setStatus('error')
30-
setError(err)
31-
}
32-
},
33-
[opts.fn],
34-
)
15+
const mutate = async (variables: TVariables): Promise<TData | undefined> => {
16+
setStatus('pending')
17+
setSubmittedAt(Date.now())
18+
setVariables(variables as any)
19+
//
20+
try {
21+
const data = await opts.fn(variables)
22+
await opts.onSuccess?.({ data })
23+
setStatus('success')
24+
setError(undefined)
25+
setData(data as any)
26+
return data
27+
} catch (err: any) {
28+
setStatus('error')
29+
setError(err)
30+
}
31+
}
3532

3633
return {
3734
status,

examples/solid/start-basic-auth/src/routeTree.gen.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export interface RootRouteChildren {
118118
SignupRoute: typeof SignupRoute
119119
}
120120

121-
declare module '@tanstack/react-router' {
121+
declare module '@tanstack/solid-router' {
122122
interface FileRoutesByPath {
123123
'/signup': {
124124
id: '/signup'
@@ -215,8 +215,8 @@ export const routeTree = rootRouteImport
215215
._addFileTypes<FileRouteTypes>()
216216

217217
import type { getRouter } from './router.tsx'
218-
import type { createStart } from '@tanstack/react-start'
219-
declare module '@tanstack/react-start' {
218+
import type { createStart } from '@tanstack/solid-start'
219+
declare module '@tanstack/solid-start' {
220220
interface Register {
221221
ssr: true
222222
router: Awaited<ReturnType<typeof getRouter>>

examples/solid/start-basic-auth/src/router.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createRouter } from '@tanstack/react-router'
1+
import { createRouter } from '@tanstack/solid-router'
22
import { routeTree } from './routeTree.gen'
33
import { DefaultCatchBoundary } from './components/DefaultCatchBoundary'
44
import { NotFound } from './components/NotFound'
@@ -15,7 +15,7 @@ export function getRouter() {
1515
return router
1616
}
1717

18-
declare module '@tanstack/react-router' {
18+
declare module '@tanstack/solid-router' {
1919
interface Register {
2020
router: ReturnType<typeof getRouter>
2121
}

examples/solid/start-basic-auth/src/routes/__root.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import {
55
Outlet,
66
Scripts,
77
createRootRoute,
8-
} from '@tanstack/react-router'
9-
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
10-
import { createServerFn } from '@tanstack/react-start'
11-
import * as React from 'react'
8+
} from '@tanstack/solid-router'
9+
import { TanStackRouterDevtools } from '@tanstack/solid-router-devtools'
10+
import { createServerFn } from '@tanstack/solid-start'
11+
import { HydrationScript } from 'solid-js/web'
12+
import type * as Solid from 'solid-js'
1213
import { DefaultCatchBoundary } from '~/components/DefaultCatchBoundary.js'
1314
import { NotFound } from '~/components/NotFound.js'
1415
import appCss from '~/styles/app.css?url'
@@ -39,7 +40,7 @@ export const Route = createRootRoute({
3940
head: () => ({
4041
meta: [
4142
{
42-
charSet: 'utf-8',
43+
charset: 'utf-8',
4344
},
4445
{
4546
name: 'viewport',
@@ -93,20 +94,21 @@ function RootComponent() {
9394
)
9495
}
9596

96-
function RootDocument({ children }: { children: React.ReactNode }) {
97-
const { user } = Route.useRouteContext()
97+
function RootDocument({ children }: { children: Solid.JSX.Element }) {
98+
const routeContext = Route.useRouteContext()
9899

99100
return (
100101
<html>
101102
<head>
102-
<HeadContent />
103+
<HydrationScript />
103104
</head>
104105
<body>
105-
<div className="p-2 flex gap-2 text-lg">
106+
<HeadContent />
107+
<div class="p-2 flex gap-2 text-lg">
106108
<Link
107109
to="/"
108110
activeProps={{
109-
className: 'font-bold',
111+
class: 'font-bold',
110112
}}
111113
activeOptions={{ exact: true }}
112114
>
@@ -115,15 +117,15 @@ function RootDocument({ children }: { children: React.ReactNode }) {
115117
<Link
116118
to="/posts"
117119
activeProps={{
118-
className: 'font-bold',
120+
class: 'font-bold',
119121
}}
120122
>
121123
Posts
122124
</Link>
123-
<div className="ml-auto">
124-
{user ? (
125+
<div class="ml-auto">
126+
{routeContext().user ? (
125127
<>
126-
<span className="mr-2">{user.email}</span>
128+
<span class="mr-2">{routeContext().user?.email}</span>
127129
<Link to="/logout">Logout</Link>
128130
</>
129131
) : (

examples/solid/start-basic-auth/src/routes/_authed.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createFileRoute } from '@tanstack/react-router'
2-
import { createServerFn } from '@tanstack/react-start'
1+
import { createFileRoute } from '@tanstack/solid-router'
2+
import { createServerFn } from '@tanstack/solid-start'
33
import { hashPassword, prismaClient } from '~/utils/prisma'
44
import { Login } from '~/components/Login'
55
import { useAppSession } from '~/utils/session'

0 commit comments

Comments
 (0)