From 00e730ed0252c41f96ef56e3003a595fb760eca6 Mon Sep 17 00:00:00 2001 From: Mark Dalgleish Date: Fri, 9 May 2025 16:34:40 +1000 Subject: [PATCH 1/2] Escape paths passed to `optimizeDeps.entries` --- .changeset/lovely-walls-exist.md | 5 +++++ packages/react-router-dev/package.json | 1 + packages/react-router-dev/vite/plugin.ts | 5 +++-- pnpm-lock.yaml | 26 +++++++++++++++++++++++- 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 .changeset/lovely-walls-exist.md diff --git a/.changeset/lovely-walls-exist.md b/.changeset/lovely-walls-exist.md new file mode 100644 index 0000000000..9fb0a9a0f2 --- /dev/null +++ b/.changeset/lovely-walls-exist.md @@ -0,0 +1,5 @@ +--- +"@react-router/dev": patch +--- + +Escape paths passed to `optimizeDeps.entries` to ensure special characters don't accidentally trigger pattern matching diff --git a/packages/react-router-dev/package.json b/packages/react-router-dev/package.json index 2f868a322a..8b1be5316b 100644 --- a/packages/react-router-dev/package.json +++ b/packages/react-router-dev/package.json @@ -89,6 +89,7 @@ "react-refresh": "^0.14.0", "semver": "^7.3.7", "set-cookie-parser": "^2.6.0", + "tinyglobby": "^0.2.13", "valibot": "^0.41.0", "vite-node": "3.0.0-beta.2" }, diff --git a/packages/react-router-dev/vite/plugin.ts b/packages/react-router-dev/vite/plugin.ts index 1532fa565e..e381688185 100644 --- a/packages/react-router-dev/vite/plugin.ts +++ b/packages/react-router-dev/vite/plugin.ts @@ -27,6 +27,7 @@ import pick from "lodash/pick"; import jsesc from "jsesc"; import colors from "picocolors"; import kebabCase from "lodash/kebabCase"; +import { convertPathToPattern } from "tinyglobby"; import * as Typegen from "../typegen"; import type { RouteManifestEntry, RouteManifest } from "../config/routes"; @@ -1224,7 +1225,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => { ...Object.values(ctx.reactRouterConfig.routes).map((route) => resolveRelativeRouteFilePath(route, ctx.reactRouterConfig) ), - ] + ].map(convertPathToPattern) : [], include: [ // Pre-bundle React dependencies to avoid React duplicates, @@ -1361,7 +1362,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => { ctx.reactRouterConfig ) ), - ], + ].map(convertPathToPattern), include: [ "react", "react/jsx-dev-runtime", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 715b3c9e9b..a91738351f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -897,6 +897,9 @@ importers: set-cookie-parser: specifier: ^2.6.0 version: 2.6.0 + tinyglobby: + specifier: ^0.2.13 + version: 0.2.13 valibot: specifier: ^0.41.0 version: 0.41.0(typescript@5.4.5) @@ -5678,6 +5681,14 @@ packages: picomatch: optional: true + fdir@6.4.4: + resolution: {integrity: sha512-1NZP+GK4GfuAv3PqKvxQRDMjdSRZjnkq7KfhlNrCNNlZ0ygQFpebfrnfnq/W7fpUnAv9aGWmY1zKx7FYL3gwhg==} + peerDependencies: + picomatch: ^3 || ^4 + peerDependenciesMeta: + picomatch: + optional: true + file-entry-cache@6.0.1: resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==} engines: {node: ^10.12.0 || >=12.0.0} @@ -8403,6 +8414,10 @@ packages: resolution: {integrity: sha512-qkf4trmKSIiMTs/E63cxH+ojC2unam7rJ0WrauAzpT3ECNTxGRMlaXxVbfxMUC/w0LaYk6jQ4y/nGR9uBO3tww==} engines: {node: '>=12.0.0'} + tinyglobby@0.2.13: + resolution: {integrity: sha512-mEwzpUgrLySlveBwEVDMKk5B57bhLPYovRfPAXD5gA/98Opn0rCDj3GtLwFvCvH5RK9uPCExUROW5NjDwvqkxw==} + engines: {node: '>=12.0.0'} + tinyglobby@0.2.9: resolution: {integrity: sha512-8or1+BGEdk1Zkkw2ii16qSS7uVrQJPre5A9o/XkWPATkk23FZh/15BKFxPnlTy6vkljZxLqYCzzBMj30ZrSvjw==} engines: {node: '>=12.0.0'} @@ -13928,6 +13943,10 @@ snapshots: optionalDependencies: picomatch: 4.0.2 + fdir@6.4.4(picomatch@4.0.2): + optionalDependencies: + picomatch: 4.0.2 + file-entry-cache@6.0.1: dependencies: flat-cache: 3.0.4 @@ -16808,7 +16827,7 @@ snapshots: picomatch: 4.0.2 postcss: 8.5.3 rolldown: 1.0.0-beta.7-commit.7452fa0(@oxc-project/runtime@0.61.2)(typescript@5.4.5) - tinyglobby: 0.2.12 + tinyglobby: 0.2.13 optionalDependencies: '@types/node': 20.11.30 esbuild: 0.25.0 @@ -17449,6 +17468,11 @@ snapshots: fdir: 6.4.3(picomatch@4.0.2) picomatch: 4.0.2 + tinyglobby@0.2.13: + dependencies: + fdir: 6.4.4(picomatch@4.0.2) + picomatch: 4.0.2 + tinyglobby@0.2.9: dependencies: fdir: 6.4.0(picomatch@4.0.2) From d050831b58a32ad9f9b9610d282fd9bdefc21b4a Mon Sep 17 00:00:00 2001 From: Mark Dalgleish Date: Fri, 9 May 2025 17:29:55 +1000 Subject: [PATCH 2/2] Switch to `escapePath` --- packages/react-router-dev/vite/plugin.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-router-dev/vite/plugin.ts b/packages/react-router-dev/vite/plugin.ts index e381688185..7ec2024b5f 100644 --- a/packages/react-router-dev/vite/plugin.ts +++ b/packages/react-router-dev/vite/plugin.ts @@ -27,7 +27,7 @@ import pick from "lodash/pick"; import jsesc from "jsesc"; import colors from "picocolors"; import kebabCase from "lodash/kebabCase"; -import { convertPathToPattern } from "tinyglobby"; +import { escapePath as escapePathAsGlob } from "tinyglobby"; import * as Typegen from "../typegen"; import type { RouteManifestEntry, RouteManifest } from "../config/routes"; @@ -1225,7 +1225,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => { ...Object.values(ctx.reactRouterConfig.routes).map((route) => resolveRelativeRouteFilePath(route, ctx.reactRouterConfig) ), - ].map(convertPathToPattern) + ].map(escapePathAsGlob) : [], include: [ // Pre-bundle React dependencies to avoid React duplicates, @@ -1362,7 +1362,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => { ctx.reactRouterConfig ) ), - ].map(convertPathToPattern), + ].map(escapePathAsGlob), include: [ "react", "react/jsx-dev-runtime",