Setting up relay (graphql) and react-router v7 framework mode #13085
johnsonjo4531
started this conversation in
Show and tell / tips
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey all I just wanted to share that thanks to some continued discussion on the graphql discord in relay's channel I got relay (a.k.a. react-relay which is a GraphQL client) and react-router-v7 framework mode working together 🥳 🎉🎉. My idea for getting them to work together is so hopefully I can get preloading of queries done by the router so I can fetch data before I render using the render-as-you-fetch pattern. Here is an example repo of relay and react-router v7 working. I will hopefully update my example repo with the render as your fetch pattern once I get it working. The following was my final vite config that ended up working the graphql rollup plugin and tailwindcss and tsconfigPaths should hopefully be optional leaving only the reactRouter and relay plugins there should be enough for most projects. Also the optimizeDeps and noExternal options are both very important to get it working:
vite.config.ts
Also even with that config I was getting the following errors when my react-router app's
root.tsx
wasn't correctly setup:This one on the frontend:
This one in the terminal's vite output:
Once that had happened I needed to be sure to move my RelayEnviromentProvider from the root.tsx from the Layout component to the App component. Like so:
app/root.tsx
I was getting so many different errors which I'll post for searchability of the issue. Most of them were fixed by the vite.config.ts. The one about useMemo was fixed by making sure the layout didn't have any hooks in it:
Beta Was this translation helpful? Give feedback.
All reactions