Skip to content

Commit

Permalink
fix(remix-dev/vite): use /@fs/ path to support default server/clien…
Browse files Browse the repository at this point in the history
…t entry outside of app root (#7913)

Co-authored-by: Pedro Cattori <pcattori@gmail.com>
  • Loading branch information
hi-ogawa and pcattori committed Nov 7, 2023
1 parent 22869fe commit 2c36e11
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .changeset/nasty-waves-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@remix-run/dev": patch
---

fix(vite): Let Vite handle serving files outside of project root via `/@fs`

This fixes errors when using default client entry or server entry in a pnpm project
where those files may be outside of the project root, but within the workspace root.

By default, Vite prevents access to files outside the workspace root
(when using workspaces) or outside of the project root (when not using
workspaces) unless user explicitly opts into it via Vite's `server.fs.allow`.
11 changes: 6 additions & 5 deletions packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ const resolveFileUrl = (
filePath: string
) => {
let relativePath = path.relative(rootDirectory, filePath);
let isWithinRoot =
!relativePath.startsWith("..") && !path.isAbsolute(relativePath);

if (relativePath.startsWith("..") || path.isAbsolute(relativePath)) {
throw new Error(
`Cannot resolve asset path "${filePath}" outside of root directory "${rootDirectory}".`
);
}
// Vite will prevent serving files outside of the workspace
// unless user explictly opts in with `server.fs.allow`
// https://vitejs.dev/config/server-options.html#server-fs-allow
if (!isWithinRoot) return `/@fs` + filePath;

return `/${normalizePath(relativePath)}`;
};
Expand Down

0 comments on commit 2c36e11

Please sign in to comment.