Skip to content

Commit 4c257a4

Browse files
committed
fix: react 19 migration fixes and enhancements Refs: KER-571
1 parent d5eefcd commit 4c257a4

34 files changed

Lines changed: 135 additions & 122 deletions

src/App.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
cookieBotRemoveListeners,
2222
} from './utils/cookiebotUtils';
2323
import useAuthHook from './hooks/useAuth';
24+
import useLanguageFromUrl from './hooks/useLanguageFromUrl';
2425
import { setOidcUser } from './actions';
2526
import getUser from './selectors/user';
2627
import enrichUserData from './actions/user';
@@ -40,6 +41,8 @@ function App({ isHighContrast, history, ...props }) {
4041
const location = useLocation();
4142
const { locale } = useIntl();
4243

44+
useLanguageFromUrl(onChangeLanguage);
45+
4346
const { authenticated, user: oidcUser, logout } = useAuthHook();
4447
const { getStoredApiTokens } = useApiTokens();
4548

src/components/CommentFormMap/CommentFormMap.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react';
1+
import { useEffect } from 'react';
22
import PropTypes from 'prop-types';
33
import { MapContainer, TileLayer, FeatureGroup } from 'react-leaflet';
44
import Leaflet from 'leaflet';

src/components/HashScroll.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { useEffect } from 'react';
2+
import { useLocation } from 'react-router-dom';
3+
4+
const HashScroll = () => {
5+
const { hash } = useLocation();
6+
7+
useEffect(() => {
8+
if (!hash) return;
9+
const id = hash.slice(1);
10+
const el = document.getElementById(id);
11+
if (el) {
12+
el.scrollIntoView({ behavior: 'smooth' });
13+
}
14+
}, [hash]);
15+
16+
return null;
17+
};
18+
19+
export default HashScroll;

src/components/Hearing/Comment/index.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ const Comment = ({
160160

161161
const onCopyURL = () => {
162162
// Build absolute URL for comment
163-
const commentUrl = `${window.location.origin}${window.location.pathname}#comment-${data.id}`;
163+
const commentUrl = `${globalThis.window.location.origin}${globalThis.window.location.pathname}#comment-${data.id}`;
164164
navigator.clipboard.writeText(commentUrl);
165165
// TODO: Add translations
166166
dispatch(
@@ -227,7 +227,7 @@ const Comment = ({
227227
const handlePostReply = (comment) => {
228228
let commentData = { ...comment };
229229

230-
if (onPostReply && onPostReply instanceof Function) {
230+
if (onPostReply) {
231231
if (isReply && parentComponentId) {
232232
commentData = { ...commentData, comment: parentComponentId };
233233
} else {
@@ -765,7 +765,7 @@ Comment.propTypes = {
765765
questions: PropTypes.array,
766766
section: PropTypes.object,
767767
user: PropTypes.object,
768-
showReplies: PropTypes,
768+
showReplies: PropTypes.bool,
769769
};
770770

771771
export default Comment;

src/components/Hearing/CommentList/index.jsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* eslint-disable sonarjs/pseudo-random */
2-
/* eslint-disable sonarjs/no-uniq-key */
3-
import React, { useState, useEffect, useRef } from 'react';
1+
import { useState, useEffect, useRef } from 'react';
42
import PropTypes from 'prop-types';
53
import { FormattedMessage } from 'react-intl';
64

@@ -28,7 +26,7 @@ function CommentList({
2826
onPostFlag,
2927
}) {
3028
const [commentShowReplies, setCommentShowReplies] = useState(() =>
31-
[...Array(comments.length)].map(() => false)
29+
[new Array(comments.length)].map(() => false)
3230
);
3331

3432
const prevCommentsRef = useRef(comments);
@@ -82,7 +80,7 @@ function CommentList({
8280
data={comment}
8381
defaultNickname={defaultNickname}
8482
hearingId={hearingId}
85-
key={comment.id + Math.random()}
83+
key={comment.id}
8684
jumpTo={jumpTo}
8785
language={language}
8886
nicknamePlaceholder={nicknamePlaceholder}

src/components/Hearing/Section/SectionImage.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
2-
import React, { useState } from 'react';
2+
import { useEffect, useState } from 'react';
33
import PropTypes from 'prop-types';
44
import Lightbox from 'yet-another-react-lightbox';
55

66
const SectionImageComponent = ({ image, altText, caption, title }) => {
77
const [open, setOpen] = useState(false);
88

9+
useEffect(() => {
10+
return () => {
11+
document.body.classList.add('nav-fixed');
12+
};
13+
}, []);
14+
915
if (!image) return null;
1016

1117
const alt = altText || caption || title || '';

src/components/HearingList/HearingsSearch/HearingsSearch.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo, useState } from 'react';
1+
import { useMemo, useState } from 'react';
22
import PropTypes from 'prop-types';
33
import { FormattedMessage } from 'react-intl';
44
import { isEmpty } from 'lodash';

src/components/InternalLink.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import classNames from 'classnames';
32
import PropTypes from 'prop-types';
43

@@ -12,6 +11,10 @@ function InternalLink({ children, destinationId, srOnly = false, className }) {
1211
const top =
1312
target.getBoundingClientRect().top + window.scrollY - SCROLL_OFFSET;
1413
window.scrollTo({ top, behavior: 'smooth' });
14+
if (!target.hasAttribute('tabIndex')) {
15+
target.setAttribute('tabIndex', '-1');
16+
}
17+
target.focus({ preventScroll: true });
1518
}
1619
};
1720

src/components/PluginContent.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Created by riku on 11.5.2017.
44
*/
5-
import React, { useEffect, useRef } from 'react';
5+
import { useEffect, useRef } from 'react';
66
import PropTypes from 'prop-types';
77
import { get } from 'lodash';
88

src/components/RichTextEditor/Iframe/IframeCopyPasteField.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import { useState } from 'react';
22
import PropTypes from 'prop-types';
33

44
import getMessage from '../../../utils/getMessage';

0 commit comments

Comments
 (0)