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

Chained Server Fn Syntax, ServerFn Middleware #2513

Merged
merged 51 commits into from
Nov 14, 2024
Merged

Conversation

tannerlinsley
Copy link
Collaborator

@tannerlinsley tannerlinsley commented Oct 11, 2024

No description provided.

@tannerlinsley tannerlinsley changed the title Server Functions 0.0.2, Middleware Chained Server Fn Syntax, ServerFn Middleware Oct 11, 2024
@ssijak
Copy link

ssijak commented Oct 15, 2024

Let's goooo 🚀

packages/start/src/client/createServerMiddleware.ts Outdated Show resolved Hide resolved
packages/start/src/client/createMiddleware.ts Outdated Show resolved Hide resolved
path: babel.NodePath<t.CallExpression>,
opts: ParseAstOptions,
) {
// const firstArg = path.node.arguments[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanup

packages/start/src/config/index.ts Outdated Show resolved Hide resolved
{
name: 'custom-hot-update-client',
handleHotUpdate(ctx) {
console.log('server hot', ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

packages/react-router/src/router.ts Show resolved Hide resolved
loader: ({ params: { _splat } }) => getDocument(_splat!),
loader: ({ params: { _splat } }) =>
getDocument({
data: _splat!,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why the _splat param needs to be asserted here as NOT undefined?

Unless, is the splat route also expected to be matched when a not is in the "notFound" status? This wouldn't make sense to me, since if we hit a "notFound" the router should grab the nearest notFoundComponent by default (or the root route's notFoundComponent based on the router's setting).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could probably ensure it's at least a string, even if it's empty

schiller-manuel and others added 8 commits November 14, 2024 00:15
# Conflicts:
#	docs/framework/react/start/getting-started.md
#	examples/react/search-validator-adapters/package.json
#	packages/arktype-adapter/package.json
#	packages/react-router/src/fileRoute.ts
#	packages/react-router/src/route.ts
#	packages/start-vite-plugin/package.json
#	packages/start/src/config/index.ts
#	packages/valibot-adapter/package.json
#	packages/zod-adapter/package.json
#	pnpm-lock.yaml
except the search-validator-adapters example, everything else builds fine
@tannerlinsley tannerlinsley merged commit 4d5d25b into main Nov 14, 2024
3 of 4 checks passed
@tannerlinsley tannerlinsley deleted the server-fn-middleware branch November 14, 2024 16:43
@ttsirkia
Copy link

This PR included a new Middleware Guide page for Start. It is visible as a link in Server Functions page but not in the main contents menu. Should it also be visible there?

@tannerlinsley
Copy link
Collaborator Author

Fixed.

@ttsirkia
Copy link

Great, thanks!

@thebuilder
Copy link

This PR silently changes the package name of adapters between two patch versions (1.18.5 and 1.18.6).

-import { zodSearchValidator } from '@tanstack/router-zod-adapter';
+import { zodValidator } from '@tanstack/zod-adapter';

After bumping dependencies, the types for searchParams becomes any, until the adapter package is changed to the new one.

Why isn't something like this marked as a breaking change, but just thrown into a huge PR with no description?
Everyone using the adapters will run this issue once they start bumping dependencies, and have to do the same detective work to find out why it breaks.

The damage is done, but could you at least:

  • Mark the old packages as deprecated, to give a hint to the developer that they should replace them
  • Update the release note with a mention of the packages having changed name

@schiller-manuel
Copy link
Contributor

@thebuilder
sorry! this was absolutely not intended. in fact, we planned that the old packages could be continued to be used. But then we overlooked that the packages depended on a type exported from router :(
I updated the release notes and we will deprecate the old packages asap.

timoconnellaus pushed a commit to timoconnellaus/tanstack-router that referenced this pull request Dec 4, 2024
* init

* Refactor createServerFn, add createServerMiddleware

* checkpoint

* checkpoint

* checkpoint

* update docs and examples to use new server function syntax

* fix: compilers, and update examples

* refactor: added merging of context and some type tests

* feat: createServerMiddleware context and input validation types

* checkpoint

* Server function middleware

* checkpoint

* checkpoint

* fix: return types from handlers, merging inputs etc

* checkpoint

* checkpoint

* checkpoint

* checkpoint

* feat: add types for client context and server context

* fix: merge server context

* checkpoint

* docs

* fix: better compilation of server functions

* fix: deferred example

* Html, Head, Body... be GONE!

* fix: API Routes

* checkpoint

* fix: support optional input types

* checkpoint

* fix lossy merge

* ci: fix build

* ci: fix start examples

* checkpoint

* feat: add client after context types

* test: add type tests

* checkpoint

* checkpoint

* Remove now-unnecessary data type headers

* checkpoint

* fix e2e test

* fix up merge conflicts

* ci: apply automated fixes

* fix: a few tests and a runtime bug

* chore: pnpm dedupe
except the search-validator-adapters example, everything else builds fine

* fix merge conflict

---------

Co-authored-by: chorobin <chrishorobin@hotmail.com>
Co-authored-by: Manuel Schiller <manuel.schiller@caligano.de>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: SeanCassiere <33615041+SeanCassiere@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants