Skip to content

Commit

Permalink
Fix primefaces#5202: Calendar rendering performance increase
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Nov 28, 2023
1 parent 05f9124 commit bba57f6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
7 changes: 1 addition & 6 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2952,12 +2952,7 @@ export const Calendar = React.memo(
})
);

return (
<span {...dayLabelProps}>
{content}
<Ripple />
</span>
);
return <span {...dayLabelProps}>{content}</span>;
};

const createWeek = (weekDates, weekNumber, groupIndex) => {
Expand Down
6 changes: 2 additions & 4 deletions components/lib/hooks/useStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const useStyle = (css, options = {}) => {
};

const load = () => {
if (!document) return;
if (!document || isLoaded) return;

styleRef.current = document.querySelector(`style[data-primereact-style-id="${name}"]`) || document.getElementById(id) || document.createElement('style');

Expand All @@ -31,8 +31,6 @@ export const useStyle = (css, options = {}) => {
name && styleRef.current.setAttribute('data-primereact-style-id', name);
}

if (isLoaded) return;

styleRef.current.textContent = css;

setIsLoaded(true);
Expand All @@ -50,7 +48,7 @@ export const useStyle = (css, options = {}) => {

// return () => {if (!manual) unload()}; /* @todo */
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [manual]);

return {
id,
Expand Down
11 changes: 6 additions & 5 deletions components/lib/ripple/Ripple.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ export const Ripple = React.memo(
const targetRef = React.useRef(null);
const context = React.useContext(PrimeReactContext);
const props = RippleBase.getProps(inProps, context);

const isRippleActive = (context && context.ripple) || PrimeReact.ripple;
const metaData = {
props
};

useStyle(RippleBase.css.styles, { name: 'ripple' });

const { ptm, cx } = RippleBase.setMetaData({
...metaData
});

useStyle(RippleBase.css.styles, { name: 'ripple', manual: !isRippleActive });

const getTarget = () => {
return inkRef.current && inkRef.current.parentElement;
};
Expand Down Expand Up @@ -101,6 +100,8 @@ export const Ripple = React.memo(
}
});

if (!isRippleActive) return null;

const rootProps = mergeProps(
{
'aria-hidden': true,
Expand All @@ -110,7 +111,7 @@ export const Ripple = React.memo(
ptm('root')
);

return (context && context.ripple) || PrimeReact.ripple ? <span role="presentation" ref={inkRef} {...rootProps} onAnimationEnd={onAnimationEnd}></span> : null;
return <span role="presentation" ref={inkRef} {...rootProps} onAnimationEnd={onAnimationEnd}></span>;
})
);

Expand Down

0 comments on commit bba57f6

Please sign in to comment.