Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#10158: set HTML document language once per mount/update
Browse files Browse the repository at this point in the history
now with eslint fixes
fkellner authored Sep 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent fed18c5 commit b05cd29
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions web/client/components/I18N/Localized.jsx
Original file line number Diff line number Diff line change
@@ -30,6 +30,22 @@ class Localized extends React.Component {
};
}

componentDidMount() {
this.updateDocumentLangAttribute();
}

componentDidUpdate(prevProps) {
if (this.props.locale !== prevProps.locale) {
this.updateDocumentLangAttribute();
}
}

updateDocumentLangAttribute() {
if (document?.documentElement) {
document.documentElement.setAttribute("lang", this.props.locale);

Check failure on line 45 in web/client/components/I18N/Localized.jsx

GitHub Actions / test-front-end

updateDocumentLangAttribute must be placed after render
}
}

render() {
let { children } = this.props;

@@ -50,22 +66,6 @@ class Localized extends React.Component {
return null;
}

componentDidMount() {
this.updateDocumentLangAttribute();
}

componentDidUpdate(prevProps) {
if (this.props.locale !== prevProps.locale) {
this.updateDocumentLangAttribute();
}
}

updateDocumentLangAttribute() {
if (document?.documentElement) {
document.documentElement.setAttribute("lang", this.props.locale);
}
}

flattenMessages = (messages, prefix = '') => {
return Object.keys(messages).reduce((previous, current) => {
return typeof messages[current] === 'string' ? {

0 comments on commit b05cd29

Please sign in to comment.