Skip to content

Commit

Permalink
fix(lazy-loading): of sanitize-html by wrapping state assignment into…
Browse files Browse the repository at this point in the history
… a function call

- Used also loadable.lib pattern of lazy loading
  • Loading branch information
ichim-david committed Jul 13, 2024
1 parent a6fbc8b commit 55c56e0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Utils/FormattedValue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { UniversalLink } from '@plone/volto/components';
import { isUrl } from '@plone/volto/helpers';

const D3 = loadable.lib(() => import('d3'));
const SanitizeHtmlLib = loadable.lib(() => import('sanitize-html'));

const AnimatedCounter = ({ originalValue }) => {
return (
Expand All @@ -33,11 +34,11 @@ const FormattedValue = ({
animatedCounter,
link = null,
}) => {
const [sanitizeHtmlModule, setSanitizeHtmlModule] = useState(null);
const [sanitizeHtml, setSanitizeHtml] = useState(null);

useEffect(() => {
import('sanitize-html').then((module) => {
setSanitizeHtmlModule(module.default);
SanitizeHtmlLib.load().then((module) => {
setSanitizeHtml(() => module.default);
});
}, []);

Expand Down Expand Up @@ -75,8 +76,9 @@ const FormattedValue = ({
const html =
isLink && isObject(link) && link.title
? link.title
: (sanitizeHtmlModule &&
sanitizeHtmlModule(value, {
: (sanitizeHtml &&
value &&
sanitizeHtml(value, {
allowedAttributes: {
span: ['id'],
},
Expand Down

0 comments on commit 55c56e0

Please sign in to comment.