tRPC, SSR, Cloudflare #1065
peterhirn
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been experimenting with tRPC on Cloudflare recently.
I started by implementing tRPC as described in the official documentation and quickly realized that SSR + tRPC doesn't work on Cloudflare at all. The problem is that tRPC by default creates an actual http request to
localhost
when running in SSR (seems inefficient). On Cloudflare (and probably other similar runtimes) there is nolocalhost
, therefore SSR fails.After some research I discovered an ongoing discussion in the tRPC repo about this topic: trpc/trpc#3768
I copied the suggested fix from this issue and adapted it to SolidStart.
/src/lib/trpc/client.ts
/src/lib/trpc/fetchSsr.ts
/src/lib/trpc/Provider.tsx
Caveats
import("~/lib/trpc/fetchSsr.js")
to get rid of warnings in dev about importing@trpc/server
on the client. Maybe there is a better/cleaner way to do this.Questions
with-trpc
example or official documentation?Cheers 🥤
Beta Was this translation helpful? Give feedback.
All reactions