Open shivghai opened 3 months ago
Hi @shivghai turns out that @orta has similar experiences with his larger app as well ... and has invested some time in implementing hot module reloading (HMR) on the api/graphql side (still a WIP). He can provide more context, but perhaps we can offer a better experience soon.
@dthyresson Is there a thread I can follow? What do you recommend as next steps?
I'm happy to help with the implementation too, this is painful enough
No issue/thread to follow (https://github.com/redwoodjs/redwood/issues/9738 relates because it's been my problem), I've mainly been prototyping outside of Redwood but the current runtime mechanics can be switched to remove the build step by moving to vite via: vite-node
Looking roughly like:
vite-node --watch src/server.ts
const schemas = import.meta.glob("./graphql/**/*.sdl.ts", { eager: true })
const services = import.meta.glob("./services/**/*.ts", { eager: true })
const fastify = Fastify({ logger: true })
const { yoga, logger } = createGraphQLYoga({
allowGraphiQL: true,
loggerConfig: {
logger: createLogger({}),
},
services: services as any,
sdls: schemas as any,
})
// [...]
function killServer() {
if (!_fastify) return
_fastify.close(() => {
console.error("Reset graphql")
})
}
// @ts-ignore
if (import.meta.hot) {
// @ts-ignore
const hot = import.meta.hot
hot.on("vite:beforeFullReload", () => {
console.log("HMR: full reload")
killServer()
})
hot.dispose(() => {
console.log("HMR: dispose")
killServer()
})
}
At a guess, to pull this off in Redwood would require:
Thanks @orta !
@Josh-Walker-GM and @Tobbe - any thoughts on how we might get api/gql side hmr in dev server?
I have a more fleshed out working version of HMR in https://github.com/orta/redwood-vite-api
What's not working?
Happening to everyone on my team.
I don't know if this also happens with the web side [Edit - it does not], but if you save an API-side file consecutively (>10x times), the build loop for the dev server breaks and after this state, any changes to the api side aren't reflected in the running code.
This makes for a VERY VERY VERY painful dev experience.
The first error I see on server logs is this:
After that, any changes on the api side aren't reflected and we have to kill the server to have those changes be reflected. The server still runs with the old code.
This is very very consistent. I think this may happen with large Redwood apps (see https://github.com/redwoodjs/redwood/issues/9237 for another example of an issue that my team saw first, presumably because we actually have a large production app).
How do we reproduce the bug?
Save a file (I can 100% repro with API side changes) multiple times consecutively
What's your environment? (If it applies)
yarn rw info
:Are you interested in working on this?