You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 no localhost, 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.
I had to use a inline import 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.
Copying the request headers has the potential for introducing serious security issues (eg. SSR of content which shouldn't be available for given user/request)
Questions
Any ideas on how to improve/simplify this code?
Would you like to see this (or a improved version) integrated in the with-trpc example or official documentation?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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