Skip to content

Commit dff7dcf

Browse files
committed
fix: replace react-router-dom with @equinor/fusion-framework-react-router in state-replication cookbook
The cookbook mixed react-router-dom's RouterProvider with the router instance returned by useRouter (@equinor/fusion-framework-react-app), which internally uses @remix-run/router via the navigation module. The mismatched react-router runtimes caused a crash in useRoutesImpl at render time. Also clean up remaining biome lint issues (unused imports/vars, array index keys, banned {} type) left over from the earlier fusion-lint cleanup pass.
1 parent 51bc5d2 commit dff7dcf

30 files changed

Lines changed: 77 additions & 139 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@equinor/fusion-framework-cookbook-app-react-state-replication": patch
3+
---
4+
5+
Fix a runtime crash on route render caused by mixing `react-router-dom`'s `RouterProvider` with the router instance returned by `useRouter` from `@equinor/fusion-framework-react-app/navigation`. The router and route components now come from `@equinor/fusion-framework-react-router`, matching the react-router runtime used internally by the framework's navigation module.

cookbooks/app-react-state-replication/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@
2626
"@equinor/fusion-framework-module-navigation": "workspace:^",
2727
"@equinor/fusion-framework-module-state": "workspace:^",
2828
"@equinor/fusion-framework-react-app": "workspace:^",
29+
"@equinor/fusion-framework-react-router": "workspace:^",
2930
"@equinor/fusion-observable": "workspace:^",
3031
"@types/pouchdb": "^6.4.2",
3132
"@types/react": "^18.2.50",
3233
"@types/react-dom": "^18.2.7",
33-
"@types/react-router-dom": "^5.3.3",
3434
"@types/uuid": "^10.0.0",
3535
"pouchdb": "^9.0.0",
3636
"react": "^18.2.0",
3737
"react-dom": "^18.2.0",
38-
"react-router-dom": "^7.8.2",
3938
"rxjs": "^7.8.1",
4039
"styled-components": "^6.0.7",
4140
"typescript": "^5.8.2",

cookbooks/app-react-state-replication/src/Router.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { RouterProvider, type RouteObject } from 'react-router-dom';
1+
import { RouterProvider } from '@equinor/fusion-framework-react-router/interop';
2+
import type { RouteObject } from '@equinor/fusion-framework-react-router';
23
import { useRouter } from '@equinor/fusion-framework-react-app/navigation';
34

45
import { Home, Profile, Root, Todo } from './pages';
@@ -24,7 +25,8 @@ const routes: RouteObject[] = [
2425
},
2526
];
2627

27-
export default function () {
28-
const router = useRouter(routes as any[]);
29-
return <RouterProvider router={router as any} />;
28+
/** Renders the application's route tree via the Fusion navigation module. */
29+
export default function Router() {
30+
const router = useRouter(routes);
31+
return <RouterProvider router={router} />;
3032
}

cookbooks/app-react-state-replication/src/components/SyncEvents/SyncEventList.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Typography } from '@equinor/eds-core-react';
22

3-
import type { SyncEvent } from '../../modules/app-state-with-replication';
4-
53
import { SyncStatusIndicator } from './SyncStatusIndicator';
64
import { useSyncEvents } from './useSyncEvents';
75

@@ -28,7 +26,7 @@ export const SyncEventList: React.FC<SyncEventListProps> = ({
2826
.reverse()
2927
.map((event, index) => (
3028
<div
31-
key={`${event.timestamp}-${index}`}
29+
key={event.id}
3230
style={{
3331
display: 'flex',
3432
alignItems: 'center',

cookbooks/app-react-state-replication/src/components/Todo/TodoListManager.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ export const TodoListManager = () => {
6868
items: prev.items
6969
// Update only the selected item while preserving the list order.
7070
.map((item) =>
71-
item.id === id
72-
? { ...item, completed: !item.completed, updatedAt: new Date().toISOString() }
73-
: item,
74-
),
71+
item.id === id
72+
? { ...item, completed: !item.completed, updatedAt: new Date().toISOString() }
73+
: item,
74+
),
7575
lastModified: new Date().toISOString(),
7676
};
7777
});

cookbooks/app-react-state-replication/src/modules/app-state-with-replication/ObserveSync.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ export function ObserveSync<T extends {}>(
3737

3838
// Register every replication callback so consumers receive a complete event history.
3939
for (const [key, handler] of Object.entries(handlers)) {
40-
// @ts-ignore
40+
// @ts-expect-error
4141
sync.on(key, handler);
4242
}
4343

4444
return () => {
4545
// Remove every callback when the observable subscription is disposed.
4646
for (const [key, handler] of Object.entries(handlers)) {
47-
// @ts-ignore
47+
// @ts-expect-error
4848
sync.off(key, handler);
4949
}
5050
};

cookbooks/app-react-state-replication/src/modules/app-state-with-replication/enable-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AnyModule, IModulesConfigurator } from '@equinor/fusion-framework-module';
1+
import type { AnyModule } from '@equinor/fusion-framework-module';
22
import type { IAppConfigurator } from '@equinor/fusion-framework-react-app';
33

44
import type { StateWithReplicaConfigurator } from './configurator';

cookbooks/app-react-state-replication/src/modules/app-state-with-replication/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type SyncEvent<Content extends {} = {}> = {
1+
export type SyncEvent<Content extends object = object> = {
22
id: string;
33
type: 'change' | 'complete' | 'error' | 'denied' | 'paused' | 'active';
44
info?: PouchDB.Replication.SyncResult<Content>;

cookbooks/app-react-state-replication/src/pages/Root.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Link, Outlet, useLocation } from 'react-router-dom';
1+
import { Link, Outlet, useLocation } from '@equinor/fusion-framework-react-router';
22

33
import { SyncStatusMonitor } from '../components/SyncEvents/SyncStatusMonitor';
44

cookbooks/app-react-state-replication/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"jsx": "react-jsx",
77
"baseUrl": "./src"
88
},
9-
"references": [{ "path": "../../packages/modules/state" }],
9+
"references": [
10+
{ "path": "../../packages/modules/state" },
11+
{ "path": "../../packages/react/router" }
12+
],
1013
"include": ["src/**/*"],
1114
"exclude": ["node_modules", "dist"]
1215
}

0 commit comments

Comments
 (0)