From a090ecb8480460d79bdb9136d1e67d072d2b3f03 Mon Sep 17 00:00:00 2001 From: therealsama <263038098+therealsama@users.noreply.github.com> Date: Fri, 7 Aug 2026 09:56:38 +0200 Subject: [PATCH] chore(deps): upgrade react-router to v8.3.0 and drop react-router-dom react-router 7.x is covered by GHSA-qwww-vcr4-c8h2 (high), whose vulnerable range is >=7.12.0 <8.3.0 with no 7.x patch. This fails the dependency-review CI gate on every Dependabot bump that touches react-router, and since the prod-minor-patch group is limited to minor/patch updates it can never reach the fix on its own. The advisory only affects the unstable RSC APIs, which this static HashRouter SPA does not use, so it was never exploitable here. Upgrading resolves it outright rather than suppressing it. v8 removes the react-router-dom package, so the dependency is replaced with react-router and imports are updated across the app. All symbols in use (HashRouter, Link, MemoryRouter, NavigationType, Route, Routes, useLocation, useNavigate, useNavigationType, useParams) are exported from the v8 root entry point, so no API changes were needed. The v8 requirements of Node >=22.22.0 and React >=19.2.7 are already satisfied. --- package-lock.json | 46 ++++++------------- package.json | 2 +- src/App.test.tsx | 2 +- src/App.tsx | 2 +- src/components/AuthorByline.tsx | 2 +- src/components/Comment.tsx | 2 +- src/components/CommentArticle.test.tsx | 2 +- src/components/CommentArticle.tsx | 2 +- src/components/CommentDetail.test.tsx | 2 +- src/components/CommentDetail.tsx | 2 +- src/components/Header.tsx | 2 +- src/components/InfiniteStoryListPage.test.tsx | 2 +- src/components/ItemArticle.tsx | 2 +- src/components/StateView.tsx | 2 +- src/components/StoryCard.test.tsx | 2 +- src/components/StoryCard.tsx | 2 +- src/components/SwipeCommentViewer.tsx | 2 +- src/components/SwipeStoryViewer.tsx | 2 +- src/hooks/useScrollRestore.test.ts | 10 ++-- src/hooks/useScrollRestore.ts | 2 +- src/pages/DomainStories.tsx | 2 +- src/pages/ItemDetail.test.tsx | 2 +- src/pages/ItemDetail.tsx | 2 +- src/pages/UserProfile.test.tsx | 2 +- src/pages/UserProfile.tsx | 2 +- src/pages/UserSubmissions.test.tsx | 2 +- src/pages/UserSubmissions.tsx | 2 +- src/test/test-utils.tsx | 2 +- 28 files changed, 46 insertions(+), 62 deletions(-) diff --git a/package-lock.json b/package-lock.json index d00eb23..6f1ce5b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "react": "^19.2.7", "react-dom": "^19.2.7", "react-intersection-observer": "^10.1.0", - "react-router-dom": "^7.18.1", + "react-router": "^8.3.0", "tailwind-merge": "^3.6.0" }, "devDependencies": { @@ -5356,6 +5356,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/cookie/-/cookie-1.1.1.tgz", "integrity": "sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ==", + "dev": true, "license": "MIT", "engines": { "node": ">=18" @@ -5365,6 +5366,12 @@ "url": "https://opencollective.com/express" } }, + "node_modules/cookie-es": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/cookie-es/-/cookie-es-3.1.1.tgz", + "integrity": "sha512-UaXxwISYJPTr9hwQxMFYZ7kNhSXboMXP+Z3TRX6f1/NyaGPfuNUZOWP1pUEb75B2HjfklIYLVRfWiFZJyC6Npg==", + "license": "MIT" + }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", @@ -7368,20 +7375,19 @@ } }, "node_modules/react-router": { - "version": "7.18.1", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-7.18.1.tgz", - "integrity": "sha512-GDLgg3i3uM0aeJO3Fm+TCS+sDQ7gu12T6x0qdTEzcwqEfleci7JwugVNIF3U//0FWKnJT7ptG+20B2jfDqnZAg==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-8.3.0.tgz", + "integrity": "sha512-qyPMvW83jGIct3yiieisxdk9M745anqhpIMKN5m1t6yBMfgVPpt77aHOqs5fUlEJRMCGffg9BaQLH9oPVOL7xQ==", "license": "MIT", "dependencies": { - "cookie": "^1.0.1", - "set-cookie-parser": "^2.6.0" + "cookie-es": "^3.1.1" }, "engines": { - "node": ">=20.0.0" + "node": ">=22.22.0" }, "peerDependencies": { - "react": ">=18", - "react-dom": ">=18" + "react": ">=19.2.7", + "react-dom": ">=19.2.7" }, "peerDependenciesMeta": { "react-dom": { @@ -7389,22 +7395,6 @@ } } }, - "node_modules/react-router-dom": { - "version": "7.18.1", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-7.18.1.tgz", - "integrity": "sha512-KaZh+X/6UtEp28x51AUYZDMg9NGoz2ja3dNHa+ta/tk40vCzKhQ/RypCWBMLbmDr6//E24Vv5uPsrqXFozdkAg==", - "license": "MIT", - "dependencies": { - "react-router": "7.18.1" - }, - "engines": { - "node": ">=20.0.0" - }, - "peerDependencies": { - "react": ">=18", - "react-dom": ">=18" - } - }, "node_modules/react-style-singleton": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/react-style-singleton/-/react-style-singleton-2.2.3.tgz", @@ -7549,12 +7539,6 @@ "semver": "bin/semver.js" } }, - "node_modules/set-cookie-parser": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.2.tgz", - "integrity": "sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==", - "license": "MIT" - }, "node_modules/sharp": { "version": "0.35.3", "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.35.3.tgz", diff --git a/package.json b/package.json index 537eea8..f85ddf2 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "react": "^19.2.7", "react-dom": "^19.2.7", "react-intersection-observer": "^10.1.0", - "react-router-dom": "^7.18.1", + "react-router": "^8.3.0", "tailwind-merge": "^3.6.0" }, "devDependencies": { diff --git a/src/App.test.tsx b/src/App.test.tsx index ac58c72..c66469d 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -1,6 +1,6 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'; import { screen } from '@testing-library/react'; -import { Routes, Route } from 'react-router-dom'; +import { Routes, Route } from 'react-router'; import { render } from './test/test-utils'; import { MobileItemDetailWrapper } from './App'; import { saveSwipePosition } from './utils/swipePosition'; diff --git a/src/App.tsx b/src/App.tsx index ff82d9f..e70b825 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import { HashRouter, Routes, Route, useParams, useLocation, useNavigate } from 'react-router-dom'; +import { HashRouter, Routes, Route, useParams, useLocation, useNavigate } from 'react-router'; import { useState, useEffect, type ReactNode } from 'react'; import { ThemeProvider } from './context/ThemeContext'; import { ScrollContainerProvider } from './context/ScrollContainerContext'; diff --git a/src/components/AuthorByline.tsx b/src/components/AuthorByline.tsx index c9a649d..afe20a7 100644 --- a/src/components/AuthorByline.tsx +++ b/src/components/AuthorByline.tsx @@ -1,5 +1,5 @@ import type { ReactNode } from 'react'; -import { Link } from 'react-router-dom'; +import { Link } from 'react-router'; import { User } from 'lucide-react'; import { isKnownAuthor } from '../api/hn'; import { metaPillClass } from '../lib/classes'; diff --git a/src/components/Comment.tsx b/src/components/Comment.tsx index e495739..d0da61e 100644 --- a/src/components/Comment.tsx +++ b/src/components/Comment.tsx @@ -1,5 +1,5 @@ import { useMemo, useState, type CSSProperties } from 'react'; -import { Link } from 'react-router-dom'; +import { Link } from 'react-router'; import { isKnownAuthor } from '../api/hn'; import { sanitizeHtml } from '../utils/sanitize'; import { OpWrap } from './AuthorByline'; diff --git a/src/components/CommentArticle.test.tsx b/src/components/CommentArticle.test.tsx index 32f3eb2..b219fe9 100644 --- a/src/components/CommentArticle.test.tsx +++ b/src/components/CommentArticle.test.tsx @@ -1,6 +1,6 @@ import { describe, it, expect } from 'vitest'; import { screen, fireEvent } from '@testing-library/react'; -import { Routes, Route, useLocation } from 'react-router-dom'; +import { Routes, Route, useLocation } from 'react-router'; import { render } from '../test/test-utils'; import { CommentArticle } from './CommentArticle'; diff --git a/src/components/CommentArticle.tsx b/src/components/CommentArticle.tsx index c5c1a2f..e9e1514 100644 --- a/src/components/CommentArticle.tsx +++ b/src/components/CommentArticle.tsx @@ -1,5 +1,5 @@ import { useMemo } from 'react'; -import { Link } from 'react-router-dom'; +import { Link } from 'react-router'; import { Clock, CornerUpLeft, MessagesSquare } from 'lucide-react'; import { CommentTree } from './Comment'; import { CommentSkeletonTree } from './CommentSkeleton'; diff --git a/src/components/CommentDetail.test.tsx b/src/components/CommentDetail.test.tsx index 1c5086d..ad1ff6d 100644 --- a/src/components/CommentDetail.test.tsx +++ b/src/components/CommentDetail.test.tsx @@ -1,7 +1,7 @@ import { describe, it, expect } from 'vitest'; import { screen, waitFor } from '@testing-library/react'; import { render } from '../test/test-utils'; -import { Routes, Route } from 'react-router-dom'; +import { Routes, Route } from 'react-router'; import { CommentDetail } from './CommentDetail'; function renderCommentDetail(commentId: number | string, initialData?: { author: string; text: string; createdAt: number }) { diff --git a/src/components/CommentDetail.tsx b/src/components/CommentDetail.tsx index 393bb23..758067c 100644 --- a/src/components/CommentDetail.tsx +++ b/src/components/CommentDetail.tsx @@ -1,5 +1,5 @@ import { useEffect } from 'react'; -import { useNavigate, useLocation } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router'; import { useCommentDetail } from '../hooks/useCommentDetail'; import { useNetworkStatus } from '../hooks/useNetworkStatus'; import { useAutoRetry } from '../hooks/useAutoRetry'; diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 6b81360..8a03ca4 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -1,5 +1,5 @@ import { useId, useMemo, useRef } from 'react'; -import { Link, useLocation } from 'react-router-dom'; +import { Link, useLocation } from 'react-router'; import { ChevronDown, Flame, diff --git a/src/components/InfiniteStoryListPage.test.tsx b/src/components/InfiniteStoryListPage.test.tsx index 9d1a3fe..dc4dd3c 100644 --- a/src/components/InfiniteStoryListPage.test.tsx +++ b/src/components/InfiniteStoryListPage.test.tsx @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { screen, fireEvent } from '@testing-library/react'; -import { Routes, Route } from 'react-router-dom'; +import { Routes, Route } from 'react-router'; import { render } from '../test/test-utils'; import { createStoryItem } from '../test/factories'; import { diff --git a/src/components/ItemArticle.tsx b/src/components/ItemArticle.tsx index 2a22a32..1741161 100644 --- a/src/components/ItemArticle.tsx +++ b/src/components/ItemArticle.tsx @@ -1,5 +1,5 @@ import { useMemo } from 'react'; -import { Link } from 'react-router-dom'; +import { Link } from 'react-router'; import { ChevronUp, Clock, Globe, MessageSquare } from 'lucide-react'; import { getHostname } from '../api/hn'; import { sanitizeHtml } from '../utils/sanitize'; diff --git a/src/components/StateView.tsx b/src/components/StateView.tsx index e811bf3..4201c11 100644 --- a/src/components/StateView.tsx +++ b/src/components/StateView.tsx @@ -1,4 +1,4 @@ -import { Link } from 'react-router-dom'; +import { Link } from 'react-router'; import { RefreshCw } from 'lucide-react'; import { Button } from './ui'; diff --git a/src/components/StoryCard.test.tsx b/src/components/StoryCard.test.tsx index 81373d4..3822151 100644 --- a/src/components/StoryCard.test.tsx +++ b/src/components/StoryCard.test.tsx @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { screen, fireEvent } from '@testing-library/react'; -import { Routes, Route, useLocation } from 'react-router-dom'; +import { Routes, Route, useLocation } from 'react-router'; import { render } from '../test/test-utils'; import { StoryCard } from './StoryCard'; import { clearViewed, markViewedWithTime, clearViewedTimes, clearSessionViewed, VIEWED_DETAIL_TIMES_KEY, VIEWED_SESSION_KEY } from '../utils/viewedItems'; diff --git a/src/components/StoryCard.tsx b/src/components/StoryCard.tsx index a411fd2..755d027 100644 --- a/src/components/StoryCard.tsx +++ b/src/components/StoryCard.tsx @@ -1,5 +1,5 @@ import { useEffect, useRef, useCallback, useMemo, useState, type CSSProperties } from 'react'; -import { Link } from 'react-router-dom'; +import { Link } from 'react-router'; import { useInView } from 'react-intersection-observer'; import { ChevronUp, Clock, Globe, MessageSquare } from 'lucide-react'; import { getHostname } from '../api/hn'; diff --git a/src/components/SwipeCommentViewer.tsx b/src/components/SwipeCommentViewer.tsx index d482369..6cd9d96 100644 --- a/src/components/SwipeCommentViewer.tsx +++ b/src/components/SwipeCommentViewer.tsx @@ -1,5 +1,5 @@ import { useState, useRef, useEffect, useLayoutEffect, useCallback } from 'react'; -import { useNavigate, useLocation } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router'; import { useSwipeScroll } from '../hooks/useSwipeScroll'; import { useDocumentTitle } from '../hooks/useDocumentTitle'; import { useNetworkStatus } from '../hooks/useNetworkStatus'; diff --git a/src/components/SwipeStoryViewer.tsx b/src/components/SwipeStoryViewer.tsx index e6d35aa..370841e 100644 --- a/src/components/SwipeStoryViewer.tsx +++ b/src/components/SwipeStoryViewer.tsx @@ -1,5 +1,5 @@ import { useState, useRef, useEffect, useLayoutEffect, useMemo } from 'react'; -import { useNavigate, useLocation } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router'; import { useInfiniteStories } from '../hooks/useInfiniteStories'; import { useSwipeScroll } from '../hooks/useSwipeScroll'; import { usePrefetchItems } from '../hooks/usePrefetchItem'; diff --git a/src/hooks/useScrollRestore.test.ts b/src/hooks/useScrollRestore.test.ts index 540e3a8..f576382 100644 --- a/src/hooks/useScrollRestore.test.ts +++ b/src/hooks/useScrollRestore.test.ts @@ -1,18 +1,18 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { renderHook, act, waitFor } from '@testing-library/react'; -import { useNavigationType, NavigationType } from 'react-router-dom'; -import type * as ReactRouterDom from 'react-router-dom'; +import { useNavigationType, NavigationType } from 'react-router'; +import type * as ReactRouter from 'react-router'; import { useScrollRestore } from './useScrollRestore'; import { writeScrollPosition, readScrollPosition, } from '../utils/scrollRestore'; -// Mock react-router-dom's useNavigationType so tests don't need a Router +// Mock react-router's useNavigationType so tests don't need a Router // context. Tests that don't set the value explicitly get NavigationType.Pop // (the "browser back / reload / initial load" default the hook restores on). -vi.mock('react-router-dom', async () => { - const actual = await vi.importActual('react-router-dom'); +vi.mock('react-router', async () => { + const actual = await vi.importActual('react-router'); return { ...actual, useNavigationType: vi.fn(() => actual.NavigationType.Pop) }; }); diff --git a/src/hooks/useScrollRestore.ts b/src/hooks/useScrollRestore.ts index 65f61ca..0bb4293 100644 --- a/src/hooks/useScrollRestore.ts +++ b/src/hooks/useScrollRestore.ts @@ -1,5 +1,5 @@ import { useCallback, useLayoutEffect, useRef } from 'react'; -import { useNavigationType, NavigationType } from 'react-router-dom'; +import { useNavigationType, NavigationType } from 'react-router'; import { readScrollPosition, writeScrollPosition } from '../utils/scrollRestore'; /** diff --git a/src/pages/DomainStories.tsx b/src/pages/DomainStories.tsx index 70fee1b..0cb2191 100644 --- a/src/pages/DomainStories.tsx +++ b/src/pages/DomainStories.tsx @@ -1,4 +1,4 @@ -import { useParams } from 'react-router-dom'; +import { useParams } from 'react-router'; import { InfiniteStoryListPage, StateView } from '../components'; import { useDocumentTitle } from '../hooks/useDocumentTitle'; import { useScrollRestore } from '../hooks/useScrollRestore'; diff --git a/src/pages/ItemDetail.test.tsx b/src/pages/ItemDetail.test.tsx index 4bdf8d6..40f3982 100644 --- a/src/pages/ItemDetail.test.tsx +++ b/src/pages/ItemDetail.test.tsx @@ -1,7 +1,7 @@ import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'; import { screen, waitFor, fireEvent } from '@testing-library/react'; import { render } from '../test/test-utils'; -import { Routes, Route } from 'react-router-dom'; +import { Routes, Route } from 'react-router'; import { ItemDetail } from './ItemDetail'; import { clearViewed, markViewed, isViewed } from '../utils/viewedItems'; import { http, HttpResponse } from 'msw'; diff --git a/src/pages/ItemDetail.tsx b/src/pages/ItemDetail.tsx index b791198..2a40c6d 100644 --- a/src/pages/ItemDetail.tsx +++ b/src/pages/ItemDetail.tsx @@ -1,4 +1,4 @@ -import { useParams } from 'react-router-dom'; +import { useParams } from 'react-router'; import { useEffect } from 'react'; import { useItemWithComments } from '../hooks/useItemWithComments'; import { ItemDetailSkeleton, CommentDetail, StateView, CommentsSection, ItemArticle, PageStage } from '../components'; diff --git a/src/pages/UserProfile.test.tsx b/src/pages/UserProfile.test.tsx index bbb9fa6..12a7e3f 100644 --- a/src/pages/UserProfile.test.tsx +++ b/src/pages/UserProfile.test.tsx @@ -1,7 +1,7 @@ import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'; import { screen, waitFor } from '@testing-library/react'; import { render } from '../test/test-utils'; -import { Routes, Route } from 'react-router-dom'; +import { Routes, Route } from 'react-router'; import { UserProfile } from './UserProfile'; import { __resetUserProfileCacheForTests } from '../hooks/useUserProfile'; import { ScrollContainerProvider } from '../context/ScrollContainerContext'; diff --git a/src/pages/UserProfile.tsx b/src/pages/UserProfile.tsx index 5b84096..c815100 100644 --- a/src/pages/UserProfile.tsx +++ b/src/pages/UserProfile.tsx @@ -1,5 +1,5 @@ import { useLayoutEffect, useMemo } from 'react'; -import { Link, useParams } from 'react-router-dom'; +import { Link, useParams } from 'react-router'; import { Award, Calendar, FileText } from 'lucide-react'; import { useUserProfile } from '../hooks/useUserProfile'; import { useDocumentTitle } from '../hooks/useDocumentTitle'; diff --git a/src/pages/UserSubmissions.test.tsx b/src/pages/UserSubmissions.test.tsx index e8b94d4..2f10213 100644 --- a/src/pages/UserSubmissions.test.tsx +++ b/src/pages/UserSubmissions.test.tsx @@ -1,7 +1,7 @@ import { describe, it, expect, beforeEach } from 'vitest'; import { screen, waitFor } from '@testing-library/react'; import { render } from '../test/test-utils'; -import { Routes, Route } from 'react-router-dom'; +import { Routes, Route } from 'react-router'; import { UserSubmissions } from './UserSubmissions'; import { __resetUserStoriesCacheForTests } from '../hooks/useUserInfiniteStories'; import { http, HttpResponse } from 'msw'; diff --git a/src/pages/UserSubmissions.tsx b/src/pages/UserSubmissions.tsx index bab4c36..8da6d16 100644 --- a/src/pages/UserSubmissions.tsx +++ b/src/pages/UserSubmissions.tsx @@ -1,4 +1,4 @@ -import { useParams } from 'react-router-dom'; +import { useParams } from 'react-router'; import { InfiniteStoryListPage, StateView } from '../components'; import { useDocumentTitle } from '../hooks/useDocumentTitle'; import { useScrollRestore } from '../hooks/useScrollRestore'; diff --git a/src/test/test-utils.tsx b/src/test/test-utils.tsx index bca8d6f..0fee0d9 100644 --- a/src/test/test-utils.tsx +++ b/src/test/test-utils.tsx @@ -1,6 +1,6 @@ /* eslint-disable react-refresh/only-export-components */ import { render, type RenderOptions } from '@testing-library/react'; -import { MemoryRouter } from 'react-router-dom'; +import { MemoryRouter } from 'react-router'; import { ThemeProvider } from '../context/ThemeContext'; import { NetworkStatusProvider } from '../context/NetworkStatusContext'; import { TooltipProvider } from '../components/ui';