You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/explanation/special-files.md
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -281,6 +281,45 @@ For an example, please refer to the default [`entry.server.tsx`][node-streaming-
281
281
282
282
Note that this does not handle thrown `Response` instances from your `loader`/`action` functions. The intention of this handler is to find bugs in your code which result in unexpected thrown errors. If you are detecting a scenario and throwing a 401/404/etc. `Response` in your `loader`/`action` then it's an expected flow that is handled by your code. If you also wish to log, or send those to an external service, that should be done at the time you throw the response.
283
283
284
+
## `.server` modules
285
+
286
+
While not strictly necessary, `.server` modules are a good way to explicitly mark entire modules as server-only.
287
+
The build will fail if any code in a `.server` file or `.server` directory accidentally ends up in the client module graph.
288
+
289
+
```txt
290
+
app
291
+
├── .server 👈 marks all files in this directory as server-only
292
+
│ ├── auth.ts
293
+
│ └── db.ts
294
+
├── cms.server.ts 👈 marks this file as server-only
295
+
├── root.tsx
296
+
└── routes.ts
297
+
```
298
+
299
+
`.server` modules must be within your app directory.
300
+
301
+
Refer to the Route Module section in the sidebar for more information.
302
+
303
+
# `.client` modules
304
+
305
+
While uncommon, you may have a file or dependency that uses module side effects in the browser. You can use `*.client.ts` on file names or nest files within `.client` directories to force them out of server bundles.
306
+
307
+
```ts filename=feature-check.client.ts
308
+
// this would break the server
309
+
exportconst supportsVibrationAPI =
310
+
"vibrate"inwindow.navigator;
311
+
```
312
+
313
+
Note that values exported from this module will all be `undefined` on the server, so the only places to use them are in [`useEffect`][use_effect] and user events like click handlers.
0 commit comments