Skip to content

Commit 8118d54

Browse files
cursoragentn3ps
andcommitted
fix: create router per mount for test isolation
Move createHashRouter() from module level into a createRouter() factory called in the class constructor. Each Index mount gets a fresh router instance, preventing stale location state from leaking between integration tests. Co-authored-by: Francis Nepomuceno <n3ps@users.noreply.github.com>
1 parent 79dc668 commit 8118d54

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

ui/pages/index.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,25 @@ function AppProviders() {
5757
);
5858
}
5959

60-
const router = createHashRouter([
61-
{
62-
element: <AppProviders />,
63-
children: [
64-
{
65-
element: <Routes />,
66-
children: routeConfig,
67-
},
68-
],
69-
},
70-
]);
60+
function createRouter() {
61+
return createHashRouter([
62+
{
63+
element: <AppProviders />,
64+
children: [
65+
{
66+
element: <Routes />,
67+
children: routeConfig,
68+
},
69+
],
70+
},
71+
]);
72+
}
7173

7274
class Index extends PureComponent {
7375
state = {};
7476

77+
router = createRouter();
78+
7579
static getDerivedStateFromError(error) {
7680
return { error };
7781
}
@@ -102,7 +106,7 @@ class Index extends PureComponent {
102106

103107
return (
104108
<Provider store={store}>
105-
<RouterProvider router={router} />
109+
<RouterProvider router={this.router} />
106110
</Provider>
107111
);
108112
}

0 commit comments

Comments
 (0)