Skip to content

stopPropagation does not work in Svelte 5 vs. works in Svelte 4 #15975

@michaelrommel

Description

@michaelrommel

Describe the bug

Hi,

I have a large element as a background that simulates an endless area. On top of that, individual rectangles shall be arranged by the user by dragging them. The drag handler from use-gesture handles the large element and for the individual rectangles (divs) a pointerdown handler was created, that captures the pointerdown element, sets that element into "moving" state and stops the propagation of the pointerdown event, so that the drag handler never sees it and does not start a drag event. This works in Svelte 4 but in Svelte 5 it no longer does.

I DO use the new onpointerdown syntax and I DO call event.stopPropagation() in the handler. Also stopImmediatePropagation does not prevent the event from bubbling up to the fabric's drag handler.

I have now scratched my head for several hours and have no solution. Is this a regression in Svelte 5 or is the library not usable with Svelte 5? I found several issues somehow related to what I am seeing, but all are closed and now supposed to be working:

#9688
#10165
#11365

If anyone has an idea or knows how that could be addressed, I would be glad to know.

The structure in the drags5 repo is as follows (for easier understanding without going to the repo):
The drag handler on the fabricEl still sees the pointerdown events.

<div
	style:position="absolute"
	style:inset="0px"
	style:z-index="-10"
	style:background-image="radial-gradient(#333 {zoom}px, transparent 0)"
	style:background-size="{24 * zoom}px {24 * zoom}px"
	style:background-position="{-zoom * center[0]}px {-zoom * center[1]}px"
></div>
<div
	style:position="absolute"
	style:inset="0px"
	style:overflow="hidden"
	style:background-color="rgba(1,1,1,0.5)"
	style:touch-action="none"
	id="fabricEl"
	bind:this={fabricEl}
>
	<div
		id="wrapper"
		style:position="absolute"
		style:background-color="red"
		style:padding="3rem"
		style:left={OFFSET_LEFT_CSS}
		style:top={OFFSET_TOP_CSS}
		style:transform-origin={OFFSET_TRANSFORM_ORIGIN_CSS}
		transition:fade|local
		use:slide={{
			x: movingSize.x,
			y: movingSize.y,
			center,
			zoom,
			immediate: true,
		}}
	>
		<div
			style:background-color="green"
			style:padding="2rem"
			onpointerdown={(event) => {
				console.log("startmoving");
				const [x, y] = normalizePosition(event);
				moving = 1;
				movingOrigin = [x - movingSize.x, y - movingSize.y];
				movingIsDone = false;
				event.stopPropagation();
				event.stopImmediatePropagation();
			}}
		>
			This is version 5.
		</div>
	</div>
</div>

Reproduction

There is a repo, where the two Svelte 4 and 5 versions live side by side, if anyone is interested: https://github.com/michaelrommel/drags.git

Logs

System Info

System:
    OS: macOS 13.7
    CPU: (20) arm64 Apple M1 Ultra
    Memory: 1.43 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.15.0 - ~/.local/share/mise/installs/node/22.15.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.9.2 - ~/.local/share/mise/installs/node/22.15.0/bin/npm
    pnpm: 10.9.0 - ~/.local/share/mise/installs/node/22.15.0/bin/pnpm
  Browsers:
    Chrome: 136.0.7103.114
    Edge: 135.0.3179.85
    Safari: 18.0.1

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions