Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { JSX } from 'solid-js/jsx-runtime'
import type { ValidationError } from '@tanstack/solid-form'

<% if (codeRouter) { %>
import type { RootRoute } from '@tanstack/react-router'
import type { RootRoute } from '@tanstack/solid-router'
<% } else { %>
export const Route = createFileRoute('/demo/form')({
component: FormExample,
Expand Down
16 changes: 16 additions & 0 deletions templates/solid/add-on/start/assets/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from '@tanstack/solid-start/config'
import viteTsConfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
tsr: {
appDirectory: 'src',
},
vite: {
plugins: [
// this is the plugin that enables path aliases
viteTsConfigPaths({
projects: ['./tsconfig.json'],
}),
],
},
})
5 changes: 5 additions & 0 deletions templates/solid/add-on/start/assets/postcss.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
plugins: {
"@tailwindcss/postcss": {},
},
};
6 changes: 6 additions & 0 deletions templates/solid/add-on/start/assets/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {
createStartAPIHandler,
defaultAPIFileRouteHandler,
} from '@tanstack/solid-start/api'

export default createStartAPIHandler(defaultAPIFileRouteHandler)
7 changes: 7 additions & 0 deletions templates/solid/add-on/start/assets/src/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { hydrate } from 'solid-js/web'
import { StartClient } from '@tanstack/solid-start'
import { createRouter } from './router'

const router = createRouter()

hydrate(() => <StartClient router={router} />, document.body)
24 changes: 24 additions & 0 deletions templates/solid/add-on/start/assets/src/router.tsx.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createRouter as createTanstackRouter } from '@tanstack/solid-router'

// Import the generated route tree
import { routeTree } from './routeTree.gen'

import './styles.css'

// Create a new router instance
export const createRouter = () => {
const router = createTanstackRouter({
routeTree,
scrollRestoration: true,
})
return router
}

const router = createRouter()

// Register the router instance for type safety
declare module '@tanstack/solid-router' {
interface Register {
router: typeof router
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as fs from 'fs'
import { createFileRoute, useRouter } from '@tanstack/solid-router'
import { createServerFn } from '@tanstack/solid-start'

const filePath = 'count.txt'

async function readCount() {
return parseInt(
await fs.promises.readFile(filePath, 'utf-8').catch(() => '0'),
)
}

const getCount = createServerFn({
method: 'GET',
}).handler(() => {
return readCount()
})

const updateCount = createServerFn({ method: 'POST' })
.validator((d: number) => d)
.handler(async ({ data }) => {
const count = await readCount()
await fs.promises.writeFile(filePath, `${count + data}`)
})

export const Route = createFileRoute('/demo/start/server-funcs')({
component: Home,
loader: async () => await getCount(),
})

function Home() {
const router = useRouter()
const state = Route.useLoaderData()

return (
<div class="p-4">
<button
onClick={() => {
updateCount({ data: 1 }).then(() => {
router.invalidate()
})
}}
claclassssName="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
>
Add 1 to {state}?
</button>
</div>
)
}
12 changes: 12 additions & 0 deletions templates/solid/add-on/start/assets/src/ssr.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {
createStartHandler,
defaultStreamHandler,
} from '@tanstack/solid-start/server'
import { getRouterManifest } from '@tanstack/solid-start/router-manifest'

import { createRouter } from './router'

export default createStartHandler({
createRouter,
getRouterManifest,
})(defaultStreamHandler)
14 changes: 14 additions & 0 deletions templates/solid/add-on/start/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Start",
"phase": "setup",
"description": "Add TanStack Start for SSR, API endpoints, and more.",
"link": "https://tanstack.com/start/latest",
"templates": ["file-router"],
"warning": "TanStack Start is not yet at 1.0 and may change significantly or not be compatible with other add-ons.",
"routes": [
{
"url": "/demo/start/server-funcs",
"name": "Start - Server Functions"
}
]
}
14 changes: 14 additions & 0 deletions templates/solid/add-on/start/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"scripts": {
"dev": "vinxi dev",
"build": "vinxi build",
"start": "vinxi start"
},
"dependencies": {
"@tailwindcss/postcss": "^4.0.7",
"@tanstack/solid-start": "^1.114.3",
"postcss": "^8.5.2",
"vinxi": "^0.5.3",
"vite-tsconfig-paths": "^5.1.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useStore } from '@tanstack/solid-store'
import { fullName, store } from '../lib/demo-store'

<% if (codeRouter) { %>
import type { RootRoute } from '@tanstack/react-router'
import type { RootRoute } from '@tanstack/solid-router'
<% } else { %>
export const Route = createFileRoute('/demo/store')({
component: DemoStore,
Expand Down