Skip to content

Comments

fix(editor): prevent ghost slides and state corruption when clicking between slides#58

Merged
danish17 merged 4 commits intodevelopfrom
fix/watch-slides-corruption
Feb 24, 2026
Merged

fix(editor): prevent ghost slides and state corruption when clicking between slides#58
danish17 merged 4 commits intodevelopfrom
fix/watch-slides-corruption

Conversation

@danish17
Copy link
Collaborator

@danish17 danish17 commented Feb 24, 2026

Problem

In the block editor, clicking in the gap between slides caused two distinct bugs:

  • Loop enabled: slides permanently reordered and lost their transforms ("ghost slide")
  • Loop disabled: carousel jumped to slide 0, navigation buttons disabled, dots collapsed to one

The issue did not reproduce on the frontend.

Root Cause

Embla ships with three built-in watchers that are all enabled by default:

Watcher Mechanism Editor trigger
watchSlides MutationObserver on .embla__container Gutenberg injects its block insertion-point indicator and block appender as direct children of .embla__container; Embla detected these as slide additions/removals and called reInit()
watchResize ResizeObserver on the viewport Block toolbar appearing on selection causes a layout measurement that could trigger reInit()
watchDrag Pointer event listeners Clicks in the CSS gap area started Embla's drag tracking and caused unintended scroll snapping

The primary culprit was watchSlides: after reInit(), Embla recalculated scroll snaps with Gutenberg's UI node counted as an extra slide, producing wrong transforms and snap positions.

Fix

Disable all three watchers in the editor's Embla initialisation (viewport/edit.tsx):

watchSlides: false,  // Gutenberg injects UI nodes into .embla__container
watchResize: false,  // Block toolbar can cause spurious reInit
watchDrag:   false,  // Clicks in slide gaps must not trigger scroll

Also fixed a pre-existing ESLint warning (react-hooks/exhaustive-deps): emblaRef.current was read inside the effect cleanup function. It is now captured into a stable viewportEl variable at effect mount time.

@danish17 danish17 self-assigned this Feb 24, 2026

### Bug Fixes

* enable loop on editor ([fe4566a](https://github.com/rtCamp/carousel-system-interactivity-api/commit/fe4566afcf72e1e663c7eb481a7957d62c2d3365))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we update these links to rtcamp/carousel-kit ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I will raise a separate PR for this.

@danish17 danish17 merged commit cda4252 into develop Feb 24, 2026
1 check passed
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.

3 participants