Skip to content

Commit dfc7bd3

Browse files
committed
Update comments to improve readability
1 parent fba4b9e commit dfc7bd3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

dotcom-rendering/src/components/ScrollableHighlights.importable.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,18 @@ export const ScrollableHighlights = ({ trails, frontId }: Props) => {
313313
};
314314
}, []);
315315

316-
// inspired by https://usehooks-ts.com/react-hook/use-isomorphic-layout-effect
316+
/* inspired by https://usehooks-ts.com/react-hook/use-isomorphic-layout-effect */
317317
const useIsomorphicLayoutEffect = isServer ? useEffect : useLayoutEffect;
318-
// useEffect runs after paint, so we briefly see the pre-hydration scroll position and then it snaps back.
319-
// to remedy this, we can use the useLayoutEffect hook. However, useLayoutEffect can only run on the client so we run useEffect on the server to stop it complaining.
318+
319+
/**
320+
* useEffect runs after paint, so we briefly see the pre-hydration scroll position and then it snaps back.
321+
* to remedy this, we can use the useLayoutEffect hook which fires before the browser repaints the screen.
322+
* However, useLayoutEffect can only run on the client so we run useEffect on the server to stop it complaining.
323+
* https://react.dev/reference/react/useLayoutEffect
324+
*/
320325
useIsomorphicLayoutEffect(() => {
321326
if (carouselRef.current) {
322-
// cancel any anchoring/snap side-effects by jumping immediately
327+
/* cancel any anchoring/snap side-effects by jumping immediately */
323328
carouselRef.current.scrollTo({ left: 0, behavior: 'auto' });
324329
setShouldShowHighlights(true);
325330
}
@@ -332,12 +337,12 @@ export const ScrollableHighlights = ({ trails, frontId }: Props) => {
332337
personalisedHighlights.length !== trails.length ||
333338
!isEqual(personalisedHighlights, trails)
334339
) {
335-
// store in local cache but don't bother setting in test trails as they are already set to trails
340+
/* Reset to editorial order */
336341
resetHighlightsState(trails);
337342
setOrderedTrails(trails);
338343
return;
339344
}
340-
// otherwise history is different to trails so set in state
345+
/* Otherwise, use personalised order from local storage */
341346
setOrderedTrails(personalisedHighlights);
342347
}, [trails]);
343348

0 commit comments

Comments
 (0)