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

bug: tRPC breaks when using revalidatePath/revalidateTag in server action #1640

Closed
Allypost opened this issue Nov 1, 2023 · 1 comment · Fixed by #1644
Closed

bug: tRPC breaks when using revalidatePath/revalidateTag in server action #1640

Allypost opened this issue Nov 1, 2023 · 1 comment · Fixed by #1644

Comments

@Allypost
Copy link
Contributor

Allypost commented Nov 1, 2023

Provide environment information

  System:
    OS: Linux 6.5 Arch Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
    Memory: 11.91 GB / 31.29 GB
    Container: Yes
    Shell: 3.6.1 - /bin/fish
  Binaries:
    Node: 21.1.0 - ~/.local/share/rtx/installs/node/21.1.0/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 10.2.0 - ~/.local/share/rtx/installs/node/21.1.0/bin/npm
    pnpm: 8.6.7 - ~/.local/share/pnpm/pnpm
    bun: 1.0.7 - ~/.local/share/rtx/installs/bun/1.0.7/bin/bun
  C3A:
    Init version: 7.22.0

Describe the bug

The issue occurs when using both server actions and tRPC inside the same component.

If a revalidatePath is used inside the server action, the component breaks after submitting the form with the error

Unhandled Runtime Error
Error: fetch failed

Call Stack
TRPCClientError.from
node_modules/@trpc/client/dist/TRPCClientError-0de4d231.mjs (37:15)
from
node_modules/@trpc/client/dist/httpBatchLink-204206a5.mjs (200:55)

This is because the tRPC proxy as is implemented in the current way forwards all headers. The issue is that next generates additional content and thus breaks the content-length header.

The (temporary) fix is to omit the content-length header in the requests.
Adding heads.delete("content-length") in the tRPC providers should solve that.

Reproduction repo

https://github.com/Allypost/create-t3-app-trpc-breaks-server-actions

To reproduce

Run the provided repo and simply click the "Broken" button.

Alternatively, add a server action with a revalidatePath to a page that has a server-component tRPC request

Additional information

Error screenshot
image

Allypost added a commit to Allypost/create-t3-app that referenced this issue Nov 1, 2023
Prevent tRPC from breaking when a `revalidateTag` or `revalidatePage`
is used inside a server action that targets the page.
Allypost added a commit to Allypost/create-t3-app that referenced this issue Nov 1, 2023
Prevent tRPC from breaking when a `revalidateTag` or `revalidatePage`
is used inside a server action that targets the page.

Refs: t3-oss#1640
@juliusmarminge
Copy link
Member

juliusmarminge commented Nov 1, 2023

we should just forward the cookies i think. there are more headers that seem to break stuff and it's only really the cookie we want to be able to auth users. any extra headers can be added by individual needs (#1644)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants