Bug reportSep 19, 2026· 0:21· 12 views
Svelte 5: onclick handler silently skipped when @attach writes to $state (svelte#18070)
0:21 total
Comments · 0
Be the first to comment.
Bug report— by SceneRecap AI
highevent-handling
os: macOSbrowser: Chromium 151.0.7922.34viewport: 1280x720
Repro steps
- 1.Open the Svelte 5 Playground reproduction containing a button configured with both an `{@attach}` directive writing to `$state` and a delegated `onclick` handler.
- 2.Click the 'Click me' button.
- 3.Observe the results and counter tallies in the preview pane.
- 4.Click the 'Click me' button again to test repeated triggers.
Expected
Clicking the button should execute both the `@attach` click handler and the delegated `onclick` handler, incrementing both `onclick count` and `@attach count`.
Actual
Only the `@attach` handler executes and increments `@attach count`; the delegated `onclick` handler is never called (`onclick count` remains 0 and `Missed` increments).
Evidence
visualAt 1.0s, initial Results show 'onclick count: 0', '@attach count: 0', and 'Missed: 0'.
visualAt 7.0s after the first button click at 6.5s, Results display 'onclick count: 0', '@attach count: 1', and 'Missed: 1'.
visualAt 12.8s after subsequent clicks, Results display 'onclick count: 0', '@attach count: 3', and 'Missed: 3'.
Issue markdown (copy-paste ready)
### Summary
When a button has both an `{@attach}` handler and a standard delegated `onclick` handler in Svelte 5, writing to a `$state` signal inside the `@attach` event handler triggers an `$effect` flush before the delegated `onclick` event can fire, silently dropping the delegated event.
### Steps to Reproduce
1. Create a component with a button using `{@attach throttle(onAttach)}` and `onclick={handleClick}`.
2. In `onAttach`, mutate a `$state` variable.
3. In `handleClick`, mutate a separate `$state` counter.
4. Click the button in the browser.
### Expected Behavior
Both `onAttach` and `handleClick` should fire upon clicking the button.
### Actual Behavior
`onAttach` fires and updates its counter, but `handleClick` is never invoked, leaving `onclick count: 0`.
*Recorded with SceneRecap.*Your recordings could explain themselves too.
Free plan · silent recordings welcome · bug reports included.
Try SceneRecap free →