From b9026e7fe1cb77b3be82636ce47d40c12f107766 Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 21 Mar 2025 12:48:54 +0000 Subject: [PATCH 01/12] feat: ConditionalLoad Added new Component "ConditionalLoad" which can work analogously to Pluggable This should be considered for stripes-core or otherwise --- .../ConditionalLoad/ConditionalLoad.js | 48 +++++++++++ .../ConditionalLoad/ConditionalLoad.test.js | 86 +++++++++++++++++++ .../TestComponent/Extra/Extra.js | 1 + .../TestComponent/Extra/index.js | 1 + .../TestComponent/TestComponent.js | 1 + .../TestComponent/TestComponent.test.js | 26 ++++++ .../ConditionalLoad/TestComponent/index.js | 1 + 7 files changed, 164 insertions(+) create mode 100644 src/components/ConditionalLoad/ConditionalLoad.js create mode 100644 src/components/ConditionalLoad/ConditionalLoad.test.js create mode 100644 src/components/ConditionalLoad/TestComponent/Extra/Extra.js create mode 100644 src/components/ConditionalLoad/TestComponent/Extra/index.js create mode 100644 src/components/ConditionalLoad/TestComponent/TestComponent.js create mode 100644 src/components/ConditionalLoad/TestComponent/TestComponent.test.js create mode 100644 src/components/ConditionalLoad/TestComponent/index.js diff --git a/src/components/ConditionalLoad/ConditionalLoad.js b/src/components/ConditionalLoad/ConditionalLoad.js new file mode 100644 index 000000000..ad9719b42 --- /dev/null +++ b/src/components/ConditionalLoad/ConditionalLoad.js @@ -0,0 +1,48 @@ +import { lazy, Suspense } from 'react'; +import PropTypes from 'prop-types'; + +import { Loading } from '@folio/stripes/components'; + +// This effectively becomes analogous to Pluggable, except happening at the dependency load stage -- should almost certainly belong to stripes-core +// This protects feature sets such as NumberGenerator, brought in as peer dependencies and therefore present in all platform-core builds, but not necessarily +// in all builds with Users present. +const ConditionalLoad = ({ + children, + FallbackComponent = () =>
Feature not available
, + importString, + importSuccess = m => m, + suppressConsoleErrors = false, + importError = err => { + if (!suppressConsoleErrors) { + console.error('Cannot import, using fallback component', err); + } + return Promise.resolve({ default: FallbackComponent }); + }, +}) => { + const Component = lazy(() => { + // Both try/catch and promise catch are necessary here for reasons I don't quite understand + try { + return import(importString) + .then(importSuccess) + .catch(importError); + } catch (e) { + return importError(e); + } + }); + + + return ( + }> + {children({ Component })} + + ); +}; + +ConditionalLoad.propTypes = { + children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]).isRequired, + importString: PropTypes.string.isRequired, + importSuccess: PropTypes.func, + importError: PropTypes.func, +}; + +export default ConditionalLoad; diff --git a/src/components/ConditionalLoad/ConditionalLoad.test.js b/src/components/ConditionalLoad/ConditionalLoad.test.js new file mode 100644 index 000000000..23b86c0f3 --- /dev/null +++ b/src/components/ConditionalLoad/ConditionalLoad.test.js @@ -0,0 +1,86 @@ +import { act, render, waitFor } from '@folio/jest-config-stripes/testing-library/react'; +import ConditionalLoad from './ConditionalLoad'; + +let component; +const testConditionalLoad = (props) => async () => { + await act(() => { + component = render( + + {({ Component }) => } + + ); + }); +}; + +describe('ConditionalLoad', () => { + describe('Component renders when import succeeds', () => { + beforeEach(testConditionalLoad({ + importString: './TestComponent' + })); + + test('renders Test Component', async () => { + const { getByText } = component; + await waitFor(() => { + expect(getByText('Test Component')).toBeInTheDocument(); + }); + }); + }); + + describe('Can get component from module import', () => { + beforeEach(testConditionalLoad({ + importString: './TestComponent/Extra', + importSuccess: m => ({ default: m.Extra }) + })); + + test('renders Extra Component', async () => { + const { getByText } = component; + await waitFor(() => { + expect(getByText('Extra Component')).toBeInTheDocument(); + }); + }); + }); + + describe('Fallback component renders when import fails', () => { + beforeEach(testConditionalLoad({ + importString: './MadeUpComponent' + })); + + test('renders Test Component', async () => { + const { getByText } = component; + await waitFor(() => { + expect(getByText('Feature not available')).toBeInTheDocument(); + }); + }); + }); + + describe('Fallback component is configurable', () => { + beforeEach(testConditionalLoad({ + importString: './MadeUpComponent', + FallbackComponent: () =>
Fallback Component
+ })); + + test('renders Test Component', async () => { + const { getByText } = component; + await waitFor(() => { + expect(getByText('Fallback Component')).toBeInTheDocument(); + }); + }); + }); + + describe('importError is directly configurable', () => { + beforeEach(testConditionalLoad({ + importString: './MadeUpComponent', + importError: (err) => Promise.resolve(({ default: () =>
{err.message}
})) + })); + + test('renders Test Component', async () => { + const { getByText } = component; + await waitFor(() => { + expect(getByText('Cannot find module \'./MadeUpComponent\' from \'src/components/ConditionalLoad/ConditionalLoad.js\'')).toBeInTheDocument(); + }); + }); + }); +}); diff --git a/src/components/ConditionalLoad/TestComponent/Extra/Extra.js b/src/components/ConditionalLoad/TestComponent/Extra/Extra.js new file mode 100644 index 000000000..23c77d860 --- /dev/null +++ b/src/components/ConditionalLoad/TestComponent/Extra/Extra.js @@ -0,0 +1 @@ +export default () => (
Extra Component
); diff --git a/src/components/ConditionalLoad/TestComponent/Extra/index.js b/src/components/ConditionalLoad/TestComponent/Extra/index.js new file mode 100644 index 000000000..19d40023e --- /dev/null +++ b/src/components/ConditionalLoad/TestComponent/Extra/index.js @@ -0,0 +1 @@ +export { default as Extra } from './Extra'; diff --git a/src/components/ConditionalLoad/TestComponent/TestComponent.js b/src/components/ConditionalLoad/TestComponent/TestComponent.js new file mode 100644 index 000000000..69158edd7 --- /dev/null +++ b/src/components/ConditionalLoad/TestComponent/TestComponent.js @@ -0,0 +1 @@ +export default () => (
Test Component
); diff --git a/src/components/ConditionalLoad/TestComponent/TestComponent.test.js b/src/components/ConditionalLoad/TestComponent/TestComponent.test.js new file mode 100644 index 000000000..74b1f1e59 --- /dev/null +++ b/src/components/ConditionalLoad/TestComponent/TestComponent.test.js @@ -0,0 +1,26 @@ +import { render } from '@folio/jest-config-stripes/testing-library/react'; +import TestComponent from './TestComponent'; +import { Extra } from './Extra'; + +describe('TestComponent', () => { + let component; + describe('', () => { + beforeEach(() => { + component = render(); + }); + test('should render test component', () => { + const { getByText } = component; + expect(getByText('Test Component')).toBeInTheDocument(); + }); + }); + + describe('', () => { + beforeEach(() => { + component = render(); + }); + test('should render extra component', () => { + const { getByText } = component; + expect(getByText('Extra Component')).toBeInTheDocument(); + }); + }); +}); diff --git a/src/components/ConditionalLoad/TestComponent/index.js b/src/components/ConditionalLoad/TestComponent/index.js new file mode 100644 index 000000000..3403ebc24 --- /dev/null +++ b/src/components/ConditionalLoad/TestComponent/index.js @@ -0,0 +1 @@ +export { default } from './TestComponent'; From ee50523c28789eec4ece29631d2f41e1c0e74c3c Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 21 Mar 2025 12:51:09 +0000 Subject: [PATCH 02/12] feat: ConditionalLoad ui-service-interaction NumberGeneratorModalButton --- .../EditSections/EditUserInfo/EditUserInfo.js | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/components/EditSections/EditUserInfo/EditUserInfo.js b/src/components/EditSections/EditUserInfo/EditUserInfo.js index d3f9b33fd..d06111dfe 100644 --- a/src/components/EditSections/EditUserInfo/EditUserInfo.js +++ b/src/components/EditSections/EditUserInfo/EditUserInfo.js @@ -6,7 +6,6 @@ import { Field } from 'react-final-form'; import { OnChange } from 'react-final-form-listeners'; import { FormattedMessage, injectIntl } from 'react-intl'; -import { NumberGeneratorModalButton } from '@folio/service-interaction'; import { Button, Select, @@ -28,6 +27,8 @@ import validateMinDate from '../../validators/validateMinDate'; import { ChangeUserTypeModal, EditUserProfilePicture } from './components'; +import ConditionalLoad from '../../ConditionalLoad/ConditionalLoad'; + import css from './EditUserInfo.css'; import { validateLength } from '../../validators/validateLength'; import { @@ -388,18 +389,30 @@ class EditUserInfo extends React.Component { fullWidth disabled={disabled || isBarcodeDisabled} /> - {showNumberGeneratorForBarcode && - } - callback={(generated) => form.change('barcode', generated)} - id="userbarcode" - generateButtonLabel={} - generator={BARCODE_GENERATOR_CODE} - modalProps={{ - label: - }} - /> - } + ({ default: m.NumberGeneratorModalButton })} + > + {({ Component: NumberGeneratorModalButton }) => { + if (showNumberGeneratorForBarcode) { + return ( + } + callback={(generated) => form.change('barcode', generated)} + id="userbarcode" + generateButtonLabel={} + generator={BARCODE_GENERATOR_CODE} + modalProps={{ + label: + }} + /> + ); + } + + return null; + } + }) + From b05d6bc32d88360966504014695817be5d2a228e Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 21 Mar 2025 13:07:50 +0000 Subject: [PATCH 03/12] docs: Added to CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca7edfe25..11e0b6478 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 13.0.0 IN PROGRESS * Collect coverage from unit tests. Refs UIU-3356. * Use number generator for barcode. Refs UIU-2729. + * Implemented optional loading of Number generator. Refs UIU-2729 ## [12.1.0](https://github.com/folio-org/ui-users/tree/v12.1.0) (2025-03-18) [Full Changelog](https://github.com/folio-org/ui-users/compare/v12.0.0...v12.1.0) From d31e667a46b6a1525c2c8929253f3d0cf8323db8 Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 21 Mar 2025 13:24:44 +0000 Subject: [PATCH 04/12] chore: Linting, proptypes and superfluous sonar line --- src/components/ConditionalLoad/ConditionalLoad.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/ConditionalLoad/ConditionalLoad.js b/src/components/ConditionalLoad/ConditionalLoad.js index ad9719b42..b96be2edf 100644 --- a/src/components/ConditionalLoad/ConditionalLoad.js +++ b/src/components/ConditionalLoad/ConditionalLoad.js @@ -20,8 +20,8 @@ const ConditionalLoad = ({ }, }) => { const Component = lazy(() => { - // Both try/catch and promise catch are necessary here for reasons I don't quite understand - try { + // Both try/catch and promise catch are necessary here for reasons I don't quite understand, but it triggers in sonar so I'm disabling for now + try { // NOSONAR return import(importString) .then(importSuccess) .catch(importError); @@ -40,9 +40,11 @@ const ConditionalLoad = ({ ConditionalLoad.propTypes = { children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]).isRequired, + FallbackComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.node]), importString: PropTypes.string.isRequired, importSuccess: PropTypes.func, importError: PropTypes.func, + suppressConsoleErrors: PropTypes.bool.isRequired, }; export default ConditionalLoad; From bdda461dce0cd4e1f93d2a45aa54d665de7de585 Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 21 Mar 2025 15:24:47 +0000 Subject: [PATCH 05/12] fix: Webpack cannot do fully dynamic imports. This fix allows us to give the possible options ahead of time so webpack knows what it may need to bundle. I don't love this fix tbh --- src/components/ConditionalLoad/ConditionalLoad.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/ConditionalLoad/ConditionalLoad.js b/src/components/ConditionalLoad/ConditionalLoad.js index b96be2edf..17765ad3b 100644 --- a/src/components/ConditionalLoad/ConditionalLoad.js +++ b/src/components/ConditionalLoad/ConditionalLoad.js @@ -19,10 +19,15 @@ const ConditionalLoad = ({ return Promise.resolve({ default: FallbackComponent }); }, }) => { + const dynamicModuleMap = { + '@folio/stripes/components': () => import('@folio/stripes/components'), + '@folio/service-interaction': () => import('@folio/service-interaction'), + }; + const Component = lazy(() => { // Both try/catch and promise catch are necessary here for reasons I don't quite understand, but it triggers in sonar so I'm disabling for now try { // NOSONAR - return import(importString) + return dynamicModuleMap[importString]() .then(importSuccess) .catch(importError); } catch (e) { From 17b6f1cc1f784d0d65277ff4141211fbd6d8940f Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 21 Mar 2025 15:33:50 +0000 Subject: [PATCH 06/12] feat: Add an isLocal so it can work on purely dynamic local imports as before... there may be benefits to that work outside of dynamic webpack loading --- src/components/ConditionalLoad/ConditionalLoad.js | 11 ++++++++++- .../ConditionalLoad/ConditionalLoad.test.js | 15 ++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/components/ConditionalLoad/ConditionalLoad.js b/src/components/ConditionalLoad/ConditionalLoad.js index 17765ad3b..4e4a26bec 100644 --- a/src/components/ConditionalLoad/ConditionalLoad.js +++ b/src/components/ConditionalLoad/ConditionalLoad.js @@ -18,16 +18,25 @@ const ConditionalLoad = ({ } return Promise.resolve({ default: FallbackComponent }); }, + isLocal = false, }) => { const dynamicModuleMap = { '@folio/stripes/components': () => import('@folio/stripes/components'), '@folio/service-interaction': () => import('@folio/service-interaction'), }; + const Component = lazy(() => { + let importFunc; + if (isLocal) { + importFunc = () => import(importString); + } else { + importFunc = () => dynamicModuleMap[importString]; + } + // Both try/catch and promise catch are necessary here for reasons I don't quite understand, but it triggers in sonar so I'm disabling for now try { // NOSONAR - return dynamicModuleMap[importString]() + return importFunc() .then(importSuccess) .catch(importError); } catch (e) { diff --git a/src/components/ConditionalLoad/ConditionalLoad.test.js b/src/components/ConditionalLoad/ConditionalLoad.test.js index 23b86c0f3..b3b2372af 100644 --- a/src/components/ConditionalLoad/ConditionalLoad.test.js +++ b/src/components/ConditionalLoad/ConditionalLoad.test.js @@ -18,7 +18,8 @@ const testConditionalLoad = (props) => async () => { describe('ConditionalLoad', () => { describe('Component renders when import succeeds', () => { beforeEach(testConditionalLoad({ - importString: './TestComponent' + importString: './TestComponent', + isLocal: true })); test('renders Test Component', async () => { @@ -32,7 +33,8 @@ describe('ConditionalLoad', () => { describe('Can get component from module import', () => { beforeEach(testConditionalLoad({ importString: './TestComponent/Extra', - importSuccess: m => ({ default: m.Extra }) + importSuccess: m => ({ default: m.Extra }), + isLocal: true })); test('renders Extra Component', async () => { @@ -45,7 +47,8 @@ describe('ConditionalLoad', () => { describe('Fallback component renders when import fails', () => { beforeEach(testConditionalLoad({ - importString: './MadeUpComponent' + importString: './MadeUpComponent', + isLocal: true })); test('renders Test Component', async () => { @@ -59,7 +62,8 @@ describe('ConditionalLoad', () => { describe('Fallback component is configurable', () => { beforeEach(testConditionalLoad({ importString: './MadeUpComponent', - FallbackComponent: () =>
Fallback Component
+ FallbackComponent: () =>
Fallback Component
, + isLocal: true })); test('renders Test Component', async () => { @@ -73,7 +77,8 @@ describe('ConditionalLoad', () => { describe('importError is directly configurable', () => { beforeEach(testConditionalLoad({ importString: './MadeUpComponent', - importError: (err) => Promise.resolve(({ default: () =>
{err.message}
})) + importError: (err) => Promise.resolve(({ default: () =>
{err.message}
})), + isLocal: true })); test('renders Test Component', async () => { From 68e220d4bd34bc74e7f0d5942520a967781a176f Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 21 Mar 2025 15:36:22 +0000 Subject: [PATCH 07/12] chore: small fixes and tweaks --- src/components/ConditionalLoad/ConditionalLoad.js | 2 +- src/components/EditSections/EditUserInfo/EditUserInfo.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/ConditionalLoad/ConditionalLoad.js b/src/components/ConditionalLoad/ConditionalLoad.js index 4e4a26bec..9a8756ba8 100644 --- a/src/components/ConditionalLoad/ConditionalLoad.js +++ b/src/components/ConditionalLoad/ConditionalLoad.js @@ -58,7 +58,7 @@ ConditionalLoad.propTypes = { importString: PropTypes.string.isRequired, importSuccess: PropTypes.func, importError: PropTypes.func, - suppressConsoleErrors: PropTypes.bool.isRequired, + suppressConsoleErrors: PropTypes.bool, }; export default ConditionalLoad; diff --git a/src/components/EditSections/EditUserInfo/EditUserInfo.js b/src/components/EditSections/EditUserInfo/EditUserInfo.js index d06111dfe..260bc38dc 100644 --- a/src/components/EditSections/EditUserInfo/EditUserInfo.js +++ b/src/components/EditSections/EditUserInfo/EditUserInfo.js @@ -408,10 +408,8 @@ class EditUserInfo extends React.Component { /> ); } - return null; - } - }) + }} From d4e89f4c4292cc2f5428fdd0d0b05133a5fa3fba Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 21 Mar 2025 16:07:32 +0000 Subject: [PATCH 08/12] test: Fixed test implementation --- .../EditUserInfo/EditUserInfo.test.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/components/EditSections/EditUserInfo/EditUserInfo.test.js b/src/components/EditSections/EditUserInfo/EditUserInfo.test.js index e33b40350..32341cca3 100644 --- a/src/components/EditSections/EditUserInfo/EditUserInfo.test.js +++ b/src/components/EditSections/EditUserInfo/EditUserInfo.test.js @@ -5,6 +5,8 @@ import { Form } from 'react-final-form'; import '__mock__/stripesComponents.mock'; +import { NumberGeneratorModalButton as MockNGMB } from '@folio/service-interaction'; + import renderWithRouter from 'helpers/renderWithRouter'; import EditUserInfo from './EditUserInfo'; @@ -27,6 +29,20 @@ jest.mock('@folio/service-interaction', () => ({ ), })); +jest.mock('../../ConditionalLoad/ConditionalLoad', () => ({ + children, + importString, + importSuccess +}) => { + const theImport = jest.requireMock(importString); + const Component = importSuccess(theImport).default; // Little bit hacky but it does the job + return ( + <> + {children({ Component })} + + ); +}); + jest.mock('@folio/stripes/components', () => ({ ...jest.requireActual('@folio/stripes/components'), Modal: jest.fn(({ children, label, footer, ...rest }) => { @@ -266,7 +282,6 @@ describe('Render Edit User Information component', () => { ...props, numberGeneratorData: { barcode: NUMBER_GENERATOR_OPTIONS_OFF }, }); - expect(screen.getByRole('textbox', { name: 'ui-users.information.barcode' })).toBeEnabled(); expect(screen.queryByRole('button', { name: 'NumberGeneratorModalButton' })).not.toBeInTheDocument(); }); From 5ab73c20c40baa5dec14087b4502b00ca9ce2e1a Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 21 Mar 2025 16:09:19 +0000 Subject: [PATCH 09/12] chore: Proptypes --- src/components/ConditionalLoad/ConditionalLoad.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/ConditionalLoad/ConditionalLoad.js b/src/components/ConditionalLoad/ConditionalLoad.js index 9a8756ba8..5bfda94ba 100644 --- a/src/components/ConditionalLoad/ConditionalLoad.js +++ b/src/components/ConditionalLoad/ConditionalLoad.js @@ -58,6 +58,7 @@ ConditionalLoad.propTypes = { importString: PropTypes.string.isRequired, importSuccess: PropTypes.func, importError: PropTypes.func, + isLocal: PropTypes.bool, suppressConsoleErrors: PropTypes.bool, }; From a37c05f720646f1b713742749a998999c35803ab Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 21 Mar 2025 16:53:10 +0000 Subject: [PATCH 10/12] fix: Fixed whoopsie with dynamic external import, extra testing --- .../ConditionalLoad/ConditionalLoad.js | 2 +- .../ConditionalLoad/ConditionalLoad.test.js | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/components/ConditionalLoad/ConditionalLoad.js b/src/components/ConditionalLoad/ConditionalLoad.js index 5bfda94ba..70fd03e8e 100644 --- a/src/components/ConditionalLoad/ConditionalLoad.js +++ b/src/components/ConditionalLoad/ConditionalLoad.js @@ -31,7 +31,7 @@ const ConditionalLoad = ({ if (isLocal) { importFunc = () => import(importString); } else { - importFunc = () => dynamicModuleMap[importString]; + importFunc = dynamicModuleMap[importString]; } // Both try/catch and promise catch are necessary here for reasons I don't quite understand, but it triggers in sonar so I'm disabling for now diff --git a/src/components/ConditionalLoad/ConditionalLoad.test.js b/src/components/ConditionalLoad/ConditionalLoad.test.js index b3b2372af..27d271cdc 100644 --- a/src/components/ConditionalLoad/ConditionalLoad.test.js +++ b/src/components/ConditionalLoad/ConditionalLoad.test.js @@ -1,12 +1,19 @@ import { act, render, waitFor } from '@folio/jest-config-stripes/testing-library/react'; import ConditionalLoad from './ConditionalLoad'; +jest.mock('@folio/stripes/components', () => { + return ({ + Test: Promise.resolve({ default: () => <>Testing External }), + Loading: () => <>Loading..., + }); +}); + let component; const testConditionalLoad = (props) => async () => { await act(() => { component = render( {({ Component }) => } @@ -88,4 +95,18 @@ describe('ConditionalLoad', () => { }); }); }); + + describe('external import works as expected', () => { + beforeEach(testConditionalLoad({ + importString: '@folio/stripes/components', + importSuccess: m => m.Test, + })); + + test('renders mocked Test Component', async () => { + const { getByText } = component; + await waitFor(() => { + expect(getByText('Testing External')).toBeInTheDocument(); + }); + }); + }); }); From 868845627644c7146c0e8c427fa6ec421c9a5ba0 Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 21 Mar 2025 16:55:00 +0000 Subject: [PATCH 11/12] test: re-turned off console errors for expected failures during test of ConditionalLoad --- src/components/ConditionalLoad/ConditionalLoad.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ConditionalLoad/ConditionalLoad.test.js b/src/components/ConditionalLoad/ConditionalLoad.test.js index 27d271cdc..805330758 100644 --- a/src/components/ConditionalLoad/ConditionalLoad.test.js +++ b/src/components/ConditionalLoad/ConditionalLoad.test.js @@ -13,7 +13,7 @@ const testConditionalLoad = (props) => async () => { await act(() => { component = render( {({ Component }) => } From 65eb77d619eaf568293b2f657b03997e620c7fab Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 21 Mar 2025 17:02:27 +0000 Subject: [PATCH 12/12] refactor: try/catch seemingly no longer an issue, hooray --- src/components/ConditionalLoad/ConditionalLoad.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/components/ConditionalLoad/ConditionalLoad.js b/src/components/ConditionalLoad/ConditionalLoad.js index 70fd03e8e..af832171b 100644 --- a/src/components/ConditionalLoad/ConditionalLoad.js +++ b/src/components/ConditionalLoad/ConditionalLoad.js @@ -34,14 +34,9 @@ const ConditionalLoad = ({ importFunc = dynamicModuleMap[importString]; } - // Both try/catch and promise catch are necessary here for reasons I don't quite understand, but it triggers in sonar so I'm disabling for now - try { // NOSONAR - return importFunc() - .then(importSuccess) - .catch(importError); - } catch (e) { - return importError(e); - } + return importFunc() + .then(importSuccess) + .catch(importError); });