How to import route-specific types for actions/loaders in .server directory with React Router v7? #10357
Replies: 1 comment
-
.server imports are not removed by remix/vite. Only imports used exclusivelly within action and loader are removed by remix. .server imports will just trigger error when used in client build. As long as your server code is in .server folder or the file ends with .server, when you import it accidentally the wrong way your build will be blocked by error. This is also the case when you have multiple imports If you import and use I see very litle sense in having the entire Route (& LoaderArgs, ActionArgs) be in a separate file. Note of potential interest: If you do want to use just types from Because the first one would be entirelly removed, the later would leave behind |
Beta Was this translation helpful? Give feedback.
-
I'm trying to use the new type safety features in React Router v7 while keeping my server-side logic secure. I've placed my actions and loaders in a
.server
directory to prevent server-side code from being bundled with client-side code (similar to Remix's conventions for server-side code isolation).My project structure looks like this:
I understand that React Router generates types in .react-router/types/ directory, but I'm not sure how to properly import and use these types in my server-side code.
For example, in
app/.server/loaders/products.ts
:Could someone explain:
Thanks in advance for any help or guidance!
Beta Was this translation helpful? Give feedback.
All reactions