How to ensure module is imported everywhere (server, client, server functions)
I need to ensure that
importExtensions
is executed in all contexts.
So far I only managed to make it work by importing it in client.tsx, ssr.tsx, and router.tsx,
and in router.tsx I also had to make sure to execute it via a global middleware. Is there a simpler approach?
router.tsx:
importExtensions:
6 Replies
sensitive-blue•9mo ago
what does importExtensions() really do?
modify some global objects?
passive-yellowOP•9mo ago
yes, for example zod-extensions:
sensitive-blue•9mo ago
how do other frameworks handle this? are there any existing APIs for this?
passive-yellowOP•9mo ago
Handle which part specifically? I have only implemented this in a Tanstack Start project.
The prototype augmentation is already working correctly in all contexts once I ensure importExtensions is always imported/executed,
but I had to do some trial and error not knowing exactly what are all the possible entry points.
sensitive-blue•9mo ago
I was just wondering e.g. how remix does this
or nextjs
if they have special APIs to register stuff like that
unwilling-turquoise•9mo ago
out of curiosity, why do this instead of exporting utility functions? generally monkey patching like this has fallen out of favour