Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
review changes
  • Loading branch information
cieplypolar committed Nov 25, 2025
commit 918547f0fca450540debcda1f64fe76009a0b829
3 changes: 0 additions & 3 deletions apps/typegpu-docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export default defineConfig({
'Cross-Origin-Opener-Policy': 'same-origin',
},
},
image: {
domains: ['raw.githubusercontent.com'],
},
markdown: {
remarkPlugins: [remarkMath],
rehypePlugins: [rehypeMathJax],
Expand Down
25 changes: 10 additions & 15 deletions apps/typegpu-docs/src/components/resolve/PlotGallery.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little over-engineered but since it's for dev I don't really mind it (all the comments are just general feedback for learning purposes).

  • We treat plots like they are not constant but they are so we should use it (for example there is no need to do useMemo for the plots - if we wanted to do extended plots we could just do that out of the component)
  • There is no expensive calculation going on here so the optimizations are a little overkill but good practice
  • Rest of the feedback is in the other comments

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the feedback. I deleted useMemo, but I can't change isTransitioning to useRef. isTransitioning state plays a crucial role in smooth carousel wrap when we transition from the last plot -> to the first plot (and first -> last).

  1. Because plots are extended with 'guard' plots, the animation appears to move continuously to the right (left).
  2. Then, I handle the transform property. I set isTransitioning to false, and change the index to real plot (not the guarding one)
  3. The CSS (this one containing animation logic) rerenders and we don't see the carousel going through all the plots.

Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { ChevronLeft, ChevronRight } from 'lucide-react';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';

const plots = [
'https://raw.githubusercontent.com/software-mansion-labs/typegpu-benchmarker/main/plots/combined-resolveDuration-full.png',
'https://raw.githubusercontent.com/software-mansion-labs/typegpu-benchmarker/main/plots/combined-resolveDuration-full-log.png',
'https://raw.githubusercontent.com/software-mansion-labs/typegpu-benchmarker/main/plots/combined-resolveDuration-latest5.png',
'https://raw.githubusercontent.com/software-mansion-labs/typegpu-benchmarker/main/plots/combined-resolveDuration-under10k.png',
];
const slideCount = plots.length;
const extendedPlots = [plots[slideCount - 1], ...plots, plots[0]];
const extendedSlideCount = extendedPlots.length;

function PlotSlide({ url }: { url: string }) {
return (
Expand All @@ -25,12 +28,6 @@ const buttonUtilityClasses =
const chevronUtilityClasses = 'w-4 h-4 sm:w-8 sm:h-8';

export default function PlotGallery() {
// this is for infinite effect
const extendedPlots = useMemo(
() => [plots[plots.length - 1], ...plots, plots[0]],
[],
);

const [currentIndex, setCurrentIndex] = useState(1);
const [isTransitioning, setIsTransitioning] = useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [isTransitioning, setIsTransitioning] = useState(false);
const isTransitioningRef = useRef(false);

I would go for this - isTransitioning does not need to cause re-renders and it will simplify transition handling


Expand All @@ -41,21 +38,19 @@ export default function PlotGallery() {
}, []);

const prevSlide = useCallback((isTransitioning: boolean) => {
console.log(isTransitioning);
if (isTransitioning) return;
setIsTransitioning(true);
setCurrentIndex((prev) => prev - 1);
}, []);

const handleTransitionEnd = useCallback((index: number) => {
setIsTransitioning(false);

if (index === 0) {
setCurrentIndex(plots.length);
} else if (index === extendedPlots.length - 1) {
setCurrentIndex(slideCount);
} else if (index === extendedSlideCount - 1) {
setCurrentIndex(1);
}
}, [extendedPlots]);
}, []);

const goToSlide = useCallback((index: number, isTransitioning: boolean) => {
if (isTransitioning) return;
Expand All @@ -64,8 +59,8 @@ export default function PlotGallery() {
}, []);

const getActualIndex = (): number => {
if (currentIndex === 0) return plots.length - 1;
if (currentIndex === extendedPlots.length - 1) return 0;
if (currentIndex === 0) return slideCount - 1;
if (currentIndex === extendedSlideCount - 1) return 0;
return currentIndex - 1;
};

Expand Down Expand Up @@ -99,7 +94,7 @@ export default function PlotGallery() {

<div
className={`flex h-full w-full transition-transform duration-200 ease-in-out ${
isTransitioning ? '' : 'transition-none' // this is necessary for smooth ending
isTransitioning ? '' : 'transition-none' // this is necessary for smooth wrapping
}`}
style={{ transform: `translateX(-${currentIndex * 100}%)` }}
onTransitionEnd={() => handleTransitionEnd(currentIndex)}
Expand Down