Skip to content

Conversation

Mahavishnu-K
Copy link

@Mahavishnu-K Mahavishnu-K commented Jul 24, 2025

Description of the Change

This pull request fixes a bug in the Carousel.svelte component where the arrow buttons were not working correctly.

The original implementation used complex and unreliable state management to calculate the scroll distance. This fix simplifies the logic entirely by removing the manual scroll tracking and using a direct carousel.scrollBy({ left: carousel.clientWidth }) call. This approach is more robust, simpler to maintain, and ensures the carousel scrolls as expected.

Local Build Environment

The contribution guide asks to run pnpm run build before submitting. Unfortunately, I was unable to get a successful build on my local Windows machine due to a persistent EMFILE: too many open files error, which is a known OS limitation with very large projects. I have made several attempts to resolve it (memory increase, clean installs) without success.

As this change is a small, self-contained UI fix to a single component, I am confident it will not break the production build, which will be verified by the CI pipeline.

How to Test

  1. Navigate to the /docs page.
  2. Scroll down to the "Show me some code" section.
  3. Click the right arrow button on the carousel.
  4. Expected behavior: The carousel smoothly slides to the next set of cards.
  5. Click the left arrow button.
  6. Expected behavior: The carousel smoothly slides back.

Contributor Checklist

  • I have read the Documentation Contributing Guide.
  • I was unable to complete the pnpm run build step due to a local environment issue (EMFILE). I am relying on the CI to validate the build.
  • My branch is up-to-date with the main branch of appwrite/website.

Summary by CodeRabbit

  • Refactor
    • Streamlined carousel navigation. The Next and Previous controls now advance by one full visible “page” at a time, rather than varying with individual item sizes. This delivers more predictable, consistent scrolling across layouts and content mixes, reducing over/under-scrolling and making navigation feel smoother.
    • Existing UI state indicators and scroll event behaviors remain unchanged.

Removed complex state management for the carousel's scroll position. Replaced with a direct and reliable scrollBy(clientWidth) call to ensure smooth and predictable navigation.
Removed complex state management for the carousel's scroll position. Replaced with a direct and reliable scrollBy(clientWidth) call to ensure smooth and predictable navigation. Ajusted the whitespace for code readability
Copy link

appwrite bot commented Jul 24, 2025

appwrite.io

Project ID: 684969cb000a2f6c0a02

Sites (1)
Site Status Logs Preview QR
 website
68496a17000f03d62013
Failed Failed Authorize Preview URL QR Code

Note

You can use Avatars API to generate QR code for any text or URLs.

@coolify-appwrite-org
Copy link

coolify-appwrite-org bot commented Jul 24, 2025

The preview deployment is ready. 🟢

Open Preview | Open Build Logs

Last updated at: 2025-07-24 08:51:02 CET

Copy link
Contributor

coderabbitai bot commented Sep 9, 2025

Walkthrough

The carousel component removed its internal scroll amount calculation and related state. The next() and prev() functions now scroll horizontally by the container’s visible width using carousel.clientWidth and -carousel.clientWidth, rather than computing item-based paging. Existing scroll event handling and UI state logic remain intact. No changes were made to exported or public APIs. No new error handling was added.

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the component and the purpose of the change by indicating that the carousel’s scrolling logic was simplified to fix arrow button behavior, directly reflecting the main modification in the changeset.
Description Check ✅ Passed The description clearly outlines the bug in the Carousel.svelte component, explains how the fix replaces manual scroll tracking with a direct scrollBy call, and includes relevant testing instructions and context about the contributor’s local build issue, making it directly related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/lib/components/Carousel.svelte (2)

52-56: Forward arrow is hard-disabled; button never becomes clickable.

The forward button has a plain disabled attribute, so it’s always disabled. Bind it to isEnd like the back button binds to isStart.

Apply this diff:

-            <button
+            <button
                 class="web-icon-button cursor-pointer"
                 aria-label="Move carousel forward"
-                disabled
-                onclick={next}
+                disabled={isEnd}
+                on:click={next}
             >

43-50: Use Svelte event bindings (on:event) instead of native attributes

  • In src/lib/components/Carousel.svelte, replace both handlers:
-                onclick={prev}
+                on:click={prev}
-                onclick={next}
+                on:click={next}
  • A grep over the repo shows countless other uses of onclick, onmouseover, onfocus, etc. All should be converted to Svelte syntax (on:event={handler}) to ensure handlers attach correctly. For example:
rg -nP '(<\w+[^>]*\s)(on\w+)='
🧹 Nitpick comments (3)
src/lib/components/Carousel.svelte (3)

28-34: Initialize nav state on mount to avoid stale disabled states on first render.

Until the first scroll event, isStart/isEnd may be inaccurate. Trigger handleScroll() on mount.

Apply this diff:

 <script lang="ts">
-    import type { Snippet } from 'svelte';
+    import type { Snippet } from 'svelte';
+    import { onMount } from 'svelte';
@@
     let isStart = $state(true);
@@
     function handleScroll() {
         isStart = carousel.scrollLeft <= 0;
         isEnd = Math.ceil(carousel.scrollLeft + carousel.offsetWidth) >= carousel.scrollWidth;
     }
+
+    onMount(() => {
+        // sync initial state after bind:this resolves
+        handleScroll();
+    });
 </script>

4-4: Tighten the ref type.

Since bind:this targets a UL, prefer HTMLUListElement for stronger typing.

Apply this diff:

-    let carousel: HTMLElement;
+    let carousel: HTMLUListElement;

15-26: Honor prefers-reduced-motion for smoother a11y.

Avoid forced smooth scrolling for users who prefer reduced motion.

Apply this diff:

-    function next() {
-        carousel.scrollBy({
-            left: carousel.clientWidth,
-            behavior: 'smooth'
-        });
-    }
+    function next() {
+        const behavior: ScrollBehavior =
+            typeof window !== 'undefined' &&
+            window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
+                ? 'auto'
+                : 'smooth';
+        carousel.scrollBy({ left: carousel.clientWidth, behavior });
+    }
@@
-    function prev() {
-        carousel.scrollBy({
-            left: -carousel.clientWidth,
-            behavior: 'smooth'
-        });
-    }
+    function prev() {
+        const behavior: ScrollBehavior =
+            typeof window !== 'undefined' &&
+            window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
+                ? 'auto'
+                : 'smooth';
+        carousel.scrollBy({ left: -carousel.clientWidth, behavior });
+    }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dfc9e9d and e66d40a.

📒 Files selected for processing (1)
  • src/lib/components/Carousel.svelte (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: tests
🔇 Additional comments (2)
src/lib/components/Carousel.svelte (2)

15-20: LGTM: Simpler page-wise scroll via clientWidth.

Directly using scrollBy with clientWidth is a good simplification and should be more reliable than manual tracking.


21-26: LGTM: Symmetric prev() implementation.

Matches next() logic and keeps behavior consistent.

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.

2 participants