Remix and preloadQuery or alternatives
I'm trying to experiment with ways to avoid data loading flicker in Remix app. Is there a recommended approach to server side rendering / preloading? I tried putting
preloadQuery
from convex/nextjs
in my remix component loader
but get a bunch of errors. Any recommendations?
My test code is:
6 Replies
we're focusing on next.js and then tanstack start. we want to double back to remix, but we just haven't had the bandwidth yet. anything you find out we'd love to hear about just to speed things up when we get to our remix focus
Thanks, totally understood. I was half using this to test remix. Is preloadQuery some complex thing or is it just a particular data structure for serialized data and subscription?
@Tristan this should just work in Remix if you pass a Convex url option: https://docs.convex.dev/api/modules/nextjs#nextjsoptions
Module: nextjs | Convex Developer Hub
Helpers for integrating Convex into Next.js applications using server rendering.
The only thing technically Next.js-specific about this is the environment variable name
preloadQuery is just what it looks like, a result and a serialized query specifier
We've had people use Remix with this but haven't taken on documenting support for it yet. Should be fine though, preload your queries as described in https://docs.convex.dev/client/react/nextjs/server-rendering
Next.js Server Rendering | Convex Developer Hub
Next.js automatically renders both Client and Server Components on the server
This works great, thanks. The simple fix is just to set the NEXT_PUBLIC_CONVEX_URL=$CONVEX_URL so you don't always have to manually pass it. The things that would make this smoother for Remix would be to move
preloadQuery
out of convex/nextjs
or have a remix equivalent, and default to CONVEX_URL or both if you're keeping packages together. There is still a type error that happens when using usePreloadedQuery
from the objected returned from useLoaderData
but I believe this is a remix issue.
Here's a working example in case it's helpful (NEXT_PUBLIC_CONVEX_URL is set in .env.local) to others in the future: