Skip to content

Commit

Permalink
STCOR-841 enable StrictMode by default (#1461)
Browse files Browse the repository at this point in the history
* Enable `<StrictMode>` by default, allowing it to be turned off via the
`stripes.config.js` prop `config.ignoreStrictMode: true`.
* `useNamespace`: Do not manipulate the return value of the hook during 
  render; that will cause multiple renders to return different values.

Refs STCOR-841
  • Loading branch information
zburke authored Apr 30, 2024
1 parent ab2cdf1 commit 3bb2e99
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Remove tag-based selectors from Login, ResetPassword, Forgot UserName/Password form CSS. Refs STCOR-712.
* Provide `useUserTenantPermissions` hook. Refs STCOR-830.
* Load DayJS locale data as part of `loginServices`. STCOR-771.
* Turn on `<StrictMode>`; ignore it with `stripes.config.js` `disableStrictMode: true`. Refs STCOR-841.

## 10.1.0 IN PROGRESS

Expand Down
34 changes: 24 additions & 10 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react';
import React, { Component, StrictMode } from 'react';
import PropTypes from 'prop-types';
import { okapi as okapiConfig, config } from 'stripes-config';
import merge from 'lodash/merge';
Expand All @@ -12,6 +12,18 @@ import { destroyStore } from './mainActions';

import Root from './components/Root';

const StrictWrapper = ({ children }) => {
if (config.disableStrictMode) {
return children;
}

return <StrictMode>{children}</StrictMode>;
};

StrictWrapper.propTypes = {
children: PropTypes.node.isRequired,
};

export default class StripesCore extends Component {
static propTypes = {
history: PropTypes.object,
Expand Down Expand Up @@ -42,15 +54,17 @@ export default class StripesCore extends Component {
const { initialState, ...props } = this.props;

return (
<Root
store={this.store}
epics={this.epics}
logger={this.logger}
config={config}
actionNames={this.actionNames}
disableAuth={(config && config.disableAuth) || false}
{...props}
/>
<StrictWrapper>
<Root
store={this.store}
epics={this.epics}
logger={this.logger}
config={config}
actionNames={this.actionNames}
disableAuth={(config && config.disableAuth) || false}
{...props}
/>
</StrictWrapper>
);
}
}
4 changes: 2 additions & 2 deletions src/components/Namespace/useNamespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import { delimiters } from '../../constants';

const useNamespace = (options = {}) => {
const moduleHierarchy = useModuleHierarchy();
const getNamespace = (opts) => {
const getNamespace = (opts = {}) => {
const { ignoreParents, key } = opts;
const { NAMESPACE_DELIMITER } = delimiters;

let namespace = ignoreParents ? moduleHierarchy.pop() : moduleHierarchy.join(NAMESPACE_DELIMITER);
let namespace = ignoreParents ? moduleHierarchy[moduleHierarchy.length - 1] : moduleHierarchy.join(NAMESPACE_DELIMITER);

if (key) {
namespace += `${NAMESPACE_DELIMITER}${key}`;
Expand Down

0 comments on commit 3bb2e99

Please sign in to comment.