Skip to content

Commit

Permalink
init tanstack start project
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Dec 20, 2024
1 parent d28e848 commit 40ff9fa
Show file tree
Hide file tree
Showing 12 changed files with 4,644 additions and 53 deletions.
4 changes: 3 additions & 1 deletion integration-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"@apollo/experimental-nextjs-app-support": "exec:./shared/build-experimental-nextjs-app-support.cjs",
"@apollo/client-integration-react-router": "exec:./shared/build-client-integration-react-router.cjs",
"graphql": "17.0.0-alpha.2",
"turbo-stream": "npm:@phryneas/[email protected]"
"turbo-stream": "npm:@phryneas/[email protected]",
"@tanstack/react-router": "patch:@tanstack/react-router@npm%3A1.91.3#~/../.yarn/patches/@tanstack-react-router-npm-1.91.3-8e077b923e.patch",
"@tanstack/start": "patch:@tanstack/start@npm%3A1.91.3#~/../.yarn/patches/@tanstack-start-npm-1.91.3-de6292cf0b.patch"
},
"workspaces": [
"*"
Expand Down
3 changes: 3 additions & 0 deletions integration-test/tanstack-start/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from "@tanstack/start/config";

export default defineConfig({});
8 changes: 8 additions & 0 deletions integration-test/tanstack-start/app/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// <reference types="vinxi/types/client" />
import { hydrateRoot } from "react-dom/client";
import { StartClient } from "@tanstack/start";
import { createRouter } from "./router";

const router = createRouter();

hydrateRoot(document, <StartClient router={router} />);
88 changes: 88 additions & 0 deletions integration-test/tanstack-start/app/routeTree.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* 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 Routes

import { Route as rootRoute } from './routes/__root'
import { Route as IndexImport } from './routes/index'

// Create/Update Routes

const IndexRoute = IndexImport.update({
id: '/',
path: '/',
getParentRoute: () => rootRoute,
} as any)

// Populate the FileRoutesByPath interface

declare module '@tanstack/react-router' {
interface FileRoutesByPath {
'/': {
id: '/'
path: '/'
fullPath: '/'
preLoaderRoute: typeof IndexImport
parentRoute: typeof rootRoute
}
}
}

// Create and export the route tree

export interface FileRoutesByFullPath {
'/': typeof IndexRoute
}

export interface FileRoutesByTo {
'/': typeof IndexRoute
}

export interface FileRoutesById {
__root__: typeof rootRoute
'/': typeof IndexRoute
}

export interface FileRouteTypes {
fileRoutesByFullPath: FileRoutesByFullPath
fullPaths: '/'
fileRoutesByTo: FileRoutesByTo
to: '/'
id: '__root__' | '/'
fileRoutesById: FileRoutesById
}

export interface RootRouteChildren {
IndexRoute: typeof IndexRoute
}

const rootRouteChildren: RootRouteChildren = {
IndexRoute: IndexRoute,
}

export const routeTree = rootRoute
._addFileChildren(rootRouteChildren)
._addFileTypes<FileRouteTypes>()

/* ROUTE_MANIFEST_START
{
"routes": {
"__root__": {
"filePath": "__root.tsx",
"children": [
"/"
]
},
"/": {
"filePath": "index.tsx"
}
}
}
ROUTE_MANIFEST_END */
16 changes: 16 additions & 0 deletions integration-test/tanstack-start/app/router.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createRouter as createTanStackRouter } from "@tanstack/react-router";
import { routeTree } from "./routeTree.gen";

export function createRouter() {
const router = createTanStackRouter({
routeTree,
});

return router;
}

declare module "@tanstack/react-router" {
interface Register {
router: ReturnType<typeof createRouter>;
}
}
48 changes: 48 additions & 0 deletions integration-test/tanstack-start/app/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
Outlet,
ScrollRestoration,
createRootRoute,
} from "@tanstack/react-router";
import { Meta, Scripts } from "@tanstack/start";
import type { ReactNode } from "react";

export const Route = createRootRoute({
head: () => ({
meta: [
{
charSet: "utf-8",
},
{
name: "viewport",
content: "width=device-width, initial-scale=1",
},
{
title: "TanStack Start Starter",
},
],
}),
component: RootComponent,
});

function RootComponent() {
return (
<RootDocument>
<Outlet />
</RootDocument>
);
}

function RootDocument({ children }: Readonly<{ children: ReactNode }>) {
return (
<html>
<head>
<Meta />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}
47 changes: 47 additions & 0 deletions integration-test/tanstack-start/app/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as fs from "node:fs";
import { createFileRoute, useRouter } from "@tanstack/react-router";
import { createServerFn } from "@tanstack/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("/")({
component: Home,
loader: async () => await getCount(),
});

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

return (
<button
type="button"
onClick={() => {
updateCount({ data: 1 }).then(() => {
router.invalidate();
});
}}
>
Add 1 to {state}?
</button>
);
}
13 changes: 13 additions & 0 deletions integration-test/tanstack-start/app/ssr.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// <reference types="vinxi/types/server" />
import {
createStartHandler,
defaultStreamHandler,
} from "@tanstack/start/server";
import { getRouterManifest } from "@tanstack/start/router-manifest";

import { createRouter } from "./router";

export default createStartHandler({
createRouter,
getRouterManifest,
})(defaultStreamHandler);
22 changes: 22 additions & 0 deletions integration-test/tanstack-start/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "tanstack-start",
"type": "module",
"scripts": {
"dev": "vinxi dev",
"build": "vinxi build",
"start": "vinxi start"
},
"dependencies": {
"@tanstack/react-router": "1.91.3",
"@tanstack/start": "1.91.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"vinxi": "^0.5.1"
},
"devDependencies": {
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@vitejs/plugin-react": "^4.3.4",
"typescript": "^5.7.2"
}
}
10 changes: 10 additions & 0 deletions integration-test/tanstack-start/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"moduleResolution": "Bundler",
"module": "ESNext",
"target": "ES2022",
"skipLibCheck": true,
"strictNullChecks": true,
},
}
Loading

0 comments on commit 40ff9fa

Please sign in to comment.