Skip to content

Conversation

@cieplypolar
Copy link
Collaborator

No description provided.

@github-actions
Copy link

github-actions bot commented Nov 4, 2025

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@918547f0fca450540debcda1f64fe76009a0b829
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@918547f0fca450540debcda1f64fe76009a0b829
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@918547f0fca450540debcda1f64fe76009a0b829

benchmark
view benchmark

commit
view commit

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that the page does not respond to the light theme, but /benchmark acts the same so we may ignore it (at least until the landing page rework)

Comment on lines 39 to 41
image: {
domains: ['raw.githubusercontent.com'],
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, we don't, my bad

Comment on lines 28 to 32
// this is for infinite effect
const extendedPlots = useMemo(
() => [plots[plots.length - 1], ...plots, plots[0]],
[],
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we don't really need this - creating logic for wrapping in callbacks is trivial and we don't care about the dependency (plots never changes).

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 don't see a simple solution inside the callbacks, if I just use modulo length, then the carousel will go through all the plots

);

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

Comment on lines +37 to +41
const nextSlide = useCallback((isTransitioning: boolean) => {
if (isTransitioning) return;
setIsTransitioning(true);
setCurrentIndex((prev) => prev + 1); // to avoid deps
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

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

+ const slideCount = plots.length;
Suggested change
const nextSlide = useCallback((isTransitioning: boolean) => {
if (isTransitioning) return;
setIsTransitioning(true);
setCurrentIndex((prev) => prev + 1); // to avoid deps
}, []);
const nextSlide = useCallback(() => {
if (isTransitioningRef.current) return;
isTransitioningRef.current = true;
setCurrentIndex((prev) => prev === slideCount - 1 ? 0 : prev + 1);
}, [slideCount]);

Comment on lines 50 to 58
const handleTransitionEnd = useCallback((index: number) => {
setIsTransitioning(false);

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

Choose a reason for hiding this comment

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

This will also be much simpler if we just do transitioning as a ref and the logic for wrapping in callbacks

Suggested change
const handleTransitionEnd = useCallback((index: number) => {
setIsTransitioning(false);
if (index === 0) {
setCurrentIndex(plots.length);
} else if (index === extendedPlots.length - 1) {
setCurrentIndex(1);
}
}, [extendedPlots]);
const handleTransitionEnd = useCallback(() => {
isTransitioningRef.current = false;
}, []);

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants