Skip to content

Commit cd2342a

Browse files
[M3-10372] - Routing: Full switch + cleanup + remove react-router-dom (linode#12602)
* initial pass * initial pass * auth * auth progress * auth progress * typing progress * type fixes * tackling all the strays * tackling all the strays * remove react-router-dom entirely * unit tests * cleanup 1 * post rebase fix * moar cleanup * fix marketplace tab * cleanup comments * Added changeset: Routing: remove `react-router-dom` and fully switch to tanstack router * some e2e fixes * snackbar provider can contain links! * feedback @bnussman-akamai * feedback @coliu-akamai part 1 --------- Co-authored-by: Alban Bailly <[email protected]> Co-authored-by: Alban Bailly <[email protected]>
1 parent 639590f commit cd2342a

File tree

137 files changed

+1106
-2025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+1106
-2025
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Tech Stories
3+
---
4+
5+
Routing: remove `react-router-dom` and fully switch to tanstack router ([#12602](https://github.com/linode/manager/pull/12602))

packages/manager/cypress/e2e/core/linodes/resize-linode.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('resize linode', () => {
2121
createTestLinode({ booted: true }, { securityMethod: 'vlan_no_internet' })
2222
).then((linode) => {
2323
interceptLinodeResize(linode.id).as('linodeResize');
24-
cy.visitWithLogin(`/linodes/${linode.id}?resize=true`);
24+
cy.visitWithLogin(`/linodes/${linode.id}/metrics?resize=true`);
2525

2626
ui.dialog
2727
.findByTitle(`Resize Linode ${linode.label}`)
@@ -63,7 +63,7 @@ describe('resize linode', () => {
6363
createTestLinode({ booted: true }, { securityMethod: 'vlan_no_internet' })
6464
).then((linode) => {
6565
interceptLinodeResize(linode.id).as('linodeResize');
66-
cy.visitWithLogin(`/linodes/${linode.id}?resize=true`);
66+
cy.visitWithLogin(`/linodes/${linode.id}/metrics?resize=true`);
6767

6868
ui.dialog
6969
.findByTitle(`Resize Linode ${linode.label}`)
@@ -168,7 +168,7 @@ describe('resize linode', () => {
168168
// Error flow when attempting to resize a linode to a smaller size without
169169
// resizing the disk to the requested size first.
170170
interceptLinodeResize(linode.id).as('linodeResize');
171-
cy.visitWithLogin(`/linodes/${linode.id}?resize=true`);
171+
cy.visitWithLogin(`/linodes/${linode.id}/metrics?resize=true`);
172172

173173
ui.dialog
174174
.findByTitle(`Resize Linode ${linode.label}`)

packages/manager/cypress/support/component/setup.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { LDProvider } from 'launchdarkly-react-client-sdk';
2929
import { SnackbarProvider } from 'notistack';
3030
import * as React from 'react';
3131
import { Provider } from 'react-redux';
32-
import { MemoryRouter } from 'react-router-dom';
3332

3433
import { LinodeThemeWrapper } from 'src/LinodeThemeWrapper';
3534
import { storeFactory } from 'src/store';
@@ -79,9 +78,7 @@ export const mountWithTheme = (
7978
options={{ bootstrap: flags }}
8079
>
8180
<SnackbarProvider>
82-
<MemoryRouter>
83-
<RouterProvider router={router} />
84-
</MemoryRouter>
81+
<RouterProvider router={router} />
8582
</SnackbarProvider>
8683
</LDProvider>
8784
</LinodeThemeWrapper>

packages/manager/eslint.config.js

Lines changed: 3 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ const restrictedImportPaths = [
2929
'Please use Typography component from @linode/ui instead of @mui/material',
3030
},
3131
{
32-
name: 'react-router-dom',
32+
name: '@tanstack/react-router',
3333
importNames: ['Link'],
3434
message:
35-
'Please use the Link component from src/components/Link instead of react-router-dom',
35+
'Please use the Link component from src/components/Link instead of direct imports from @tanstack/react-router',
3636
},
3737
];
3838

@@ -401,93 +401,7 @@ export const baseConfig = [
401401
},
402402
},
403403

404-
// 14. Tanstack Router (temporary)
405-
{
406-
files: [
407-
// for each new features added to the migration router, add its directory here
408-
'src/features/Account/**/*',
409-
'src/features/Billing/**/*',
410-
'src/features/Betas/**/*',
411-
'src/features/CloudPulse/**/*',
412-
'src/features/Databases/**/*',
413-
'src/features/Domains/**/*',
414-
'src/features/DataStream/**/*',
415-
'src/features/Events/**/*',
416-
'src/features/Firewalls/**/*',
417-
'src/features/Help/**/*',
418-
'src/features/IAM/**/*',
419-
'src/features/Images/**/*',
420-
'src/features/Kubernetes/**/*',
421-
'src/features/Linodes/**/*',
422-
'src/features/Longview/**/*',
423-
'src/features/Managed/**/*',
424-
'src/features/NodeBalancers/**/*',
425-
'src/features/ObjectStorage/**/*',
426-
'src/features/PlacementGroups/**/*',
427-
'src/features/Profile/**/*',
428-
'src/features/Search/**/*',
429-
'src/features/TopMenu/SearchBar/**/*',
430-
'src/components/Tag/**/*',
431-
'src/features/StackScripts/**/*',
432-
'src/features/Support/**/*',
433-
'src/features/Users/**/*',
434-
'src/features/Volumes/**/*',
435-
'src/features/VPCs/**/*',
436-
],
437-
rules: {
438-
'no-restricted-imports': [
439-
// This needs to remain an error however trying to link to a feature that is not yet migrated will break the router
440-
// For those cases react-router-dom history.push is still needed
441-
// using `eslint-disable-next-line no-restricted-imports` can help bypass those imports
442-
'error',
443-
{
444-
paths: [
445-
{
446-
importNames: [
447-
// intentionally not including <Link> in this list as this will be updated last globally
448-
'useNavigate',
449-
'useParams',
450-
'useLocation',
451-
'useHistory',
452-
'useRouteMatch',
453-
'matchPath',
454-
'MemoryRouter',
455-
'Route',
456-
'RouteProps',
457-
'Switch',
458-
'Redirect',
459-
'RouteComponentProps',
460-
'withRouter',
461-
],
462-
message:
463-
'Please use routing utilities intended for @tanstack/react-router.',
464-
name: 'react-router-dom',
465-
},
466-
{
467-
importNames: ['TabLinkList'],
468-
message:
469-
'Please use the TanStackTabLinkList component for components being migrated to TanStack Router.',
470-
name: 'src/components/Tabs/TabLinkList',
471-
},
472-
{
473-
importNames: ['OrderBy', 'default'],
474-
message:
475-
'Please use useOrderV2 hook for components being migrated to TanStack Router.',
476-
name: 'src/components/OrderBy',
477-
},
478-
{
479-
importNames: ['Prompt'],
480-
message:
481-
'Please use the TanStack useBlocker hook for components/features being migrated to TanStack Router.',
482-
name: 'src/components/Prompt/Prompt',
483-
},
484-
],
485-
},
486-
],
487-
},
488-
},
489-
490-
// 15. Prettier (coming last as recommended)
404+
// 14. Prettier (coming last as recommended)
491405
{
492406
files: ['**/*.{js,ts,tsx}'],
493407
plugins: {

packages/manager/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@
7777
"react-hook-form": "^7.51.0",
7878
"react-number-format": "^3.5.0",
7979
"react-redux": "~7.1.3",
80-
"react-router-dom": "~5.3.4",
81-
"react-router-hash-link": "^2.3.1",
8280
"react-vnc": "^3.0.7",
8381
"react-waypoint": "^10.3.0",
8482
"recharts": "^2.14.1",
@@ -153,8 +151,6 @@
153151
"@types/react-csv": "^1.1.3",
154152
"@types/react-dom": "^19.1.6",
155153
"@types/react-redux": "~7.1.7",
156-
"@types/react-router-dom": "~5.3.3",
157-
"@types/react-router-hash-link": "^1.2.1",
158154
"@types/redux-mock-store": "^1.0.1",
159155
"@types/throttle-debounce": "^1.0.0",
160156
"@types/zxcvbn": "^4.4.0",

packages/manager/src/App.tsx

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,27 @@ import withFeatureFlagProvider from 'src/containers/withFeatureFlagProvider.cont
99
import { ErrorBoundaryFallback } from 'src/features/ErrorBoundary/ErrorBoundaryFallback';
1010

1111
import { SplashScreen } from './components/SplashScreen';
12-
import { GoTo } from './GoTo';
13-
import { useAdobeAnalytics } from './hooks/useAdobeAnalytics';
1412
import { useInitialRequests } from './hooks/useInitialRequests';
15-
import { useNewRelic } from './hooks/useNewRelic';
16-
import { usePendo } from './hooks/usePendo';
17-
import { useSessionExpiryToast } from './hooks/useSessionExpiryToast';
18-
import { MainContent } from './MainContent';
19-
import { useEventsPoller } from './queries/events/events';
20-
// import { Router } from './Router';
13+
import { Router } from './Router';
2114
import { useSetupFeatureFlags } from './useSetupFeatureFlags';
2215

2316
export const App = withDocumentTitleProvider(
2417
withFeatureFlagProvider(() => {
25-
const { isLoading } = useInitialRequests();
18+
// Skip all initialization if we're on any authentication callback - just let the router handle it
19+
const isAuthCallback =
20+
window.location.pathname === '/oauth/callback' ||
21+
window.location.pathname === '/admin/callback';
22+
23+
if (isAuthCallback) {
24+
return (
25+
<ErrorBoundaryFallback>
26+
<DocumentTitleSegment segment="Akamai Cloud Manager" />
27+
<Router />
28+
</ErrorBoundaryFallback>
29+
);
30+
}
2631

32+
const { isLoading } = useInitialRequests();
2733
const { areFeatureFlagsLoading } = useSetupFeatureFlags();
2834

2935
if (isLoading || areFeatureFlagsLoading) {
@@ -43,24 +49,9 @@ export const App = withDocumentTitleProvider(
4349
Opens an external site in a new window
4450
</span>
4551
</div>
46-
<GoTo />
4752
<DocumentTitleSegment segment="Akamai Cloud Manager" />
48-
{/**
49-
* Eventually we will have the <Router /> here in place of <MainContent />
50-
* <Router />
51-
*/}
52-
<MainContent />
53-
<GlobalListeners />
53+
<Router />
5454
</ErrorBoundaryFallback>
5555
);
5656
})
5757
);
58-
59-
const GlobalListeners = () => {
60-
useEventsPoller();
61-
useAdobeAnalytics();
62-
usePendo();
63-
useNewRelic();
64-
useSessionExpiryToast();
65-
return null;
66-
};

packages/manager/src/GoTo.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useAccountSettings, useGrants, useProfile } from '@linode/queries';
22
import { Dialog, Select } from '@linode/ui';
3+
import { useNavigate } from '@tanstack/react-router';
34
import * as React from 'react';
4-
import { useHistory } from 'react-router-dom';
55

66
import { useIsDatabasesEnabled } from './features/Databases/utilities';
77
import { useIsPlacementGroupsEnabled } from './features/PlacementGroups/utils';
@@ -10,7 +10,7 @@ import { useGlobalKeyboardListener } from './hooks/useGlobalKeyboardListener';
1010
import type { SelectOption } from '@linode/ui';
1111

1212
export const GoTo = React.memo(() => {
13-
const routerHistory = useHistory();
13+
const navigate = useNavigate();
1414

1515
const { data: accountSettings } = useAccountSettings();
1616
const { data: grants } = useGrants();
@@ -30,7 +30,7 @@ export const GoTo = React.memo(() => {
3030
};
3131

3232
const onSelect = (item: SelectOption<string>) => {
33-
routerHistory.push(item.value);
33+
navigate({ to: item.value });
3434
onClose();
3535
};
3636

0 commit comments

Comments
 (0)