Skip to content

Commit

Permalink
fix: replace vinxi/https exports with start/server exports
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Jan 21, 2025
1 parent f21186e commit 2d182c7
Show file tree
Hide file tree
Showing 22 changed files with 496 additions and 79 deletions.
17 changes: 12 additions & 5 deletions docs/framework/react/guide/tanstack-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,36 @@ Create a `tsconfig.json` file with at least the following settings:

# Install Dependencies

TanStack Start is powered by [Vinxi](https://vinxi.vercel.app/) and [TanStack Router](https://tanstack.com/router) and requires them as dependencies.
TanStack Start is powered by the following packages and need to be installed as dependencies:

- [@tanstack/start](https://github.com/tanstack/start)
- [@tanstack/react-router](https://tanstack.com/router)
- [Vinxi](https://vinxi.vercel.app/)

> [!NOTE]
> Vinxi is a temporary dependency that will be replaced by a simple vite plugin or a dedicated Start CLI.
To install them, run:

```shell
npm i @tanstack/start @tanstack/react-router vinxi
```

You'll also need React and the Vite React plugin, so install them too:
You'll also need React and the Vite React plugin, so install their dependencies as well:

```shell
npm i react react-dom @vitejs/plugin-react
```

and some TypeScript:
Please, for you, your fellow developers, and your users' sake, use TypeScript:

```shell
npm i -D typescript @types/react @types/react-dom
```

# Update Configuration Files

We'll then update our `package.json` to reference the new Vinxi entry point and set `"type": "module"`:
We'll then update our `package.json` to use Vinxi's CLI and set `"type": "module"`:

```jsonc
{
Expand All @@ -79,7 +86,7 @@ We'll then update our `package.json` to reference the new Vinxi entry point and
}
```

To tell Vinxi that it should start TanStack Start's minimal behavior, we need to configure the `app.config.ts` file:
Then configure TanStack Start's `app.config.ts` file:

```typescript
// app.config.ts
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/react/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ It's probably no surprise at this point that picking a router is so important th

**Does this mean that TanStack Router is a framework?**

TanStack Router itself is not a "framework" in the traditional sense, since it doesn't address a few other common full-stack concerns. However TanStack Router has been designed to be upgradable to a full-stack framework when used in conjunction with other tools that address bundling, deployments, and server-side-specific functionality. This is why we are currently developing [TanStack Start](https://tanstack.com/start), a full-stack framework that is built on top of TanStack Router and tools like Vinxi, Nitro, and Vite.
TanStack Router itself is not a "framework" in the traditional sense, since it doesn't address a few other common full-stack concerns. However TanStack Router has been designed to be upgradable to a full-stack framework when used in conjunction with other tools that address bundling, deployments, and server-side-specific functionality. This is why we are currently developing [TanStack Start](https://tanstack.com/start), a full-stack framework that is built on top of TanStack Router and tools like Nitro, and Vite.

For a deeper dive on the history of TanStack Router, feel free to read [TanStack Router's History](./decisions-on-dx.md#tanstack-routers-origin-story).

Expand Down
8 changes: 4 additions & 4 deletions docs/framework/react/start/api-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ You can set the status code of the response by either:
})
```

- Using the `setResponseStatus` helper function from `vinxi/http`
- Using the `setResponseStatus` helper function from `@tanstack/start/server`

```ts
// routes/api/hello.ts
import { json } from '@tanstack/start'
import { createAPIFileRoute } from '@tanstack/start/api'
import { setResponseStatus } from 'vinxi/http'
import { setResponseStatus } from '@tanstack/start/server'

export const APIRoute = createAPIFileRoute('/users/$id')({
GET: async ({ request, params }) => {
Expand Down Expand Up @@ -283,12 +283,12 @@ Sometimes you may need to set headers in the response. You can do this by either
// Hello, World!
```

- Or using the `setHeaders` helper function from `vinxi/http`.
- Or using the `setHeaders` helper function from `@tanstack/start/server`.

```ts
// routes/api/hello.ts
import { createAPIFileRoute } from '@tanstack/start/api'
import { setHeaders } from 'vinxi/http'
import { setHeaders } from '@tanstack/start/server'

export const APIRoute = createAPIFileRoute('/hello')({
GET: async ({ request }) => {
Expand Down
7 changes: 3 additions & 4 deletions docs/framework/react/start/build-from-scratch.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ We highly recommend using TypeScript with TanStack Start. Create a `tsconfig.jso

TanStack Start is (currently\*) powered by [Vinxi](https://vinxi.vercel.app/) and [TanStack Router](https://tanstack.com/router) and requires them as dependencies.

> [!NOTE] > \*Vinxi will be removed before version 1.0.0 is released and TanStack will rely only on Vite and Nitro. The commands and APIs that use Vinxi will likely be replaced with a Vite plugin.
> [!NOTE] > \*Vinxi will be removed before version 1.0.0 is released and TanStack will rely only on Vite and Nitro. The commands and APIs that use Vinxi will likely be replaced with a Vite plugin or dedicated TanStack Start CLI.
To install them, run:

Expand All @@ -67,7 +67,7 @@ npm i -D typescript @types/react @types/react-dom

## Update Configuration Files

We'll then update our `package.json` to reference the new Vinxi entry point and set `"type": "module"`:
We'll then update our `package.json` to use Vinxi's CLI and set `"type": "module"`:

```json
{
Expand All @@ -81,7 +81,7 @@ We'll then update our `package.json` to reference the new Vinxi entry point and
}
```

To tell Vinxi that it should start TanStack Start's minimal behavior, we need to configure the `app.config.ts` file:
Then configure TanStack Start's `app.config.ts` file:

```typescript
// app.config.ts
Expand Down Expand Up @@ -160,7 +160,6 @@ information to our server entry point:

```tsx
// app/ssr.tsx
/// <reference types="vinxi/types/server" />
import {
createStartHandler,
defaultStreamHandler,
Expand Down
2 changes: 0 additions & 2 deletions docs/framework/react/start/learn-the-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ This is done via the `app/ssr.tsx` file:

```tsx
// app/ssr.tsx
/// <reference types="vinxi/types/server" />
import {
createStartHandler,
defaultStreamHandler,
Expand All @@ -79,7 +78,6 @@ Getting our html to the client is only half the battle. Once there, we need to h

```tsx
// app/client.tsx
/// <reference types="vinxi/types/client" />
import { hydrateRoot } from 'react-dom/client'
import { StartClient } from '@tanstack/start'
import { createRouter } from './router'
Expand Down
4 changes: 2 additions & 2 deletions docs/framework/react/start/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ id: overview
title: TanStack Start Overview
---

TanStack Start is a full-stack React framework powered by TanStack Router. It provides a full-document SSR, streaming, server functions, bundling, and more, powered by TanStack Router, Vinxi, and Vite. It is ready to deploy to your favorite hosting provider!
TanStack Start is a full-stack React framework powered by TanStack Router. It provides a full-document SSR, streaming, server functions, bundling, and more using tools like [Nitro](https://nitro.unjs.io/) and [Vite](https://vitejs.dev/). It is ready to deploy to your favorite hosting provider!

## Router or Start?

Expand Down Expand Up @@ -39,7 +39,7 @@ What you get with TanStack Start:

## How does it work?

TanStack Start uses a tool called **Vinxi** to bundle and deploy your application. In fact, this is the same tool that powers Solid Start! With Vinxi, we can do a few things we couldn't do before:
TanStack Start uses [Nitro](https://nitro.unjs.io/) and [Vite](https://vitejs.dev/) to bundle and deploy your application. In fact, these are the same tools that power Solid Start! With these tools, we can do a few things we couldn't do before:

- Provide a unified API for SSR, streaming, and hydration
- Extract server-only code from your client-side code (e.g. server functions)
Expand Down
24 changes: 12 additions & 12 deletions docs/framework/react/start/server-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function Test() {

## Server Function Context

In addition to the single parameter that server functions accept, you can also access server request context from within any server function using utilities from `vinxi/http`. Under the hood, Vinxi uses `unjs`'s `h3` package to perform cross-platform HTTP requests.
In addition to the single parameter that server functions accept, you can also access server request context from within any server function using utilities from `@tanstack/start/server`. Under the hood, we use [Unjs](https://unjs.io/)'s `h3` package to perform cross-platform HTTP requests.

There are many context functions available to you for things like:

Expand All @@ -332,17 +332,17 @@ There are many context functions available to you for things like:
- Dealing with multi-part form data
- Reading/Setting custom server context properties

For a full list of available context functions, see all of the available [h3 Methods](https://h3.unjs.io/utils/request) or inspect the [Vinxi Exports Source Code](https://github.com/nksaraf/vinxi/blob/main/packages/vinxi/runtime/http.js#L232-L320).
For a full list of available context functions, see all of the available [h3 Methods](https://h3.unjs.io/utils/request) or inspect the [@tanstack/start/server Source Code](https://github.com/tanstack/router/tree/main/packages/start/src/server/index.tsx).

For starters, here are a few examples:

## Accessing the Request Context

Let's use Vinxi's `getWebRequest` function to access the request itself from within a server function:
Let's use the `getWebRequest` function to access the request itself from within a server function:

```tsx
import { createServerFn } from '@tanstack/start'
import { getWebRequest } from 'vinxi/http'
import { getWebRequest } from '@tanstack/start/server'

export const getServerTime = createServerFn({ method: 'GET' }).handler(
async () => {
Expand All @@ -357,11 +357,11 @@ export const getServerTime = createServerFn({ method: 'GET' }).handler(

## Accessing Headers

Use Vinxi's `getHeaders` function to access all headers from within a server function:
Use the `getHeaders` function to access all headers from within a server function:

```tsx
import { createServerFn } from '@tanstack/start'
import { getHeaders } from 'vinxi/http'
import { getHeaders } from '@tanstack/start/server'

export const getServerTime = createServerFn({ method: 'GET' }).handler(
async () => {
Expand All @@ -382,7 +382,7 @@ You can also access individual headers using the `getHeader` function:

```tsx
import { createServerFn } from '@tanstack/start'
import { getHeader } from 'vinxi/http'
import { getHeader } from '@tanstack/start/server'

export const getServerTime = createServerFn({ method: 'GET' }).handler(
async () => {
Expand Down Expand Up @@ -427,11 +427,11 @@ By default, server functions assume that any non-Response object returned is eit

## Responding with Custom Headers

To respond with custom headers, you can use Vinxi's `setHeader` function:
To respond with custom headers, you can use the `setHeader` function:

```tsx
import { createServerFn } from '@tanstack/start'
import { setHeader } from 'vinxi/http'
import { setHeader } from '@tanstack/start/server'

export const getServerTime = createServerFn({ method: 'GET' }).handler(
async () => {
Expand All @@ -443,11 +443,11 @@ export const getServerTime = createServerFn({ method: 'GET' }).handler(

## Responding with Custom Status Codes

To respond with a custom status code, you can use Vinxi's `setResponseStatus` function:
To respond with a custom status code, you can use the `setResponseStatus` function:

```tsx
import { createServerFn } from '@tanstack/start'
import { setResponseStatus } from 'vinxi/http'
import { setResponseStatus } from '@tanstack/start/server'

export const getServerTime = createServerFn({ method: 'GET' }).handler(
async () => {
Expand Down Expand Up @@ -599,7 +599,7 @@ export const auth = createServerFn({ method: 'GET' }).handler(async () => {
})
```

> ⚠️ Do not use Vinxi's `sendRedirect` function to send soft redirects from within server functions. This will send the redirect using the `Location` header and will force a full page hard navigation on the client.
> ⚠️ Do not use `@tanstack/start/server`'s `sendRedirect` function to send soft redirects from within server functions. This will send the redirect using the `Location` header and will force a full page hard navigation on the client.
## Redirect Headers

Expand Down
2 changes: 1 addition & 1 deletion e2e/start/basic-auth/app/utils/session.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// app/services/session.server.ts
import { useSession } from 'vinxi/http'
import { useSession } from '@tanstack/start/server'
import type { User } from '@prisma/client'

type SessionUser = {
Expand Down
2 changes: 1 addition & 1 deletion e2e/start/basic/app/routes/status.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createFileRoute } from '@tanstack/react-router'
import { createServerFn, useServerFn } from '@tanstack/start'
import { setResponseStatus } from 'vinxi/http'
import { setResponseStatus } from '@tanstack/start/server'

const helloFn = createServerFn().handler(() => {
setResponseStatus(225, `hello`)
Expand Down
4 changes: 2 additions & 2 deletions e2e/start/clerk-basic/app/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import { TanStackRouterDevtools } from '@tanstack/router-devtools'
import { Meta, Scripts, createServerFn } from '@tanstack/start'
import * as React from 'react'
import { getAuth } from '@clerk/tanstack-start/server'
import { getWebRequest } from 'vinxi/http'
import { getWebRequest } from '@tanstack/start/server'
import { DefaultCatchBoundary } from '~/components/DefaultCatchBoundary.js'
import { NotFound } from '~/components/NotFound.js'
import appCss from '~/styles/app.css?url'

const fetchClerkAuth = createServerFn({ method: 'GET' }).handler(async () => {
const user = await getAuth(getWebRequest())
const user = await getAuth(getWebRequest()!)

return {
user,
Expand Down
2 changes: 1 addition & 1 deletion examples/react/start-basic-auth/app/utils/session.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// app/services/session.server.ts
import { useSession } from 'vinxi/http'
import { useSession } from '@tanstack/start/server'
import type { User } from '@prisma/client'

type SessionUser = {
Expand Down
4 changes: 2 additions & 2 deletions examples/react/start-clerk-basic/app/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import { TanStackRouterDevtools } from '@tanstack/router-devtools'
import { Meta, Scripts, createServerFn } from '@tanstack/start'
import * as React from 'react'
import { getAuth } from '@clerk/tanstack-start/server'
import { getWebRequest } from 'vinxi/http'
import { getWebRequest } from '@tanstack/start/server'
import { DefaultCatchBoundary } from '~/components/DefaultCatchBoundary.js'
import { NotFound } from '~/components/NotFound.js'
import appCss from '~/styles/app.css?url'

const fetchClerkAuth = createServerFn({ method: 'GET' }).handler(async () => {
const { userId } = await getAuth(getWebRequest())
const { userId } = await getAuth(getWebRequest()!)

return {
userId,
Expand Down
2 changes: 1 addition & 1 deletion examples/react/start-supabase-basic/app/utils/supabase.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseCookies, setCookie } from 'vinxi/http'
import { parseCookies, setCookie } from '@tanstack/start/server'
import { createServerClient } from '@supabase/ssr'

export function getSupabaseServerClient() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineEventHandler, toWebRequest } from 'vinxi/http'
import { defineEventHandler, toWebRequest } from '@tanstack/start/server'
import { initTRPC } from '@trpc/server'
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'

Expand Down
2 changes: 1 addition & 1 deletion examples/react/with-trpc/trpc-server.handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineEventHandler, toWebRequest } from 'vinxi/http'
import { defineEventHandler, toWebRequest } from '@tanstack/start/server'
import { initTRPC } from '@trpc/server'
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'

Expand Down
2 changes: 2 additions & 0 deletions packages/start/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@
"@vinxi/server-components": "0.5.0",
"@vinxi/server-functions": "0.5.0",
"@vitejs/plugin-react": "^4.3.4",
"h3": "^1.13.1",
"import-meta-resolve": "^4.1.0",
"isbot": "^5.1.17",
"jsesc": "^3.0.2",
"ofetch": "^1.4.1",
"tiny-invariant": "^1.3.3",
"unctx": "^2.4.1",
"vinxi": "0.5.1",
"zod": "^3.24.1"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/start/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eventHandler, toWebRequest } from 'vinxi/http'
import { eventHandler, toWebRequest } from '@tanstack/start/server'
import vinxiFileRoutes from 'vinxi/routes'
import type { ResolveParams } from '@tanstack/react-router'

Expand Down Expand Up @@ -29,7 +29,7 @@ export type HTTP_API_METHOD = (typeof HTTP_API_METHODS)[number]
*/
export function createStartAPIHandler(cb: StartAPIHandlerCallback) {
return eventHandler(async (event) => {
const request = toWebRequest(event)
const request = toWebRequest(event)!
const res = await cb({ request })
return res
})
Expand Down
7 changes: 3 additions & 4 deletions packages/start/src/server-handler/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="vinxi/types/server" />
import {
defaultTransformer,
isNotFound,
Expand All @@ -11,10 +10,10 @@ import {
getEvent,
getResponseStatus,
toWebRequest,
} from 'vinxi/http'
} from '@tanstack/start/server'
// @ts-expect-error
import _serverFnManifest from 'tsr:server-fn-manifest'
import type { H3Event } from 'vinxi/server'
import type { H3Event } from '@tanstack/start/server'

export default eventHandler(handleServerAction)

Expand All @@ -28,7 +27,7 @@ const serverFnManifest = _serverFnManifest as Record<
>

async function handleServerAction(event: H3Event) {
return handleServerRequest(toWebRequest(event), event)
return handleServerRequest(toWebRequest(event)!, event)
}

function sanitizeBase(base: string | undefined) {
Expand Down
Loading

0 comments on commit 2d182c7

Please sign in to comment.