Skip to content
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

feat: Agnostic Server Fn Plugin #2993

Merged
merged 68 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
1663de6
checkpoint
tannerlinsley Dec 11, 2024
83e7a78
checkpoint
tannerlinsley Dec 12, 2024
9ac11e8
cleanup
tannerlinsley Dec 12, 2024
3582323
checkpoint
tannerlinsley Dec 12, 2024
fa7c035
client babel now works, runtime and rpc injection
tannerlinsley Dec 12, 2024
e0d8a31
fix: dont touch anything outside of the function
tannerlinsley Dec 12, 2024
44dac10
server functions now import a tsr-serverfn-split file version
tannerlinsley Dec 12, 2024
b1335a3
checkpoint
tannerlinsley Dec 18, 2024
9e2d9cc
checkpoint
tannerlinsley Dec 20, 2024
ce2ab10
fis tests
tannerlinsley Dec 20, 2024
bc98574
It's working!!!
tannerlinsley Dec 21, 2024
97af6f7
move serverFnFetcher to start client
tannerlinsley Dec 23, 2024
08c32e9
fix: no extra context, throw errors from middleware
tannerlinsley Dec 23, 2024
c73937e
docs: add custom link example for mantine (#3033)
youssefbenlemlih Dec 18, 2024
a3f6821
ci: apply automated fixes
autofix-ci[bot] Dec 18, 2024
707c188
fix(react-router): make sure full matches are passed into route funct…
schiller-manuel Dec 19, 2024
c48ab4f
release: v1.91.3
tannerlinsley Dec 19, 2024
915fbc0
docs: minor typo in code-based-routing.md (#3043)
AlexisPin Dec 19, 2024
1687da1
feat(start): create-start cli (#2920)
timoconnellaus Dec 19, 2024
f2dbdff
docs: Minor typo in middleware.md (#3042)
nanocom Dec 20, 2024
efed787
release: v1.92.0
tannerlinsley Dec 20, 2024
0310d21
refactor(react-router): expose `scrollBehavior` on the `ScrollRestora…
joshuaKnauber Dec 21, 2024
f8b04e6
release: v1.92.1
tannerlinsley Dec 21, 2024
11f2b96
fix(start): returning `null` from server functions (#3048)
alakhpc Dec 22, 2024
3a538f7
release: v1.92.2
tannerlinsley Dec 22, 2024
ce467d1
fix: allow serverFn errors to also have context (#3037)
tannerlinsley Dec 23, 2024
d4574ef
release: v1.92.3
tannerlinsley Dec 23, 2024
dd3ab7b
move directive plugin to own package
tannerlinsley Dec 24, 2024
cdd1028
Merge branch 'main' into feat-server-fn-plugin
tannerlinsley Jan 6, 2025
45b39c7
fixes, tests
tannerlinsley Jan 6, 2025
d82e9df
suggested fixes from sean
tannerlinsley Jan 7, 2025
7733c0c
fix tests
tannerlinsley Jan 7, 2025
d37a786
fix: import specifier
tannerlinsley Jan 7, 2025
497a83f
fix: dev imports
tannerlinsley Jan 7, 2025
83a1bc8
fix: simpler config, better logging, more reliable plugin coordination
tannerlinsley Jan 7, 2025
71037fb
fix: update test snapshots
tannerlinsley Jan 7, 2025
bbaf8fd
fix: non-split directives, clean up compilers, logging, and
tannerlinsley Jan 8, 2025
6eab24e
fix: production server fn builds
tannerlinsley Jan 8, 2025
dfb5248
feat(start): explicitly enable and disable route generation
SeanCassiere Jan 11, 2025
0325c62
fix: $fetch during dev
tannerlinsley Jan 14, 2025
d0f653f
ci: apply automated fixes
autofix-ci[bot] Jan 14, 2025
f36d71c
Update comparison.md
tannerlinsley Jan 8, 2025
318e8c1
docs: remove duplicate word (#3125)
markvu2607 Jan 8, 2025
fd6c53f
chore: add skipLibCheck to examples (#3134)
chorobin Jan 9, 2025
4ce56c1
docs: Typo issue - getParent Does not Exists in type RouteOptions (#3…
muthu32 Jan 9, 2025
a289855
docs: Fix notFound import (#3133)
jeffhertzler Jan 9, 2025
df3ce48
docs: fix dead link and typo in guide (#3136)
serhalp Jan 9, 2025
49a0cf7
fix(react-router): separate internal and user provided history state …
ferretwithaberet Jan 10, 2025
fc8cd8e
release: v1.95.2
tannerlinsley Jan 10, 2025
5f6bf40
fix(router-generator) use explicit routes export by default (#3109)
esjs Jan 10, 2025
12ce5bb
fix(start): serialize `FormData` for server function input (#3138)
SeanCassiere Jan 10, 2025
2dbe636
release: v1.95.3
tannerlinsley Jan 10, 2025
838b768
test(react-router): check `FormData` serialization in transformer (#3…
SeanCassiere Jan 10, 2025
2bcd51e
docs(router): missing character in code-splitting guide (#3143)
pierluigigiancola Jan 12, 2025
6327a19
fix(create-start): readme changes and little fixes (#3142)
thomasballinger Jan 12, 2025
5201e2a
release: v1.95.4
tannerlinsley Jan 12, 2025
55adec3
fix(start): preserve multiple values for same key in `FormData` seria…
EskiMojo14 Jan 12, 2025
e78a82a
release: v1.95.5
tannerlinsley Jan 13, 2025
bec805c
docs(migrate): correct typo in migration documentation (#3153)
markvu2607 Jan 13, 2025
dac04e9
docs(start): fix `FormData` server functions examples (#3062)
kasulio Jan 13, 2025
cbe1f34
docs(router): require the use of React's `createRoot` function (#3151)
jorroll Jan 13, 2025
d942fad
fix: order of injected scripts (#3158)
schiller-manuel Jan 14, 2025
df701bd
release: v1.95.6
tannerlinsley Jan 14, 2025
087adf2
perf(start): reduce instantiations of server fn and middleware (again…
chorobin Jan 14, 2025
57ca66b
release: v1.95.7
tannerlinsley Jan 14, 2025
df7b4f9
Merge branch 'main' into feat-server-fn-plugin
tannerlinsley Jan 14, 2025
ba22a93
fix imports
tannerlinsley Jan 14, 2025
a5aeb79
fix: build test
tannerlinsley Jan 14, 2025
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
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ pnpm-lock.yaml
node_modules

**/test-results
**/tests/generator/file-modification/routes/(test)/*
**/tests/generator/file-modification/routes/(test)/*
/.nx/workspace-data
4 changes: 2 additions & 2 deletions examples/react/start-basic/app/routes/deferred.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { createServerFn } from '@tanstack/start'
import { Suspense, useState } from 'react'

const personServerFn = createServerFn({ method: 'GET' })
.validator((d) => d as string)
.validator((d: string) => d)
.handler(({ data: name }) => {
return { name, randomNumber: Math.floor(Math.random() * 100) }
})

const slowServerFn = createServerFn({ method: 'GET' })
.validator((d) => d as string)
.validator((d: string) => d)
.handler(async ({ data: name }) => {
await new Promise((r) => setTimeout(r, 1000))
return { name, randomNumber: Math.floor(Math.random() * 100) }
Expand Down
2 changes: 1 addition & 1 deletion examples/react/start-basic/app/utils/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type PostType = {

export const fetchPost = createServerFn({ method: 'GET' })
.middleware([logMiddleware])
.validator((d) => d as string)
.validator((d: string) => d)
.handler(async ({ data }) => {
console.info(`Fetching post with id ${data}...`)
const post = await axios
Expand Down
2 changes: 1 addition & 1 deletion examples/react/start-supabase-basic/app/utils/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type PostType = {
}

export const fetchPost = createServerFn({ method: 'GET' })
.validator((d) => d as string)
.validator((d: string) => d)
.handler(async ({ data: postId }) => {
console.info(`Fetching post with id ${postId}...`)
const post = await axios
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@
"@tanstack/arktype-adapter": "workspace:*",
"@tanstack/start": "workspace:*",
"@tanstack/start-vite-plugin": "workspace:*",
"@tanstack/eslint-plugin-router": "workspace:*",
"temp-react": "0.0.0-experimental-035a41c4e-20230704",
"temp-react-dom": "0.0.0-experimental-035a41c4e-20230704"
"@tanstack/eslint-plugin-router": "workspace:*"
}
}
}
2 changes: 2 additions & 0 deletions packages/router-plugin/src/core/code-splitter/compilers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export function compileCodeSplitReferenceRoute(opts: ParseAstOptions) {
return generate(ast, {
sourceMaps: true,
sourceFileName: opts.filename,
minified: process.env.NODE_ENV === 'production',
})
}

Expand Down Expand Up @@ -543,6 +544,7 @@ export function compileCodeSplitVirtualRoute(opts: ParseAstOptions) {
return generate(ast, {
sourceMaps: true,
sourceFileName: opts.filename,
minified: process.env.NODE_ENV === 'production',
})
}

Expand Down
5 changes: 5 additions & 0 deletions packages/server-functions-vite-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<img src="https://static.scarf.sh/a.png?x-pxid=d988eb79-b0fc-4a2b-8514-6a1ab932d188" />

# TanStack Start Vite Plugin
tannerlinsley marked this conversation as resolved.
Show resolved Hide resolved

See https://tanstack.com/router/latest/docs/framework/react/guide/file-based-routing
5 changes: 5 additions & 0 deletions packages/server-functions-vite-plugin/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @ts-check

import rootConfig from '../../eslint.config.js'

export default [...rootConfig]
89 changes: 89 additions & 0 deletions packages/server-functions-vite-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"name": "@tanstack/directive-functions-plugin",
"version": "1.87.3",
"description": "Modern and scalable routing for React applications",
"author": "Tanner Linsley",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/TanStack/router.git",
"directory": "packages/directive-functions-plugin"
},
"homepage": "https://tanstack.com/start",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/tannerlinsley"
},
"keywords": [
"react",
"location",
"router",
"routing",
"async",
"async router",
"typescript"
],
"scripts": {
"clean": "rimraf ./dist && rimraf ./coverage",
"test": "pnpm test:eslint && pnpm test:types && pnpm test:build && pnpm test:unit",
"test:unit": "vitest",
"test:unit:dev": "vitest --watch",
"test:eslint": "eslint ./src",
"test:types": "pnpm run \"/^test:types:ts[0-9]{2}$/\"",
"test:types:ts52": "node ../../node_modules/typescript52/lib/tsc.js",
"test:types:ts53": "node ../../node_modules/typescript53/lib/tsc.js",
"test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js",
"test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js",
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js",
"test:types:ts57": "tsc",
"test:build": "publint --strict && attw --ignore-rules no-resolution --pack .",
"build": "vite build"
},
"type": "module",
"types": "dist/esm/index.d.ts",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.js",
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
}
},
"./package.json": "./package.json"
},
"sideEffects": false,
"files": [
"dist",
"src"
],
"engines": {
"node": ">=12"
},
"dependencies": {
"@babel/code-frame": "7.26.2",
"@babel/core": "^7.26.0",
"@babel/generator": "^7.26.3",
"@babel/parser": "^7.26.3",
"@babel/plugin-syntax-jsx": "^7.25.9",
"@babel/plugin-syntax-typescript": "^7.25.9",
"@babel/template": "^7.25.9",
"@babel/traverse": "^7.26.4",
"@babel/types": "^7.26.3",
"@types/babel__code-frame": "^7.0.6",
"@types/babel__core": "^7.20.5",
"@types/babel__generator": "^7.6.8",
"@types/babel__template": "^7.4.4",
"@types/babel__traverse": "^7.20.6",
"@types/diff": "^6.0.0",
"babel-dead-code-elimination": "^1.0.6",
"chalk": "^5.3.0",
"dedent": "^1.5.3",
"diff": "^7.0.0",
"tiny-invariant": "^1.3.3"
}
}
20 changes: 20 additions & 0 deletions packages/server-functions-vite-plugin/src/ast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { parse } from '@babel/parser'
import type { ParseResult } from '@babel/parser'

export type ParseAstOptions = {
tannerlinsley marked this conversation as resolved.
Show resolved Hide resolved
code: string
filename: string
root: string
}

export function parseAst(opts: ParseAstOptions): ParseResult<babel.types.File> {
return parse(opts.code, {
plugins: ['jsx', 'typescript'],
sourceType: 'module',
...{
root: opts.root,
filename: opts.filename,
sourceMaps: true,
},
})
}
Loading
Loading