Skip to content

fix(vite-plugin): resolve root-relative SSR ids when the root matches the first path segment - #1796

Closed
HawkForge wants to merge 1 commit into
vanilla-extract-css:masterfrom
HawkForge:fix-ssr-root-relative-ids
Closed

HawkForge wants to merge 1 commit into
vanilla-extract-css:masterfrom
HawkForge:fix-ssr-root-relative-ids

Conversation

@HawkForge

Copy link
Copy Markdown

Fixes #1402. Thanks @zgeoff for the report and the reproduction repo, and @mattkindy for confirming it still happens with React Router 7.

When the Vite root is /app, for example a Docker WORKDIR /app with a Remix or React Router app/ directory, the SSR module id for /app/app/routes/_index.css.ts is the root-relative /app/routes/_index.css.ts. getAbsoluteId treated that id as already absolute for two reasons: resolvedId.startsWith(root) matched, and the monorepo "same filesystem root" check also matched because both paths start with /app. The plugin then looked up CSS for the wrong file and failed with No CSS for file: /app/routes/_index.css.ts.

From the string alone, an absolute /app/routes/x.css.ts and a root-relative /app/routes/x.css.ts cannot be told apart, so this change uses the file system to break the tie. The rule in getAbsoluteId is:

  1. A Windows drive path is returned as is (unchanged).
  2. An id that does not look absolute is joined to root (unchanged). "Looks absolute" means the same as before: the id is inside root, or it shares the root's first path segment (monorepos).
  3. An id that looks absolute is kept as is, unless its directory does not exist and the directory of root + id does. Only in that case is the root-joined path returned.

The check runs on the directory, not the file, because .vanilla.css ids are virtual and never exist on disk. For ids that really are absolute, their directory exists, so the result is unchanged and the cost is one existsSync call. The outcome changes only when the absolute reading points at a directory that is not there but the root-relative reading does, which is the situation in this issue.

The "inside root" check also gains a separator (${root}/ instead of root), so with a root of /app an id like /application/styles.css.ts is no longer treated as inside the root. It is now handled like any other id whose first segment differs from the root's, and is joined to the root.

New tests in packages/vite-plugin/src/ids.test.ts (with fs.existsSync mocked) cover the reported SSR id, a real absolute path under a /app root, and the /application prefix case. The first and third fail without the source change, and all existing cases still pass. pnpm test:unit passes, and prettier and oxlint are clean on the changed files. A changeset is included.

I could only reproduce the id shape from the issue log in unit tests; I did not run the Docker reproduction end to end.

@changeset-bot

changeset-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b310342

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@vanilla-extract/vite-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vite plugin fails to resolve files when full path starts with /app (remix, docker)

1 participant