fix: normalize file path before creating route ID in configRoutesToRouteManifest#14952
fix: normalize file path before creating route ID in configRoutesToRouteManifest#14952restareaByWeezy wants to merge 2 commits intoremix-run:devfrom
Conversation
…uteManifest When routes are defined using the relative() helper, route.file is an absolute path (via Path.resolve). The file property was already normalized to a relative path, but createRouteId used the raw route.file, producing absolute route IDs like "/home/user/app/routes/home" instead of "routes/home". Extract the normalization into a shared variable so both the ID and file property use the relative path. Fixes remix-run#14125
|
Hi @restareaByWeezy, Welcome, and thank you for contributing to React Router! Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once. You may review the CLA and sign it by adding your name to contributors.yml. Once the CLA is signed, the If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run. Thanks! - The Remix team |
|
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
|
👋 We've moved away from Changesets to our own internal changes process. Please convert your changesets file to a change file in the proper package directory (i.e., |
Problem
Fixes #14125
When routes are defined using the
relative()helper inroutes.ts, route IDs become absolute file paths (e.g.,/home/projects/app/routes/home) instead of the expected relative paths (e.g.,routes/home).This happens because
relative()callsPath.resolve(directory, file)to produce absolute paths, andconfigRoutesToRouteManifestpasses this absolute path directly tocreateRouteId()without normalizing it first.Root Cause
In
configRoutesToRouteManifest'swalk()function, thefileproperty was already normalized from absolute to relative:But
createRouteId(route.file)on the line above used the rawroute.file, which is still absolute when coming fromrelative().Solution
Extract the file normalization into a shared
normalizedFilevariable so both the route ID and thefileproperty use the relative path.This is a minimal change that applies the existing normalization logic to the ID computation.
Changeset
Included a patch changeset for
@react-router/dev.Test Plan
relative()produces absolute paths viaPath.resolve(), and the fix ensurescreateRouteIdreceives a relative path, matching the behavior of non-relative()routesconfigRoutesToRouteManifestin the repo; the fix is a straightforward refactor of existing normalization logic