Skip to content

fix: prevent event delegation logic conflicting between svelte instances#17728

Merged
Rich-Harris merged 2 commits intomainfrom
event-delegation-encapsulation
Feb 17, 2026
Merged

fix: prevent event delegation logic conflicting between svelte instances#17728
Rich-Harris merged 2 commits intomainfrom
event-delegation-encapsulation

Conversation

@Rich-Harris
Copy link
Member

Fixes sveltejs/svelte.dev#1793. There are actually two fixes here, and either is sufficient to fix the playground, but they are complementary. First, we only add the delegated event handler after the component has successfully mounted, otherwise it will never get cleaned up if an error occurs during mount.

Second, instead of storing data on event.__root (which leaks between instances), we reuse the existing event_symbol to provide the necessary encapsulation. (I'll be honest I don't totally understand what this property is for anyway and can't be bothered to figure it out right now, but I'm sure it's important.)

No test because I'm not really sure how you would test this; it requires a fairly esoteric setup.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

@changeset-bot
Copy link

changeset-bot bot commented Feb 17, 2026

🦋 Changeset detected

Latest commit: 3516086

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@17728

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
@Rich-Harris Rich-Harris merged commit e47c747 into main Feb 17, 2026
13 of 14 checks passed
@Rich-Harris Rich-Harris deleted the event-delegation-encapsulation branch February 17, 2026 14:57
@github-actions github-actions bot mentioned this pull request Feb 17, 2026
Rich-Harris pushed a commit that referenced this pull request Feb 17, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## svelte@5.51.3

### Patch Changes

- fix: prevent event delegation logic conflicting between svelte
instances ([#17728](#17728))

- fix: treat CSS attribute selectors as case-insensitive for HTML
enumerated attributes
([#17712](#17712))

- fix: locate Rollup annontaion friendly to JS downgraders
([#17724](#17724))

- fix: run effects in pending snippets
([#17719](#17719))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

Playground Reactivity Breaks in Both Repl and Tutorial Repl After Temporary Error 5.51.2

2 participants