Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.snapshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const config: Config.InitialOptions = {
setupFiles: ['<rootDir>/tests/js/sentry-test/snapshots/snapshot-setup.ts'],
setupFilesAfterEnv: ['<rootDir>/tests/js/sentry-test/snapshots/snapshot-framework.ts'],

resolver: '<rootDir>/tests/js/jestReactRouterResolver.cjs',
moduleNameMapper: {
'\\.(css|less|png|gif|jpg|woff|mp4)$':
'<rootDir>/tests/js/sentry-test/mocks/importStyleMock.js',
Expand Down
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ const config: Config.InitialOptions = {
],
coverageReporters: ['html', 'cobertura'],
coverageDirectory: '.artifacts/coverage',
resolver: '<rootDir>/tests/js/jestReactRouterResolver.cjs',
moduleNameMapper: {
'\\.(css|less|png|gif|jpg|avif|webp|woff|mp4)$':
'<rootDir>/tests/js/sentry-test/mocks/importStyleMock.js',
Expand Down
2 changes: 2 additions & 0 deletions knip.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const productionEntryPoints = [
'static/app/components/core/*/index.tsx',
// defined in rsbuild.config.ts pipelines
'static/app/utils/setupStatics.tsx',
// Source-scoped Rspack/Jest aliases use this runtime entry; TS uses types.d.ts.
'static/app/utils/reactRouterV6/index.ts',
'static/app/serviceWorker/worker/worker.ts',
// scripts are entry points
'scripts/*.ts',
Expand Down
17 changes: 17 additions & 0 deletions oxlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ const config = defineConfig({
'@sentry/no-digits-in-tn': 'error',
'@sentry/no-dynamic-translations': 'error',
'@sentry/no-flag-comments': 'error',
'@sentry/no-legacy-router-imports': 'error',
'@sentry/no-query-data-type-parameters': 'error',
'@sentry/no-raw-css-in-styled': 'error',
'@sentry/no-redundant-default-argument': 'error',
Expand Down Expand Up @@ -1462,6 +1463,22 @@ const config = defineConfig({
'unicorn-js/prefer-simple-condition-first': 'off',
},
overrides: [
{
files: [
'tests/js/jestReactRouterResolver.cjs',
'tests/js/jestReactRouterResolver.spec.ts',
],
env: {node: true},
rules: {'import/no-nodejs-modules': 'off'},
},
{
files: [
'static/app/utils/reactRouterV6/index.ts',
'static/app/utils/reactRouterV6/dom.ts',
'static/app/utils/reactRouterV6/types.d.ts',
],
rules: {'@sentry/no-legacy-router-imports': 'off'},
},
{
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'],
rules: {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
"react-grid-layout": "1.5.3",
"react-lazyload": "^3.2.1",
"react-popper": "^2.3.0",
"react-router": "6.30.6",
"react-router-dom": "6.30.6",
"react-select": "4.3.1",
"react-textarea-autosize": "8.5.7",
Expand Down Expand Up @@ -263,6 +264,7 @@
"jest-canvas-mock": "^2.5.8",
"jest-environment-node": "30.5.1",
"jest-fail-on-console": "3.3.4",
"jest-resolve": "30.5.1",
"jsdom": "30.1.1",
"knip": "6.40.0",
"odiff-bin": "4.3.8",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,21 @@ const appConfig: Configuration = {
* Please remember to test it.
*/
rules: [
{
// Only first-party imports use V8 paths. Leave dependencies and the
// compatibility implementation on the original V6 package resolution.
include: [staticPrefix, path.join(import.meta.dirname, 'tests/js')],
exclude: [path.join(staticPrefix, 'app/utils/reactRouterV6'), /node_modules/],
resolve: {
alias: {
'react-router$': path.join(staticPrefix, 'app/utils/reactRouterV6/index.ts'),
'react-router/dom$': path.join(
staticPrefix,
'app/utils/reactRouterV6/dom.ts'
),
},
},
},
{
test: /\.(?:tsx?|jsx?)$/,
oneOf: [
Expand Down
8 changes: 7 additions & 1 deletion static/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
### Routing

- Routes defined in `static/app/routes.tsx`
- Use React Router v6 patterns
- The app still runs React Router V6; follow V6 routing patterns and behavior.
- Use V8 import paths: import router APIs and types from `react-router`, and
`RouterProvider` from `react-router/dom`. These paths are aliased to the V6
runtime through `static/app/utils/reactRouterV6`.
- Only the compatibility modules may import `react-router-dom` or
`@remix-run/router` directly. Keep using Sentry's routing helpers where required.
Nuqs adapters and Sentry tracing integrations remain V6.
- Lazy load route components when possible

### Frontend API Calls
Expand Down
2 changes: 1 addition & 1 deletion static/app/actionCreators/organizations.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {NavigateFunction} from 'react-router-dom';
import type {NavigateFunction} from 'react-router';

import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
import type {Client} from 'sentry/api';
Expand Down
2 changes: 1 addition & 1 deletion static/app/bootstrap/initializeSdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
matchRoutes,
useLocation,
useNavigationType,
} from 'react-router-dom';
} from 'react-router';
import {type Event, type Log} from '@sentry/core';
import * as Sentry from '@sentry/react';

Expand Down
3 changes: 2 additions & 1 deletion static/app/bootstrap/processInitQueue.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useState} from 'react';
import {createRoot} from 'react-dom/client';
import {createBrowserRouter, RouterProvider} from 'react-router-dom';
import {createBrowserRouter} from 'react-router';
import {RouterProvider} from 'react-router/dom';
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
import throttle from 'lodash/throttle';

Expand Down
2 changes: 1 addition & 1 deletion static/app/components/core/link/link.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {type LinkProps as ReactRouterLinkProps} from 'react-router-dom';
import {type LinkProps as ReactRouterLinkProps} from 'react-router';
import isPropValid from '@emotion/is-prop-valid';
import {css, type Theme} from '@emotion/react';
import styled from '@emotion/styled';
Expand Down
2 changes: 1 addition & 1 deletion static/app/components/core/link/linkBehaviorContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {createContext, useContext, type FunctionComponent} from 'react';
import {Link as RouterLink} from 'react-router-dom';
import {Link as RouterLink} from 'react-router';
import * as Sentry from '@sentry/react';

import type {LinkProps} from './link';
Expand Down
2 changes: 1 addition & 1 deletion static/app/components/core/tabs/tabList.snapshots.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {MemoryRouter} from 'react-router-dom';
import {MemoryRouter} from 'react-router';

import {TabList, Tabs} from '@sentry/scraps/tabs';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {RequestError} from 'sentry/utils/requestError/requestError';

import ReplayClipPreview from './replayClipPreview';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
jest.mock('react-router', () => ({
...jest.requireActual('react-router'),
useMatches: jest.fn(() => [
{
id: '0',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {ComponentProps} from 'react';
import {useEffect, useRef, useState} from 'react';
import {useMatches} from 'react-router-dom';
import {useMatches} from 'react-router';
import styled from '@emotion/styled';
import type {Query} from 'history';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Fragment, useMemo} from 'react';
import {useMatches} from 'react-router-dom';
import {useMatches} from 'react-router';
import styled from '@emotion/styled';

import {LinkButton, type LinkButtonProps} from '@sentry/scraps/button';
Expand Down
2 changes: 1 addition & 1 deletion static/app/components/links/listLink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NavLink} from 'react-router-dom';
import {NavLink} from 'react-router';
import classNames from 'classnames';
import type {LocationDescriptor} from 'history';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useCallback, useMemo, useRef} from 'react';
import {useMatches} from 'react-router-dom';
import {useMatches} from 'react-router';
import {isAppleDevice} from '@react-aria/utils';
import isEqual from 'lodash/isEqual';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Fragment, useCallback, useMemo, useRef, useState} from 'react';
import {useMatches} from 'react-router-dom';
import {useMatches} from 'react-router';
import {isAppleDevice} from '@react-aria/utils';
import sortBy from 'lodash/sortBy';
import xor from 'lodash/xor';
Expand Down
2 changes: 1 addition & 1 deletion static/app/components/replays/header/replayMetaData.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Fragment} from 'react';
import {useMatches} from 'react-router-dom';
import {useMatches} from 'react-router';
import styled from '@emotion/styled';

import {Link} from '@sentry/scraps/link';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ReactNode} from 'react';
import {useMatches} from 'react-router-dom';
import {useMatches} from 'react-router';
import {useTheme} from '@emotion/react';
import styled from '@emotion/styled';
import type {LocationDescriptor} from 'history';
Expand Down
2 changes: 1 addition & 1 deletion static/app/components/timeRangeSelector/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Fragment, useCallback, useState} from 'react';
import * as React from 'react';
import {useMatches} from 'react-router-dom';
import {useMatches} from 'react-router';
import styled from '@emotion/styled';
import {mergeProps} from '@react-aria/utils';

Expand Down
3 changes: 2 additions & 1 deletion static/app/main.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {lazy, Suspense, useEffect, useState} from 'react';
import {createBrowserRouter, RouterProvider} from 'react-router-dom';
import {createBrowserRouter} from 'react-router';
import {RouterProvider} from 'react-router/dom';
import {wrapCreateBrowserRouterV6} from '@sentry/react';
import {MotionConfig} from 'framer-motion';
import {NuqsAdapter} from 'nuqs/adapters/react-router/v6';
Expand Down
2 changes: 1 addition & 1 deletion static/app/router/preload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {matchRoutes, type RouteObject, type To} from 'react-router-dom';
import {matchRoutes, type RouteObject, type To} from 'react-router';
import * as Sentry from '@sentry/react';

export const PRELOAD_HANDLE = '_preload';
Expand Down
2 changes: 1 addition & 1 deletion static/app/router/routeConfigContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {createContext, useContext} from 'react';
import type {RouteObject} from 'react-router-dom';
import type {RouteObject} from 'react-router';

const RouteConfigContext = createContext<RouteObject[] | null>(null);

Expand Down
2 changes: 1 addition & 1 deletion static/app/router/routeMapTestUtils.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {RouteObject} from 'react-router-dom';
import type {RouteObject} from 'react-router';

import {
dedupeRoutes,
Expand Down
2 changes: 1 addition & 1 deletion static/app/router/routeMapTestUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {RouteObject} from 'react-router-dom';
import type {RouteObject} from 'react-router';

import {PRELOAD_HANDLE} from 'sentry/router/preload';
import {normalizeUrl} from 'sentry/utils/url/normalizeUrl';
Expand Down
2 changes: 1 addition & 1 deletion static/app/router/routes.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {matchRoutes, type RouteObject} from 'react-router-dom';
import {matchRoutes, type RouteObject} from 'react-router';

import * as constants from 'sentry/constants';
import {buildRoutes} from 'sentry/router/routes';
Expand Down
3 changes: 1 addition & 2 deletions static/app/router/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {RouteObject} from 'react-router-dom';
import {Outlet} from 'react-router-dom';
import {Outlet, type RouteObject} from 'react-router';
import memoize from 'lodash/memoize';

import {t} from 'sentry/locale';
Expand Down
2 changes: 1 addition & 1 deletion static/app/scrapsProviders/link.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useMemo} from 'react';
import {Link as RouterLink} from 'react-router-dom';
import {Link as RouterLink} from 'react-router';

import {LinkBehaviorContextProvider, type LinkProps} from '@sentry/scraps/link';

Expand Down
2 changes: 1 addition & 1 deletion static/app/stories/view/legacyStoriesRedirect.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Navigate} from 'react-router-dom';
import {Navigate} from 'react-router';

import {useLocation} from 'sentry/utils/useLocation';

Expand Down
2 changes: 1 addition & 1 deletion static/app/stories/view/storyTableOfContents.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react';
import {useLocation} from 'react-router-dom';
import {useLocation} from 'react-router';
import {css} from '@emotion/react';
import styled from '@emotion/styled';

Expand Down
2 changes: 1 addition & 1 deletion static/app/types/overrides.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {UIMatch} from 'react-router-dom';
import type {UIMatch} from 'react-router';
import type {Location} from 'history';

import type {TrackingProps} from '@sentry/scraps/trackingContext';
Expand Down
2 changes: 1 addition & 1 deletion static/app/utils/getRouteStringFromRoutes.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {UIMatch} from 'react-router-dom';
import type {UIMatch} from 'react-router';

import {getRouteStringFromRoutes} from 'sentry/utils/getRouteStringFromRoutes';

Expand Down
4 changes: 2 additions & 2 deletions static/app/utils/getRouteStringFromRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {UIMatch} from 'react-router-dom';
import type {UIMatch} from 'react-router';

import type {PlainRoute} from 'sentry/types/legacyReactRouter';

Expand All @@ -20,7 +20,7 @@ type Props =
* It will look for the last route path that begins with a `/` and
* concatenate all of the following routes. Skips any routes without a path
*
* @param params.matches An array of UIMatch objects from react-router-dom `useMatches()`
* @param params.matches An array of UIMatch objects from react-router `useMatches()`
* @returns A route path string
*/
export function getRouteStringFromRoutes({routes, matches}: Props): string {
Expand Down
2 changes: 1 addition & 1 deletion static/app/utils/navigateIfQueryChanged.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {NavigateOptions} from 'react-router-dom';
import type {NavigateOptions} from 'react-router';
import type {Location} from 'history';
import * as qs from 'query-string';

Expand Down
2 changes: 1 addition & 1 deletion static/app/utils/provideAriaRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useCallback} from 'react';
import {useHref} from 'react-router-dom';
import {useHref} from 'react-router';
import {RouterProvider as AriaRouterProvider} from '@react-aria/utils';

import {useNavigate} from 'sentry/utils/useNavigate';
Expand Down
2 changes: 1 addition & 1 deletion static/app/utils/reactRouter6Compat/location.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Location as Location6, To} from 'react-router-dom';
import type {Location as Location6, To} from 'react-router';
import * as Sentry from '@sentry/react';
import type {Location as Location3, LocationDescriptor, Query} from 'history';
import * as qs from 'query-string';
Expand Down
2 changes: 1 addition & 1 deletion static/app/utils/reactRouter6Compat/onRouteLeave.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {unstable_usePrompt, type Location} from 'react-router-dom';
import {unstable_usePrompt, type Location} from 'react-router';

type ReactRouterV6RouteLeaveCallback = (state: {
currentLocation: Location;
Expand Down
2 changes: 1 addition & 1 deletion static/app/utils/reactRouter6Compat/router.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useEffect} from 'react';
import {Navigate, type NavigateProps, type RouteObject} from 'react-router-dom';
import {Navigate, type NavigateProps, type RouteObject} from 'react-router';
import * as Sentry from '@sentry/react';

import {USING_CUSTOMER_DOMAIN} from 'sentry/constants';
Expand Down
1 change: 1 addition & 0 deletions static/app/utils/reactRouterV6/dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {RouterProvider} from 'react-router-dom';
Comment thread
nsdeschenes marked this conversation as resolved.
Resolved
10 changes: 10 additions & 0 deletions static/app/utils/reactRouterV6/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Resolve V8 package paths to the existing V6 runtime until the runtime upgrade.
// oxlint-disable-next-line import/export -- V6 DOM re-exports the aliased core; types.d.ts bypasses that cycle.
export * from 'react-router-dom';
export {
createMemoryHistory as UNSAFE_createMemoryHistory,
createRouter as UNSAFE_createRouter,
type Router as DataRouter,
type InitialEntry,
type RouterNavigateOptions,
} from '@remix-run/router';
Loading
Loading