-
Notifications
You must be signed in to change notification settings - Fork 144
feat(examples): add TanStack Start example #1325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edmundhung
wants to merge
3
commits into
main
Choose a base branch
from
edmundhung/tanstack-start-example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,041
−2
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| node_modules | ||
| .output | ||
| .tanstack | ||
| dist | ||
| /playwright-report | ||
| /test-results |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # TanStack Start Example | ||
|
|
||
| This example demonstrates how to combine Conform with TanStack Start server | ||
| functions: | ||
|
|
||
| - [Basic form with manual validation](./src/routes/login.tsx) | ||
| - [Async validation](./src/routes/signup.tsx) ([with an async schema](./src/routes/signup-async-schema.tsx)) | ||
| - [Dynamic form with data persistence](./src/routes/todos.tsx) | ||
| - [File uploads](./src/routes/file-upload.tsx) with `FormData` and native `File` values | ||
|
|
||
| Each route passes Conform's `FormData` to a TanStack Start server function with | ||
| `useServerFn`. The server function performs trusted validation and the mutation, | ||
| then its Conform submission report is applied back to the form. Redirects are | ||
| handled by `useServerFn`. | ||
|
|
||
| Try it out on [StackBlitz](https://stackblitz.com/github/edmundhung/conform/tree/main/examples/tanstack-start). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| { | ||
| "name": "tanstack-start-example", | ||
| "private": true, | ||
| "type": "module", | ||
| "imports": { | ||
| "#/*": "./src/*" | ||
| }, | ||
| "scripts": { | ||
| "build": "vite build", | ||
| "dev": "vite dev --port 3000", | ||
| "generate-routes": "tsr generate", | ||
| "preview": "vite preview", | ||
| "test": "playwright test", | ||
| "typecheck": "tsr generate && tsc" | ||
| }, | ||
| "dependencies": { | ||
| "@conform-to/react": "1.21.1", | ||
| "@conform-to/zod": "1.21.1", | ||
| "@tanstack/react-router": "1.170.31", | ||
| "@tanstack/react-start": "1.168.48", | ||
| "react": "^19.2.7", | ||
| "react-dom": "^19.2.7", | ||
| "zod": "^4.4.3" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "1.62.1", | ||
| "@tanstack/router-cli": "1.167.32", | ||
| "@types/node": "^22", | ||
| "@types/react": "^19.2.17", | ||
| "@types/react-dom": "^19.2.3", | ||
| "@vitejs/plugin-react": "^6.1.0", | ||
| "typescript": "^5.9.3", | ||
| "vite": "^8.2.1" | ||
| }, | ||
| "dependenciesMeta": { | ||
| "@conform-to/react": { | ||
| "injected": true | ||
| }, | ||
| "@conform-to/zod": { | ||
| "injected": true | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { defineConfig, devices } from '@playwright/test'; | ||
|
|
||
| export default defineConfig({ | ||
| testDir: 'tests', | ||
| forbidOnly: !!process.env.CI, | ||
| retries: process.env.CI ? 2 : 0, | ||
| workers: process.env.CI ? 1 : undefined, | ||
| reporter: process.env.CI ? 'github' : undefined, | ||
| use: { | ||
| trace: 'on-first-retry', | ||
| }, | ||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: devices['Desktop Chrome'], | ||
| }, | ||
| { | ||
| name: 'firefox', | ||
| use: devices['Desktop Firefox'], | ||
| }, | ||
| { | ||
| name: 'webkit', | ||
| use: devices['Desktop Safari'], | ||
| }, | ||
| ], | ||
| webServer: { | ||
| command: 'pnpm run build && pnpm run preview --port 5681', | ||
| port: 5681, | ||
| reuseExistingServer: !process.env.CI, | ||
| timeout: 120000, | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| /* eslint-disable */ | ||
|
|
||
| // @ts-nocheck | ||
|
|
||
| // noinspection JSUnusedGlobalSymbols | ||
|
|
||
| // This file was automatically generated by TanStack Router. | ||
| // You should NOT make any changes in this file as it will be overwritten. | ||
| // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. | ||
|
|
||
| import { Route as rootRouteImport } from './routes/__root' | ||
| import { Route as IndexRouteImport } from './routes/index' | ||
| import { Route as FileUploadRouteImport } from './routes/file-upload' | ||
| import { Route as LoginRouteImport } from './routes/login' | ||
| import { Route as SignupRouteImport } from './routes/signup' | ||
| import { Route as SignupAsyncSchemaRouteImport } from './routes/signup-async-schema' | ||
| import { Route as TodosRouteImport } from './routes/todos' | ||
|
|
||
| const IndexRoute = IndexRouteImport.update({ | ||
| id: '/', | ||
| path: '/', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
| const FileUploadRoute = FileUploadRouteImport.update({ | ||
| id: '/file-upload', | ||
| path: '/file-upload', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
| const LoginRoute = LoginRouteImport.update({ | ||
| id: '/login', | ||
| path: '/login', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
| const SignupRoute = SignupRouteImport.update({ | ||
| id: '/signup', | ||
| path: '/signup', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
| const SignupAsyncSchemaRoute = SignupAsyncSchemaRouteImport.update({ | ||
| id: '/signup-async-schema', | ||
| path: '/signup-async-schema', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
| const TodosRoute = TodosRouteImport.update({ | ||
| id: '/todos', | ||
| path: '/todos', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
|
|
||
| export interface FileRoutesByFullPath { | ||
| '/': typeof IndexRoute | ||
| '/file-upload': typeof FileUploadRoute | ||
| '/login': typeof LoginRoute | ||
| '/signup': typeof SignupRoute | ||
| '/signup-async-schema': typeof SignupAsyncSchemaRoute | ||
| '/todos': typeof TodosRoute | ||
| } | ||
| export interface FileRoutesByTo { | ||
| '/': typeof IndexRoute | ||
| '/file-upload': typeof FileUploadRoute | ||
| '/login': typeof LoginRoute | ||
| '/signup': typeof SignupRoute | ||
| '/signup-async-schema': typeof SignupAsyncSchemaRoute | ||
| '/todos': typeof TodosRoute | ||
| } | ||
| export interface FileRoutesById { | ||
| __root__: typeof rootRouteImport | ||
| '/': typeof IndexRoute | ||
| '/file-upload': typeof FileUploadRoute | ||
| '/login': typeof LoginRoute | ||
| '/signup': typeof SignupRoute | ||
| '/signup-async-schema': typeof SignupAsyncSchemaRoute | ||
| '/todos': typeof TodosRoute | ||
| } | ||
| export interface FileRouteTypes { | ||
| fileRoutesByFullPath: FileRoutesByFullPath | ||
| fullPaths: | ||
| | '/' | ||
| | '/file-upload' | ||
| | '/login' | ||
| | '/signup' | ||
| | '/signup-async-schema' | ||
| | '/todos' | ||
| fileRoutesByTo: FileRoutesByTo | ||
| to: | ||
| | '/' | ||
| | '/file-upload' | ||
| | '/login' | ||
| | '/signup' | ||
| | '/signup-async-schema' | ||
| | '/todos' | ||
| id: | ||
| | '__root__' | ||
| | '/' | ||
| | '/file-upload' | ||
| | '/login' | ||
| | '/signup' | ||
| | '/signup-async-schema' | ||
| | '/todos' | ||
| fileRoutesById: FileRoutesById | ||
| } | ||
| export interface RootRouteChildren { | ||
| IndexRoute: typeof IndexRoute | ||
| FileUploadRoute: typeof FileUploadRoute | ||
| LoginRoute: typeof LoginRoute | ||
| SignupRoute: typeof SignupRoute | ||
| SignupAsyncSchemaRoute: typeof SignupAsyncSchemaRoute | ||
| TodosRoute: typeof TodosRoute | ||
| } | ||
|
|
||
| declare module '@tanstack/react-router' { | ||
| interface FileRoutesByPath { | ||
| '/': { | ||
| id: '/' | ||
| path: '/' | ||
| fullPath: '/' | ||
| preLoaderRoute: typeof IndexRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| '/file-upload': { | ||
| id: '/file-upload' | ||
| path: '/file-upload' | ||
| fullPath: '/file-upload' | ||
| preLoaderRoute: typeof FileUploadRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| '/login': { | ||
| id: '/login' | ||
| path: '/login' | ||
| fullPath: '/login' | ||
| preLoaderRoute: typeof LoginRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| '/signup': { | ||
| id: '/signup' | ||
| path: '/signup' | ||
| fullPath: '/signup' | ||
| preLoaderRoute: typeof SignupRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| '/signup-async-schema': { | ||
| id: '/signup-async-schema' | ||
| path: '/signup-async-schema' | ||
| fullPath: '/signup-async-schema' | ||
| preLoaderRoute: typeof SignupAsyncSchemaRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| '/todos': { | ||
| id: '/todos' | ||
| path: '/todos' | ||
| fullPath: '/todos' | ||
| preLoaderRoute: typeof TodosRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const rootRouteChildren: RootRouteChildren = { | ||
| IndexRoute: IndexRoute, | ||
| FileUploadRoute: FileUploadRoute, | ||
| LoginRoute: LoginRoute, | ||
| SignupRoute: SignupRoute, | ||
| SignupAsyncSchemaRoute: SignupAsyncSchemaRoute, | ||
| TodosRoute: TodosRoute, | ||
| } | ||
| export const routeTree = rootRouteImport | ||
| ._addFileChildren(rootRouteChildren) | ||
| ._addFileTypes<FileRouteTypes>() | ||
|
|
||
| import type { getRouter } from './router.tsx' | ||
| import type { createStart } from '@tanstack/react-start' | ||
| declare module '@tanstack/react-start' { | ||
| interface Register { | ||
| ssr: true | ||
| router: Awaited<ReturnType<typeof getRouter>> | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { createRouter as createTanStackRouter } from '@tanstack/react-router'; | ||
| import { routeTree } from './routeTree.gen'; | ||
|
|
||
| export function getRouter() { | ||
| return createTanStackRouter({ | ||
| routeTree, | ||
| scrollRestoration: true, | ||
| defaultPreload: 'intent', | ||
| defaultPreloadStaleTime: 0, | ||
| }); | ||
| } | ||
|
|
||
| declare module '@tanstack/react-router' { | ||
| interface Register { | ||
| router: ReturnType<typeof getRouter>; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.