Skip to content

fix(docs): Complete server function mutation example and fix broken links. #3992

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
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

mpiroc
Copy link

@mpiroc mpiroc commented Apr 14, 2025

Fixes the following in the "learn the basics" doc for Tanstack Start:

  1. The example snippet for server function mutations is incomplete and does not do what the description says it does.
  2. The link to the full mutation docs was a broken, non-relative link.
  3. Another link in this doc was also broken and non-relative.

I'm just getting started with Tanstack Start, so my example might not contain best practices--I would like feedback before merging!

Context (from discord):

Hi, I'm looking at https://tanstack.com/start/latest/docs/framework/react/learn-the-basics, and the example in the "Mutations" section seems to be missing a lot:

  • Missing import: z
  • Missing definition/import: db
  • Missing definition/import: users

It also doesn't seem to do what the description says:

Here's a quick example of how you can use server functions to perform a mutation on the server and invalidate the data on the client:
Unless I'm missing something, the example doesn't do any type of invalidation.

For context, here is the example:

import { createServerFn } from '@tanstack/react-start'

const UserSchema = z.object({
  id: z.string(),
  name: z.string(),
})

const updateUser = createServerFn({ method: 'POST' })
  .validator(UserSchema)
  .handler(async ({ data }) => {
    return db
      .update(users)
      .set({ name: data.name })
      .where(eq(users.id, data.id))
  })

// Somewhere else in your application
await updateUser({ data: { id: '1', name: 'John' } })

@github-actions github-actions bot added the documentation Everything documentation related label Apr 14, 2025
Copy link

nx-cloud bot commented Apr 14, 2025

View your CI Pipeline Execution ↗ for commit 8a9ad9a.

Command Status Duration Result
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 4s View ↗
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-04-16 21:41:38 UTC

```

To learn more about mutations, check out the [mutations guide](/router/latest/docs/framework/react/guide/data-mutations).
To learn more about mutations, check out the [mutations guide](/router/framework/react/guide/data-mutations).
Copy link
Member

Choose a reason for hiding this comment

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

I think there may have been some miscommunication here. By absolute, I meant what'd be used by the website.
Keep the link as it was, since the /$version/docs/ is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Everything documentation related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants