Skip to content

Commit 0638efe

Browse files
authored
Fix vite HMR whith multi exports in jsx or tsx files (#74)
Signed-off-by: achour94 <berrahmaachour@gmail.com>
1 parent 418902b commit 0638efe

File tree

8 files changed

+91
-65
lines changed

8 files changed

+91
-65
lines changed

.eslintrc.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
// node_modules is implicitly always ignored
66
"build"
77
],
8+
"plugins": ["react-refresh"],
89
"rules": {
910
"prettier/prettier": "warn",
10-
"curly": "error"
11+
"curly": "error",
12+
"react-refresh/only-export-components": [
13+
"error",
14+
{ "allowConstantExport": true }
15+
]
1116
}
1217
}

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"eslint-plugin-prettier": "^4.2.1",
8282
"eslint-plugin-react": "^7.37.4",
8383
"eslint-plugin-react-hooks": "^4.6.2",
84+
"eslint-plugin-react-refresh": "^0.4.19",
8485
"identity-obj-proxy": "^3.0.0",
8586
"jest": "^29.7.0",
8687
"jest-environment-jsdom": "^29.7.0",

src/components/App/app-top-bar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import GridAdminLogoLight from '../../images/GridAdmin_logo_light.svg?react';
2727
import GridAdminLogoDark from '../../images/GridAdmin_logo_dark.svg?react';
2828
import AppPackage from '../../../package.json';
2929
import { AppState } from '../../redux/reducer';
30-
import { MainPaths } from '../../routes';
3130
import { AppDispatch } from '../../redux/store';
31+
import { MainPaths } from '../../routes/utils';
3232

3333
const tabs = new Map<MainPaths, ReactElement>([
3434
[

src/components/App/app.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { store } from '../../redux/store';
1717
import { createTheme, StyledEngineProvider, ThemeProvider } from '@mui/material/styles';
1818
import { SnackbarProvider } from '@gridsuite/commons-ui';
1919
import { CssBaseline } from '@mui/material';
20-
import { appRoutes } from '../../routes';
20+
import { appRoutes } from '../../routes/utils';
2121

2222
let container: HTMLElement | null = null;
2323

src/pages/profiles/modification/profile-modification-dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { UserAdminSrv, UserProfile } from '../../../services';
2424
import { UUID } from 'crypto';
2525

2626
// TODO remove FetchStatus when exported in commons-ui (available soon)
27-
export enum FetchStatus {
27+
enum FetchStatus {
2828
IDLE = 'IDLE',
2929
FETCHING = 'FETCHING',
3030
FETCH_SUCCESS = 'FETCH_SUCCESS',

src/routes/router.tsx

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
*/
77

88
import { FunctionComponent, PropsWithChildren, useEffect, useMemo, useState } from 'react';
9-
import { FormattedMessage } from 'react-intl';
10-
import { AuthenticationRouter, getPreLoginPath, initializeAuthenticationProd } from '@gridsuite/commons-ui';
9+
import { AuthenticationRouter, initializeAuthenticationProd } from '@gridsuite/commons-ui';
1110
import {
1211
createBrowserRouter,
13-
Navigate,
1412
Outlet,
1513
RouteObject,
1614
RouterProvider,
@@ -22,67 +20,10 @@ import { useDispatch, useSelector } from 'react-redux';
2220
import { AppState } from '../redux/reducer';
2321
import { AppsMetadataSrv, UserAdminSrv } from '../services';
2422
import { App } from '../components/App';
25-
import { Profiles, Users, Groups } from '../pages';
26-
import ErrorPage from './ErrorPage';
2723
import { updateUserManagerDestructured } from '../redux/actions';
28-
import HomePage from './HomePage';
2924
import { getErrorMessage } from '../utils/error';
3025
import { AppDispatch } from '../redux/store';
31-
32-
export enum MainPaths {
33-
users = 'users',
34-
profiles = 'profiles',
35-
groups = 'groups',
36-
}
37-
38-
export function appRoutes(): RouteObject[] {
39-
return [
40-
{
41-
path: '/',
42-
errorElement: <ErrorPage />,
43-
children: [
44-
{
45-
index: true,
46-
element: <HomePage />,
47-
},
48-
{
49-
path: `/${MainPaths.users}`,
50-
element: <Users />,
51-
handle: {
52-
appBar_tab: MainPaths.users,
53-
},
54-
},
55-
{
56-
path: `/${MainPaths.profiles}`,
57-
element: <Profiles />,
58-
handle: {
59-
appBar_tab: MainPaths.profiles,
60-
},
61-
},
62-
{
63-
path: `/${MainPaths.groups}`,
64-
element: <Groups />,
65-
handle: {
66-
appBar_tab: MainPaths.groups,
67-
},
68-
},
69-
],
70-
},
71-
{
72-
path: '/sign-in-callback',
73-
element: <Navigate replace to={getPreLoginPath() || '/'} />,
74-
},
75-
{
76-
path: '/logout-callback',
77-
element: <FormattedMessage tagName="h1" id="logoutFailed" />,
78-
},
79-
{
80-
path: '*',
81-
element: <FormattedMessage tagName="h1" id="pageNotFound" />,
82-
errorElement: <ErrorPage />,
83-
},
84-
];
85-
}
26+
import { appRoutes } from './utils';
8627

8728
const AuthRouter: FunctionComponent<{
8829
userManager: Parameters<typeof AuthenticationRouter>[0]['userManager'];

src/routes/utils.tsx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
import { Navigate, RouteObject } from 'react-router-dom';
9+
import { Profiles, Users, Groups } from '../pages';
10+
import ErrorPage from './ErrorPage';
11+
import HomePage from './HomePage';
12+
import { getPreLoginPath } from '@gridsuite/commons-ui';
13+
import { FormattedMessage } from 'react-intl';
14+
15+
export enum MainPaths {
16+
users = 'users',
17+
profiles = 'profiles',
18+
groups = 'groups',
19+
}
20+
21+
export function appRoutes(): RouteObject[] {
22+
return [
23+
{
24+
path: '/',
25+
errorElement: <ErrorPage />,
26+
children: [
27+
{
28+
index: true,
29+
element: <HomePage />,
30+
},
31+
{
32+
path: `/${MainPaths.users}`,
33+
element: <Users />,
34+
handle: {
35+
appBar_tab: MainPaths.users,
36+
},
37+
},
38+
{
39+
path: `/${MainPaths.profiles}`,
40+
element: <Profiles />,
41+
handle: {
42+
appBar_tab: MainPaths.profiles,
43+
},
44+
},
45+
{
46+
path: `/${MainPaths.groups}`,
47+
element: <Groups />,
48+
handle: {
49+
appBar_tab: MainPaths.groups,
50+
},
51+
},
52+
],
53+
},
54+
{
55+
path: '/sign-in-callback',
56+
element: <Navigate replace to={getPreLoginPath() || '/'} />,
57+
},
58+
{
59+
path: '/logout-callback',
60+
element: <FormattedMessage tagName="h1" id="logoutFailed" />,
61+
},
62+
{
63+
path: '*',
64+
element: <FormattedMessage tagName="h1" id="pageNotFound" />,
65+
errorElement: <ErrorPage />,
66+
},
67+
];
68+
}

0 commit comments

Comments
 (0)