Repository navigation
Conversation
… the first path segment Fixes #1402
🦋 Changeset detectedLatest commit: b310342 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 DockerWORKDIR /appwith a Remix or React Routerapp/directory, the SSR module id for/app/app/routes/_index.css.tsis the root-relative/app/routes/_index.css.ts.getAbsoluteIdtreated 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 withNo CSS for file: /app/routes/_index.css.ts.From the string alone, an absolute
/app/routes/x.css.tsand a root-relative/app/routes/x.css.tscannot be told apart, so this change uses the file system to break the tie. The rule ingetAbsoluteIdis:root(unchanged). "Looks absolute" means the same as before: the id is insideroot, or it shares the root's first path segment (monorepos).root + iddoes. Only in that case is the root-joined path returned.The check runs on the directory, not the file, because
.vanilla.cssids 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 oneexistsSynccall. 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 ofroot), so with a root of/appan id like/application/styles.css.tsis 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(withfs.existsSyncmocked) cover the reported SSR id, a real absolute path under a/approot, and the/applicationprefix case. The first and third fail without the source change, and all existing cases still pass.pnpm test:unitpasses, 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.