Skip to content

Commit

Permalink
bug #409 Unset TomSelect after destroying the Stimulus Controller (ja…
Browse files Browse the repository at this point in the history
…nklan)

This PR was merged into the 2.x branch.

Discussion
----------

Unset TomSelect after destroying the Stimulus Controller

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Tickets       | [407](#407)
| License       | MIT

Sometimes Stimulus re-uses an instance of a controller after it's destroyed and re-created - for example when a Live Twig Component re-renders. Without unsetting the variable, [connect() method thinks TomSelect is already in place, and does nothing](https://github.com/symfony/ux/blob/2.x/src/Autocomplete/assets/src/controller.ts#L21-L25).

Commits
-------

01916e6 Unset tomSelect after destroying the instance
  • Loading branch information
weaverryan committed Aug 9, 2022
2 parents 72cacda + 01916e6 commit 53421dd
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Autocomplete/assets/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export default class extends Controller {

disconnect() {
this.tomSelect.destroy();
// Fixes https://github.com/symfony/ux/issues/407
this.tomSelect = undefined;
}

#getCommonConfig(): Partial<TomSettings> {
Expand Down

0 comments on commit 53421dd

Please sign in to comment.